Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87b72e1

Browse files
committed
dummy projection
1 parent 105c149 commit 87b72e1

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

init.c

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
#include "funcapi.h"
1313

1414
#include "access/htup_details.h"
15+
#include "access/heapam.h"
16+
1517
#include "point.h"
18+
#include "crossmatch.h"
1619

1720
extern void _PG_init(void);
1821

@@ -37,6 +40,9 @@ typedef struct
3740
HeapTupleData scan_tuple; /* buffer to fetch tuple */
3841
List *dev_tlist; /* tlist to be returned from the device */
3942
List *dev_quals; /* quals to be run on the device */
43+
44+
Relation left;
45+
Relation right;
4046
} CrossmatchScanState;
4147

4248
static CustomPathMethods crossmatch_path_methods;
@@ -91,6 +97,7 @@ create_crossmatch_path(PlannerInfo *root,
9197
result->cpath.path.parent = joinrel;
9298
result->cpath.path.param_info = param_info;
9399
result->cpath.path.pathkeys = NIL;
100+
result->cpath.path.pathtarget = &joinrel->reltarget;
94101
result->cpath.path.rows = joinrel->rows;
95102
result->cpath.flags = 0;
96103
result->cpath.methods = &crossmatch_path_methods;
@@ -221,7 +228,7 @@ create_crossmatch_plan(PlannerInfo *root,
221228
{
222229
CrossmatchJoinPath *gpath = (CrossmatchJoinPath *) best_path;
223230
List *joinrestrictclauses = gpath->joinrestrictinfo;
224-
List *joinclauses;
231+
List *joinclauses; /* NOTE: do we really need it? */
225232
List *otherclauses;
226233
CustomScan *cscan;
227234

@@ -249,7 +256,6 @@ create_crossmatch_plan(PlannerInfo *root,
249256

250257
cscan->flags = best_path->flags;
251258
cscan->methods = &crossmatch_plan_methods;
252-
cscan->custom_plans = list_copy_tail(custom_plans, 1);
253259

254260
return &cscan->scan.plan;
255261
}
@@ -261,45 +267,57 @@ crossmatch_create_scan_state(CustomScan *node)
261267

262268
NodeSetTag(scan_state, T_CustomScanState);
263269
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;
268273

269274
return (Node *) scan_state;
270275
}
271276

272-
/* HACK: remove this */
273-
static int i = 0;
274-
275277
static void
276278
crossmatch_begin(CustomScanState *node, EState *estate, int eflags)
277279
{
278-
i = 0;
280+
279281
}
280282

281283
static TupleTableSlot *
282284
crossmatch_exec(CustomScanState *node)
283285
{
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;
286289
HeapTuple htup;
287290

291+
HeapTupleData fetched_tup;
292+
293+
ResetExprContext(econtext);
294+
288295
/* 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)")),
290297
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);
292301

293302
htup = heap_form_tuple(tupdesc, values, nulls);
294303

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);
296310

297-
i++;
311+
result = ExecProject(node->ss.ps.ps_ProjInfo, &isDone);
298312

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+
}
301319
else
302-
ExecStoreTuple(htup, slot, InvalidBuffer, false);
320+
ExecClearTuple(slot);
303321

304322
return slot;
305323
}

0 commit comments

Comments
 (0)