forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit2762792
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.us1 parent2128ceb commit2762792
File tree
15 files changed
+696
-524
lines changed- src
- backend
- executor
- optimizer
- plan
- prep
- util
- include
- executor
- nodes
- optimizer
- test/regress
- expected
- sql
- tools/pgindent
15 files changed
+696
-524
lines changedLines changed: 43 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
526 | 526 |
| |
527 | 527 |
| |
528 | 528 |
| |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
529 | 572 |
| |
530 | 573 |
| |
531 | 574 |
| |
|
0 commit comments
Comments
(0)