12
12
#include "funcapi.h"
13
13
14
14
#include "access/htup_details.h"
15
+ #include "access/heapam.h"
16
+
15
17
#include "point.h"
18
+ #include "crossmatch.h"
16
19
17
20
extern void _PG_init (void );
18
21
@@ -37,6 +40,9 @@ typedef struct
37
40
HeapTupleData scan_tuple ; /* buffer to fetch tuple */
38
41
List * dev_tlist ; /* tlist to be returned from the device */
39
42
List * dev_quals ; /* quals to be run on the device */
43
+
44
+ Relation left ;
45
+ Relation right ;
40
46
} CrossmatchScanState ;
41
47
42
48
static CustomPathMethods crossmatch_path_methods ;
@@ -91,6 +97,7 @@ create_crossmatch_path(PlannerInfo *root,
91
97
result -> cpath .path .parent = joinrel ;
92
98
result -> cpath .path .param_info = param_info ;
93
99
result -> cpath .path .pathkeys = NIL ;
100
+ result -> cpath .path .pathtarget = & joinrel -> reltarget ;
94
101
result -> cpath .path .rows = joinrel -> rows ;
95
102
result -> cpath .flags = 0 ;
96
103
result -> cpath .methods = & crossmatch_path_methods ;
@@ -221,7 +228,7 @@ create_crossmatch_plan(PlannerInfo *root,
221
228
{
222
229
CrossmatchJoinPath * gpath = (CrossmatchJoinPath * ) best_path ;
223
230
List * joinrestrictclauses = gpath -> joinrestrictinfo ;
224
- List * joinclauses ;
231
+ List * joinclauses ; /* NOTE: do we really need it? */
225
232
List * otherclauses ;
226
233
CustomScan * cscan ;
227
234
@@ -249,7 +256,6 @@ create_crossmatch_plan(PlannerInfo *root,
249
256
250
257
cscan -> flags = best_path -> flags ;
251
258
cscan -> methods = & crossmatch_plan_methods ;
252
- cscan -> custom_plans = list_copy_tail (custom_plans , 1 );
253
259
254
260
return & cscan -> scan .plan ;
255
261
}
@@ -261,45 +267,57 @@ crossmatch_create_scan_state(CustomScan *node)
261
267
262
268
NodeSetTag (scan_state , T_CustomScanState );
263
269
scan_state -> css .flags = node -> flags ;
264
- if (node -> methods == & crossmatch_plan_methods )
265
- scan_state -> css .methods = & crossmatch_exec_methods ;
266
- else
267
- elog (ERROR , "Bug? unexpected CustomPlanMethods" );
270
+ scan_state -> css .methods = & crossmatch_exec_methods ;
271
+
272
+ scan_state -> css .ss .ps .ps_TupFromTlist = false;
268
273
269
274
return (Node * ) scan_state ;
270
275
}
271
276
272
- /* HACK: remove this */
273
- static int i = 0 ;
274
-
275
277
static void
276
278
crossmatch_begin (CustomScanState * node , EState * estate , int eflags )
277
279
{
278
- i = 0 ;
280
+
279
281
}
280
282
281
283
static TupleTableSlot *
282
284
crossmatch_exec (CustomScanState * node )
283
285
{
284
- TupleTableSlot * slot = node -> ss .ss_ScanTupleSlot ;
285
- TupleDesc tupdesc = node -> ss .ss_ScanTupleSlot -> tts_tupleDescriptor ;
286
+ TupleTableSlot * slot = node -> ss .ps .ps_ResultTupleSlot ;
287
+ TupleDesc tupdesc = node -> ss .ps .ps_ResultTupleSlot -> tts_tupleDescriptor ;
288
+ ExprContext * econtext = node -> ss .ps .ps_ProjInfo -> pi_exprContext ;
286
289
HeapTuple htup ;
287
290
291
+ HeapTupleData fetched_tup ;
292
+
293
+ ResetExprContext (econtext );
294
+
288
295
/* TODO: fill with real data from joined tables */
289
- Datum values [2 ] = { DirectFunctionCall1 (spherepoint_in , CStringGetDatum ("(0d, 0d)" )),
296
+ Datum values [4 ] = { DirectFunctionCall1 (spherepoint_in , CStringGetDatum ("(0d, 0d)" )),
290
297
DirectFunctionCall1 (spherepoint_in , CStringGetDatum ("(0d, 0d)" )) };
291
- bool nulls [2 ] = {0 , 0 };
298
+ bool nulls [4 ] = {0 ,1 ,1 ,1 };
299
+
300
+ elog (LOG , "slot.natts: %d" , tupdesc -> natts );
292
301
293
302
htup = heap_form_tuple (tupdesc , values , nulls );
294
303
295
- elog (LOG , "natts: %d" , tupdesc -> natts );
304
+ if (node -> ss .ps .ps_ProjInfo -> pi_itemIsDone != ExprEndResult )
305
+ {
306
+ TupleTableSlot * result ;
307
+ ExprDoneCond isDone ;
308
+
309
+ econtext -> ecxt_scantuple = ExecStoreTuple (htup , slot , InvalidBuffer , false);
296
310
297
- i ++ ;
311
+ result = ExecProject ( node -> ss . ps . ps_ProjInfo , & isDone ) ;
298
312
299
- if (i > 10 )
300
- ExecClearTuple (slot );
313
+ if (isDone != ExprEndResult )
314
+ {
315
+ node -> ss .ps .ps_TupFromTlist = (isDone == ExprMultipleResult );
316
+ return result ;
317
+ }
318
+ }
301
319
else
302
- ExecStoreTuple ( htup , slot , InvalidBuffer , false );
320
+ ExecClearTuple ( slot );
303
321
304
322
return slot ;
305
323
}
0 commit comments