- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit2abd7ae
committed
Fix representation of hash keys in Hash/HashJoin nodes.
In5f32b29 I changed the creation of HashState.hashkeys toactually use HashState as the parent (instead of HashJoinState, whichwas incorrect, as they were executed below HashState), to fix theproblem of hashkeys expressions otherwise relying on slot typesappropriate for HashJoinState, rather than HashState as would becorrect. That reliance was only introduced in 12, which is why itpreviously worked to use HashJoinState as the parent (although I'd beunsurprised if there were problematic cases).Unfortunately that's not a sufficient solution, because before thiscommit, the to-be-hashed expressions referenced inner/outer asappropriate for the HashJoin, not Hash. That didn't have obvious badconsequences, because the slots containing the tuples were put intoecxt_innertuple when hashing a tuple for HashState (even though Hashdoesn't have an inner plan).There are less common cases where this can cause visible problemshowever (rather than just confusion when inspecting such executortrees). E.g. "ERROR: bogus varno: 65000", when explaining queriescontaining a HashJoin where the subsidiary Hash node's hash keysreference a subplan. While normally hashkeys aren't displayed byEXPLAIN, if one of those expressions references a subplan, thatsubplan may be printed as part of the Hash node - which then failedbecause an inner plan was referenced, and Hash doesn't have that.It seems quite possible that there's other broken cases, too.Fix the problem by properly splitting the expression for the HashJoinand Hash nodes at plan time, and have them reference the propersubsidiary node. While other workarounds are possible, fixing thiscorrectly seems easy enough. It was a pretty ugly hack to haveExecInitHashJoin put the expression into the already initializedHashState, in the first place.I decided to not just split inner/outer hashkeys insidemake_hashjoin(), but also to separate out hashoperators andhashcollations at plan time. Otherwise we would have ended up havingtwo very similar loops, one at plan time and the other during executorstartup. The work seems to more appropriately belong to plan time,anyway.Reported-By: Nikita Glukhov, Alexander KorotkovAuthor: Andres FreundReviewed-By: Tom Lane, in an earlier versionDiscussion:https://postgr.es/m/CAPpHfdvGVegF_TKKRiBrSmatJL2dR9uwFCuR+teQ_8tEXU8mxg@mail.gmail.comBackpatch: 12-1 parenta9f301d commit2abd7ae
File tree
11 files changed
+330
-47
lines changed- src
- backend
- executor
- nodes
- optimizer/plan
- include/nodes
- test/regress
- expected
- sql
11 files changed
+330
-47
lines changedLines changed: 14 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
157 | 157 |
| |
158 | 158 |
| |
159 | 159 |
| |
160 |
| - | |
| 160 | + | |
| 161 | + | |
161 | 162 |
| |
162 | 163 |
| |
163 | 164 |
| |
164 | 165 |
| |
165 | 166 |
| |
166 | 167 |
| |
167 | 168 |
| |
168 |
| - | |
| 169 | + | |
169 | 170 |
| |
170 | 171 |
| |
171 | 172 |
| |
| |||
281 | 282 |
| |
282 | 283 |
| |
283 | 284 |
| |
284 |
| - | |
| 285 | + | |
285 | 286 |
| |
286 | 287 |
| |
287 | 288 |
| |
| |||
388 | 389 |
| |
389 | 390 |
| |
390 | 391 |
| |
391 |
| - | |
392 |
| - | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
393 | 395 |
| |
394 | 396 |
| |
395 | 397 |
| |
| |||
1773 | 1775 |
| |
1774 | 1776 |
| |
1775 | 1777 |
| |
1776 |
| - | |
1777 |
| - | |
1778 |
| - | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
1779 | 1785 |
| |
1780 | 1786 |
| |
1781 | 1787 |
| |
|
Lines changed: 4 additions & 36 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
600 | 600 |
| |
601 | 601 |
| |
602 | 602 |
| |
603 |
| - | |
604 |
| - | |
605 |
| - | |
606 |
| - | |
607 |
| - | |
608 | 603 |
| |
609 | 604 |
| |
610 |
| - | |
611 | 605 |
| |
612 | 606 |
| |
613 | 607 |
| |
| |||
730 | 724 |
| |
731 | 725 |
| |
732 | 726 |
| |
733 |
| - | |
734 |
| - | |
735 |
| - | |
736 |
| - | |
737 |
| - | |
738 |
| - | |
739 |
| - | |
740 |
| - | |
741 |
| - | |
742 |
| - | |
743 |
| - | |
744 |
| - | |
745 |
| - | |
746 |
| - | |
747 |
| - | |
748 |
| - | |
749 |
| - | |
750 |
| - | |
751 |
| - | |
752 |
| - | |
753 |
| - | |
754 |
| - | |
755 |
| - | |
756 |
| - | |
757 |
| - | |
758 |
| - | |
759 |
| - | |
760 |
| - | |
761 |
| - | |
762 |
| - | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
763 | 731 |
| |
764 | 732 |
| |
765 | 733 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
899 | 899 |
| |
900 | 900 |
| |
901 | 901 |
| |
| 902 | + | |
| 903 | + | |
| 904 | + | |
902 | 905 |
| |
903 | 906 |
| |
904 | 907 |
| |
| |||
1066 | 1069 |
| |
1067 | 1070 |
| |
1068 | 1071 |
| |
| 1072 | + | |
1069 | 1073 |
| |
1070 | 1074 |
| |
1071 | 1075 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
761 | 761 |
| |
762 | 762 |
| |
763 | 763 |
| |
| 764 | + | |
| 765 | + | |
| 766 | + | |
764 | 767 |
| |
765 | 768 |
| |
766 | 769 |
| |
| |||
863 | 866 |
| |
864 | 867 |
| |
865 | 868 |
| |
| 869 | + | |
866 | 870 |
| |
867 | 871 |
| |
868 | 872 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2096 | 2096 |
| |
2097 | 2097 |
| |
2098 | 2098 |
| |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
2099 | 2102 |
| |
2100 | 2103 |
| |
2101 | 2104 |
| |
| |||
2274 | 2277 |
| |
2275 | 2278 |
| |
2276 | 2279 |
| |
| 2280 | + | |
2277 | 2281 |
| |
2278 | 2282 |
| |
2279 | 2283 |
| |
|
Lines changed: 38 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
222 | 222 |
| |
223 | 223 |
| |
224 | 224 |
| |
| 225 | + | |
| 226 | + | |
225 | 227 |
| |
226 | 228 |
| |
227 | 229 |
| |
| 230 | + | |
228 | 231 |
| |
229 | 232 |
| |
230 | 233 |
| |
| |||
4380 | 4383 |
| |
4381 | 4384 |
| |
4382 | 4385 |
| |
| 4386 | + | |
| 4387 | + | |
| 4388 | + | |
| 4389 | + | |
4383 | 4390 |
| |
4384 | 4391 |
| |
4385 | 4392 |
| |
| 4393 | + | |
4386 | 4394 |
| |
4387 | 4395 |
| |
4388 | 4396 |
| |
| |||
4474 | 4482 |
| |
4475 | 4483 |
| |
4476 | 4484 |
| |
| 4485 | + | |
| 4486 | + | |
| 4487 | + | |
| 4488 | + | |
| 4489 | + | |
| 4490 | + | |
| 4491 | + | |
| 4492 | + | |
| 4493 | + | |
| 4494 | + | |
| 4495 | + | |
| 4496 | + | |
| 4497 | + | |
| 4498 | + | |
| 4499 | + | |
| 4500 | + | |
| 4501 | + | |
| 4502 | + | |
4477 | 4503 |
| |
4478 | 4504 |
| |
4479 | 4505 |
| |
4480 | 4506 |
| |
| 4507 | + | |
4481 | 4508 |
| |
4482 | 4509 |
| |
4483 | 4510 |
| |
| |||
4504 | 4531 |
| |
4505 | 4532 |
| |
4506 | 4533 |
| |
| 4534 | + | |
| 4535 | + | |
| 4536 | + | |
4507 | 4537 |
| |
4508 | 4538 |
| |
4509 | 4539 |
| |
| |||
5545 | 5575 |
| |
5546 | 5576 |
| |
5547 | 5577 |
| |
| 5578 | + | |
| 5579 | + | |
| 5580 | + | |
5548 | 5581 |
| |
5549 | 5582 |
| |
5550 | 5583 |
| |
| |||
5558 | 5591 |
| |
5559 | 5592 |
| |
5560 | 5593 |
| |
| 5594 | + | |
| 5595 | + | |
| 5596 | + | |
5561 | 5597 |
| |
5562 | 5598 |
| |
5563 | 5599 |
| |
| |||
5567 | 5603 |
| |
5568 | 5604 |
| |
5569 | 5605 |
| |
| 5606 | + | |
5570 | 5607 |
| |
5571 | 5608 |
| |
5572 | 5609 |
| |
| |||
5579 | 5616 |
| |
5580 | 5617 |
| |
5581 | 5618 |
| |
| 5619 | + | |
5582 | 5620 |
| |
5583 | 5621 |
| |
5584 | 5622 |
| |
|
Lines changed: 44 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
107 | 107 |
| |
108 | 108 |
| |
109 | 109 |
| |
| 110 | + | |
110 | 111 |
| |
111 | 112 |
| |
112 | 113 |
| |
| |||
646 | 647 |
| |
647 | 648 |
| |
648 | 649 |
| |
| 650 | + | |
| 651 | + | |
| 652 | + | |
649 | 653 |
| |
650 | 654 |
| |
651 | 655 |
| |
| |||
1419 | 1423 |
| |
1420 | 1424 |
| |
1421 | 1425 |
| |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
1422 | 1456 |
| |
1423 | 1457 |
| |
1424 | 1458 |
| |
| |||
1754 | 1788 |
| |
1755 | 1789 |
| |
1756 | 1790 |
| |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
1757 | 1801 |
| |
1758 | 1802 |
| |
1759 | 1803 |
| |
|
Lines changed: 0 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1852 | 1852 |
| |
1853 | 1853 |
| |
1854 | 1854 |
| |
1855 |
| - | |
1856 | 1855 |
| |
1857 | 1856 |
| |
1858 | 1857 |
| |
| |||
1883 | 1882 |
| |
1884 | 1883 |
| |
1885 | 1884 |
| |
1886 |
| - | |
1887 | 1885 |
| |
1888 | 1886 |
| |
1889 | 1887 |
| |
| |||
2222 | 2220 |
| |
2223 | 2221 |
| |
2224 | 2222 |
| |
2225 |
| - | |
2226 | 2223 |
| |
2227 | 2224 |
| |
2228 | 2225 |
| |
|
Lines changed: 14 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
737 | 737 |
| |
738 | 738 |
| |
739 | 739 |
| |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
740 | 748 |
| |
741 | 749 |
| |
742 | 750 |
| |
| |||
899 | 907 |
| |
900 | 908 |
| |
901 | 909 |
| |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
902 | 916 |
| |
903 | 917 |
| |
904 | 918 |
| |
|
0 commit comments
Comments
(0)