2
2
3
3
PG_MODULE_MAGIC ;
4
4
5
- /*
6
- * Handler and Validator functions
7
- */
8
5
extern Datum bt_fdw_handler (PG_FUNCTION_ARGS );
9
6
extern Datum bt_fdw_validator (PG_FUNCTION_ARGS );
10
7
11
8
PG_FUNCTION_INFO_V1 (bt_fdw_handler );
12
9
PG_FUNCTION_INFO_V1 (bt_fdw_validator );
13
10
14
- /*
15
- * FDW functions implementation
16
- */
17
-
18
11
Datum
19
12
bt_fdw_handler (PG_FUNCTION_ARGS ) {
20
13
FdwRoutine * fdw_routine = makeNode (FdwRoutine );
21
- fdw_routine -> GetForeignRelSize = btGetForeignRelSize ;
22
- fdw_routine -> GetForeignPaths = btGetForeignPaths ;
23
- fdw_routine -> GetForeignPlan = btGetForeignPlan ;
24
- fdw_routine -> ExplainForeignScan = btExplainForeignScan ;
25
- fdw_routine -> BeginForeignScan = btFdwBeginForeignScan ;
26
- fdw_routine -> IterateForeignScan = btFdWIterateForeignScan ;
27
- fdw_routine -> ReScanForeignScan = btReScanForeignScan ;
28
- fdw_routine -> EndForeignScan = btEndForeignScan ;
14
+ fdw_routine -> GetForeignRelSize = bt_fdw_get_foreign_rel_size ;
15
+ fdw_routine -> GetForeignPaths = bt_fdw_get_foreign_paths ;
16
+ fdw_routine -> GetForeignPlan = bt_fdw_get_foreign_plan ;
17
+ fdw_routine -> ExplainForeignScan = bt_fdw_explain_foreign_scan ;
18
+ fdw_routine -> BeginForeignScan = bt_fdw_begin_foreign_scan ;
19
+ fdw_routine -> IterateForeignScan = bt_fdw_iterate_foreign_scan ;
20
+ fdw_routine -> ReScanForeignScan = bt_fdw_rescan_foreign_scan ;
21
+ fdw_routine -> EndForeignScan = bt_fdw_end_foreign_scan ;
29
22
fdw_routine -> AnalyzeForeignTable = NULL ;
30
- fdw_routine -> IsForeignRelUpdatable = btIsForeignRelUpdatable ;
31
- fdw_routine -> AddForeignUpdateTargets = btAddForeignUpdateTargets ; /* U D */
32
- fdw_routine -> PlanForeignModify = btPlanForeignModify ; /* I U D */
33
- fdw_routine -> BeginForeignModify = btBeginForeignModify ; /* I U D */
34
- fdw_routine -> ExecForeignInsert = btExecForeignInsert ; /* I */
35
- fdw_routine -> ExecForeignUpdate = btExecForeignUpdate ; /* U */
36
- fdw_routine -> ExecForeignDelete = btExecForeignDelete ; /* D */
37
- fdw_routine -> EndForeignModify = btEndForeignModify ; /* I U D */
23
+ fdw_routine -> IsForeignRelUpdatable = bt_is_foreign_rel_updatable ;
24
+ fdw_routine -> AddForeignUpdateTargets = bt_fdw_add_foreign_update_targets ;
25
+ fdw_routine -> PlanForeignModify = bt_fdw_plan_foreign_modify ;
26
+ fdw_routine -> BeginForeignModify = bt_fdw_begin_foreign_modify ;
27
+ fdw_routine -> ExecForeignInsert = bt_fdw_exec_foreign_insert ;
28
+ fdw_routine -> ExecForeignUpdate = bt_fdw_exec_foreign_update ;
29
+ fdw_routine -> ExecForeignDelete = bt_fdw_exec_foreign_delete ;
30
+ fdw_routine -> EndForeignModify = bt_fdw_end_foreign_modify ;
38
31
39
32
PG_RETURN_POINTER (fdw_routine );
40
33
}
41
34
42
35
Datum
43
36
bt_fdw_validator (PG_FUNCTION_ARGS ) {
44
37
PG_RETURN_BOOL (true);
45
- }
46
-
47
- static void
48
- btGetForeignRelSize (PlannerInfo * root ,
49
- RelOptInfo * baserel ,
50
- Oid foreigntableid ) {
51
- elog (LOG , "entering function %s" , __func__ );
52
-
53
- baserel -> rows = 1 ;
54
- }
55
-
56
- static void
57
- btGetForeignPaths (PlannerInfo * root ,
58
- RelOptInfo * baserel ,
59
- Oid foreigntableid ) {
60
- Cost total_cost , startup_cost ;
61
- elog (LOG , "entering function %s" , __func__ );
62
- startup_cost = 10 ;
63
- total_cost = startup_cost + baserel -> rows ;
64
-
65
- /* Create a ForeignPath node and add it as only possible path */
66
- add_path (baserel , (Path * )
67
- create_foreignscan_path (root , baserel ,
68
- NULL , /* default pathtarget */
69
- baserel -> rows ,
70
- startup_cost ,
71
- total_cost ,
72
- NIL , /* no pathkeys */
73
- NULL , /* no outer rel either */
74
- NULL , /* no extra plan */
75
- NIL )); /* no fdw_private data */
76
- }
77
-
78
- static ForeignScan *
79
- btGetForeignPlan (PlannerInfo * root ,
80
- RelOptInfo * baserel ,
81
- Oid foreigntableid ,
82
- ForeignPath * best_path ,
83
- List * tlist ,
84
- List * scan_clauses ,
85
- Plan * outer_plan ) {
86
-
87
- elog (LOG , "entering function %s" , __func__ );
88
-
89
- Index scan_relid = baserel -> relid ;
90
-
91
- get_limit (root );
92
-
93
- scan_clauses = extract_actual_clauses (scan_clauses , false);
94
-
95
- return make_foreignscan (tlist ,
96
- scan_clauses ,
97
- scan_relid ,
98
- NIL , /* no expressions to evaluate */
99
- NIL , /* no private state either */
100
- NIL , /* no custom tlist */
101
- NIL , /* no remote quals */
102
- outer_plan );
103
- }
104
-
105
- static void
106
- btExplainForeignScan (ForeignScanState * node , ExplainState * es ) {
107
- /* TODO: calculate real values */
108
- ExplainPropertyText ("Foreign Bigtable" , "bt" , es );
109
-
110
- if (es -> costs ) {
111
- ExplainPropertyLong ("Foreign Bigtable, costs and row estiamtes are meaningless" , 0 , es );
112
- }
113
- }
114
-
115
- static void
116
- btFdwBeginForeignScan (ForeignScanState * node , int eflags ) {
117
- bt_fdw_state_t * st = bt_fdw_state_from_fss (node );
118
-
119
- // elog(LOG, "entering function %s", __func__);
120
-
121
- if (eflags & EXEC_FLAG_EXPLAIN_ONLY ) {
122
- return ;
123
- }
124
-
125
- node -> fdw_state = st ;
126
- }
127
-
128
- static TupleTableSlot *
129
- btFdWIterateForeignScan (ForeignScanState * node ) {
130
-
131
- bt_fdw_state_t * st ;
132
- st = node -> fdw_state ;
133
-
134
- elog (LOG , "entering function %s" , __func__ );
135
-
136
- bt_fdw_iterate_foreign_scan (st , node );
137
- TupleTableSlot * slot = node -> ss .ss_ScanTupleSlot ;
138
- return slot ;
139
- }
140
-
141
- static void
142
- btReScanForeignScan (ForeignScanState * node ) {
143
- elog (LOG , "entering function %s" , __func__ );
144
- }
145
-
146
- static void
147
- btEndForeignScan (ForeignScanState * node ) {
148
- elog (LOG , "entering function %s" , __func__ );
149
-
150
- }
151
-
152
- static void
153
- btAddForeignUpdateTargets (Query * parsetree ,
154
- RangeTblEntry * target_rte ,
155
- Relation target_relation ) {
156
-
157
- elog (DEBUG1 , "entering function %s" , __func__ );
158
-
159
- }
160
-
161
-
162
- static List *
163
- btPlanForeignModify (PlannerInfo * root ,
164
- ModifyTable * plan ,
165
- Index resultRelation ,
166
- int subplan_index ) {
167
-
168
- elog (DEBUG1 , "entering function %s" , __func__ );
169
-
170
- return NULL ;
171
- }
172
-
173
-
174
- static void
175
- btBeginForeignModify (ModifyTableState * mtstate ,
176
- ResultRelInfo * rinfo ,
177
- List * fdw_private ,
178
- int subplan_index ,
179
- int eflags ) {
180
-
181
- bt_fdw_state_t * st = bt_fdw_state_from_relinfo (rinfo );
182
-
183
- elog (LOG , "entering function %s" , __func__ );
184
-
185
- if (eflags & EXEC_FLAG_EXPLAIN_ONLY ) {
186
- return ;
187
- }
188
-
189
- rinfo -> ri_FdwState = st ;
190
-
191
- }
192
-
193
-
194
- static TupleTableSlot *
195
- btExecForeignInsert (EState * estate ,
196
- ResultRelInfo * rinfo ,
197
- TupleTableSlot * slot ,
198
- TupleTableSlot * planSlot ) {
199
-
200
- bt_fdw_state_t * st ;
201
- st = rinfo -> ri_FdwState ;
202
-
203
- TupleDesc tupdesc = slot -> tts_tupleDescriptor ;
204
- Form_pg_attribute attr = tupdesc -> attrs [1 ];
205
- bool isnull ;
206
-
207
- Datum val = slot_getattr (slot , 1 , & isnull );
208
-
209
- char * res = TextDatumGetCString (val );
210
-
211
- bt_fdw_exec_foreign_insert (st , res );
212
-
213
- elog (DEBUG1 , "entering function %s" , __func__ );
214
-
215
- return slot ;
216
- }
217
-
218
-
219
- static TupleTableSlot *
220
- btExecForeignUpdate (EState * estate ,
221
- ResultRelInfo * rinfo ,
222
- TupleTableSlot * slot ,
223
- TupleTableSlot * planSlot ) {
224
-
225
-
226
- elog (DEBUG1 , "entering function %s" , __func__ );
227
-
228
- return slot ;
229
- }
230
-
231
-
232
- static TupleTableSlot *
233
- btExecForeignDelete (EState * estate ,
234
- ResultRelInfo * rinfo ,
235
- TupleTableSlot * slot ,
236
- TupleTableSlot * planSlot ) {
237
-
238
- elog (DEBUG1 , "entering function %s" , __func__ );
239
-
240
- return slot ;
241
- }
242
-
243
-
244
- static void
245
- btEndForeignModify (EState * estate ,
246
- ResultRelInfo * rinfo ) {
247
-
248
- elog (DEBUG1 , "entering function %s" , __func__ );
249
-
250
- }
251
-
252
- static int
253
- btIsForeignRelUpdatable (Relation rel ) {
254
-
255
- elog (DEBUG1 , "entering function %s" , __func__ );
256
-
257
- return (0 << CMD_UPDATE ) | (1 << CMD_INSERT ) | (0 << CMD_DELETE );
258
- }
38
+ }
0 commit comments