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

Commit2762792

Browse files
committed
Convert SetOp to read its inputs as outerPlan and innerPlan.
The original design for set operations involved appending the twoinput relations into one and adding a flag column that allowsdistinguishing which side each row came from. Then the SetOp nodepries them apart again based on the flag. This is bizarre. Theonly apparent reason to do it is that when sorting, we'd only needone Sort node not two. But since sorting is at least O(N log N),sorting all the data is actually worse than sorting each sideseparately --- plus, we have no chance of taking advantage ofpresorted input. On top of that, adding the flag column frequentlyrequires an additional projection step that adds cycles, and thenthe Append node isn't free either. Let's get rid of all of thatand make the SetOp node have two separate children, using theexisting outerPlan/innerPlan infrastructure.This initial patch re-implements nodeSetop.c and does a bare minimumof work on the planner side to generate correctly-shaped plans.In particular, I've tried not to change the cost estimates here,so that the visible changes in the regression test results will onlyinvolve removal of useless projection steps and not any changes inwhether to use sorted vs hashed mode.For SORTED mode, we combine successive identical tuples from eachinput into groups, and then merge-join the groups. The tuplecomparisons now use SortSupport instead of simple equality, butthe group-formation part should involve roughly the same number oftuple comparisons as before. The cross-comparisons between left andright groups probably add to that, but I'm not sure to quantify howmany more comparisons we might need.For HASHED mode, nodeSetop's logic is almost the same as before,just refactored into two separate loops instead of one loop thathas an assumption that it will see all the left-hand inputs first.In both modes, I added early-exit logic to not bother reading theright-hand relation if the left-hand input is empty, since neitherINTERSECT nor EXCEPT modes can produce any output if the left inputis empty. This could have been done before in the hashed mode, butnot in sorted mode. Sorted mode can also stop as soon as it exhauststhe left input; any remaining right-hand tuples cannot have matches.Also, this patch adds some infrastructure for detecting whetherchild plan nodes all output the same type of tuple table slot.If they do, the hash table logic can use slightly more efficientcode based on assuming that that's the input slot type it will see.We'll make use of that infrastructure in other plan node types later.Patch by me; thanks to Richard Guo and David Rowley for review.Discussion:https://postgr.es/m/1850138.1731549611@sss.pgh.pa.us
1 parent2128ceb commit2762792

File tree

15 files changed

+696
-524
lines changed

15 files changed

+696
-524
lines changed

‎src/backend/executor/execUtils.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,49 @@ ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
526526
returnplanstate->ps_ResultTupleSlot->tts_ops;
527527
}
528528

529+
/*
530+
* ExecGetCommonSlotOps - identify common result slot type, if any
531+
*
532+
* If all the given PlanState nodes return the same fixed tuple slot type,
533+
* return the slot ops struct for that slot type. Else, return NULL.
534+
*/
535+
constTupleTableSlotOps*
536+
ExecGetCommonSlotOps(PlanState**planstates,intnplans)
537+
{
538+
constTupleTableSlotOps*result;
539+
boolisfixed;
540+
541+
if (nplans <=0)
542+
returnNULL;
543+
result=ExecGetResultSlotOps(planstates[0],&isfixed);
544+
if (!isfixed)
545+
returnNULL;
546+
for (inti=1;i<nplans;i++)
547+
{
548+
constTupleTableSlotOps*thisops;
549+
550+
thisops=ExecGetResultSlotOps(planstates[i],&isfixed);
551+
if (!isfixed)
552+
returnNULL;
553+
if (result!=thisops)
554+
returnNULL;
555+
}
556+
returnresult;
557+
}
558+
559+
/*
560+
* ExecGetCommonChildSlotOps - as above, for the PlanState's standard children
561+
*/
562+
constTupleTableSlotOps*
563+
ExecGetCommonChildSlotOps(PlanState*ps)
564+
{
565+
PlanState*planstates[2];
566+
567+
planstates[0]=outerPlanState(ps);
568+
planstates[1]=innerPlanState(ps);
569+
returnExecGetCommonSlotOps(planstates,2);
570+
}
571+
529572

530573
/* ----------------
531574
*ExecAssignProjectionInfo

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp