Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit725fefe

Browse files
committed
improve projection (dispatch columns via tlist)
1 parent934e8d0 commit725fefe

File tree

1 file changed

+66
-25
lines changed

1 file changed

+66
-25
lines changed

‎init.c

Lines changed: 66 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,14 @@ typedef struct
5656

5757
List*scan_tlist;
5858

59+
Indexouter_relid;
5960
Oidouter_idx;
6061
Oidouter_rel;
61-
ItemPointerouter_ptr;
62-
HeapTupleouter_tup;
6362
Relationouter;
6463

64+
Indexinner_relid;
6565
Oidinner_idx;
6666
Oidinner_rel;
67-
ItemPointerinner_ptr;
68-
HeapTupleinner_tup;
6967
Relationinner;
7068

7169
float8threshold;
@@ -446,9 +444,17 @@ create_crossmatch_plan(PlannerInfo *root,
446444
gpath->outer_rel,
447445
gpath->inner_idx,
448446
gpath->inner_rel));
447+
448+
/* store threshold as cstring */
449449
cscan->custom_private=lappend(cscan->custom_private,
450450
makeString(float8_to_cstring(gpath->threshold)));
451451

452+
cscan->custom_private=lappend(cscan->custom_private,
453+
makeInteger(gpath->outer_path->parent->relid));
454+
455+
cscan->custom_private=lappend(cscan->custom_private,
456+
makeInteger(gpath->inner_path->parent->relid));
457+
452458
return&cscan->scan.plan;
453459
}
454460

@@ -470,8 +476,12 @@ crossmatch_create_scan_state(CustomScan *node)
470476
scan_state->outer_rel=lsecond_oid(linitial(node->custom_private));
471477
scan_state->inner_idx=lthird_oid(linitial(node->custom_private));
472478
scan_state->inner_rel=lfourth_oid(linitial(node->custom_private));
479+
473480
scan_state->threshold=cstring_to_float8(strVal(lsecond(node->custom_private)));
474481

482+
scan_state->outer_relid=intVal(lthird(node->custom_private));
483+
scan_state->inner_relid=intVal(lfourth(node->custom_private));
484+
475485
return (Node*)scan_state;
476486
}
477487

@@ -480,9 +490,7 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags)
480490
{
481491
CrossmatchScanState*scan_state= (CrossmatchScanState*)node;
482492
CrossmatchContext*ctx= (CrossmatchContext*)palloc0(sizeof(CrossmatchContext));
483-
484-
/* TODO: fix this kludge */
485-
intnlist=list_length(scan_state->scan_tlist)+2;
493+
intnlist=list_length(scan_state->scan_tlist);
486494

487495
scan_state->ctx=ctx;
488496
setupFirstcall(ctx,scan_state->outer_idx,
@@ -519,8 +527,8 @@ crossmatch_exec(CustomScanState *node)
519527
bool*nulls=scan_state->nulls;
520528

521529
ItemPointerDatap_tids[2]= {0 };
522-
HeapTupleDatahtup1;
523-
HeapTupleDatahtup2;
530+
HeapTupleDatahtup_outer;
531+
HeapTupleDatahtup_inner;
524532
Bufferbuf1;
525533
Bufferbuf2;
526534

@@ -534,22 +542,55 @@ crossmatch_exec(CustomScanState *node)
534542
/* We don't have to fetch tuples if scan tlist is empty */
535543
if (scan_state->scan_tlist!=NIL)
536544
{
537-
TupleDesctupdesc=node->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
538-
539-
htup1.t_self=p_tids[0];
540-
heap_fetch(scan_state->outer,SnapshotSelf,
541-
&htup1,&buf1, false,NULL);
542-
values[0]=heap_getattr(&htup1,1,scan_state->outer->rd_att,
543-
&nulls[0]);
544-
545-
htup2.t_self=p_tids[1];
546-
heap_fetch(scan_state->inner,SnapshotSelf,
547-
&htup2,&buf2, false,NULL);
548-
values[1]=heap_getattr(&htup2,1,scan_state->inner->rd_att,
549-
&nulls[1]);
550-
551-
ReleaseBuffer(buf1);
552-
ReleaseBuffer(buf2);
545+
TupleDesctupdesc=node->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
546+
intcol_index=0;
547+
boolhtup_outer_ready= false;
548+
boolhtup_inner_ready= false;
549+
ListCell*l;
550+
551+
htup_outer.t_self=p_tids[0];
552+
htup_inner.t_self=p_tids[1];
553+
554+
foreach(l,scan_state->scan_tlist)
555+
{
556+
TargetEntry*target= (TargetEntry*)lfirst(l);
557+
Var*var= (Var*)target->expr;
558+
559+
if (var->varno==scan_state->outer_relid)
560+
{
561+
if (!htup_outer_ready)
562+
{
563+
htup_outer_ready= true;
564+
heap_fetch(scan_state->outer,SnapshotSelf,
565+
&htup_outer,&buf1, false,NULL);
566+
}
567+
568+
values[col_index]=heap_getattr(&htup_outer,var->varattno,
569+
scan_state->outer->rd_att,
570+
&nulls[col_index]);
571+
}
572+
573+
if (var->varno==scan_state->inner_relid)
574+
{
575+
if (!htup_inner_ready)
576+
{
577+
htup_inner_ready= true;
578+
heap_fetch(scan_state->inner,SnapshotSelf,
579+
&htup_inner,&buf2, false,NULL);
580+
}
581+
582+
values[col_index]=heap_getattr(&htup_inner,var->varattno,
583+
scan_state->outer->rd_att,
584+
&nulls[col_index]);
585+
}
586+
587+
col_index++;
588+
}
589+
590+
if (htup_outer_ready)
591+
ReleaseBuffer(buf1);
592+
if (htup_inner_ready)
593+
ReleaseBuffer(buf2);
553594

554595
htup=heap_form_tuple(tupdesc,values,nulls);
555596
scan_state->stored_tuple=htup;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp