forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitcc5d985

Richard Guo
Fix incorrect handling of subquery pullup
When pulling up a subquery, if the subquery's target list items areused in grouping set columns, we need to wrap them in PlaceHolderVars.This ensures that expressions retain their separate identity so thatthey will match grouping set columns when appropriate.In9094767, we decided to wrap subquery outputs that are non-varexpressions in PlaceHolderVars. This prevents const-simplificationfrom merging them into the surrounding expressions after subquerypullup, which could otherwise lead to failing to match thosesubexpressions to grouping set columns, with the effect that they'dnot go to null when expected.However, that left some loose ends. If the subquery's target listcontains two or more identical Var expressions, we can still fail tomatch the Var expression to the expected grouping set expression.This is not related to const-simplification, but rather to how wematch expressions to lower target items in setrefs.c.For sort/group expressions, we use ressortgroupref matching, whichworks well. For other expressions, we primarily rely on comparing theexpressions to determine if they are the same. Therefore, we need away to prevent setrefs.c from matching the expression to some otheridentical ones.To fix, wrap all subquery outputs in PlaceHolderVars if the parentquery uses grouping sets, ensuring that they preserve their separateidentity throughout the whole planning process.Reported-by: Dean Rasheed <dean.a.rasheed@gmail.com>Author: Richard Guo <guofenglinux@gmail.com>Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>Discussion:https://postgr.es/m/CAMbWs4-meSahaanKskpBn0KKxdHAXC1_EJCVWHxEodqirrGJnw@mail.gmail.com1 parent4c49611 commitcc5d985
File tree
5 files changed
+93
-43
lines changed- src
- backend
- optimizer/prep
- rewrite
- test/regress
- expected
- sql
- tools/pgindent
5 files changed
+93
-43
lines changedLines changed: 51 additions & 42 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
57 | 57 |
| |
58 | 58 |
| |
59 | 59 |
| |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
60 | 69 |
| |
61 | 70 |
| |
62 | 71 |
| |
| |||
70 | 79 |
| |
71 | 80 |
| |
72 | 81 |
| |
73 |
| - | |
| 82 | + | |
74 | 83 |
| |
75 | 84 |
| |
76 | 85 |
| |
| |||
1025 | 1034 |
| |
1026 | 1035 |
| |
1027 | 1036 |
| |
1028 |
| - | |
| 1037 | + | |
1029 | 1038 |
| |
1030 | 1039 |
| |
1031 | 1040 |
| |
1032 | 1041 |
| |
1033 | 1042 |
| |
1034 | 1043 |
| |
1035 |
| - | |
1036 |
| - | |
1037 |
| - | |
1038 |
| - | |
1039 |
| - | |
1040 |
| - | |
1041 |
| - | |
| 1044 | + | |
| 1045 | + | |
1042 | 1046 |
| |
1043 | 1047 |
| |
1044 |
| - | |
| 1048 | + | |
1045 | 1049 |
| |
1046 | 1050 |
| |
1047 | 1051 |
| |
| |||
1435 | 1439 |
| |
1436 | 1440 |
| |
1437 | 1441 |
| |
1438 |
| - | |
| 1442 | + | |
1439 | 1443 |
| |
1440 | 1444 |
| |
1441 | 1445 |
| |
1442 | 1446 |
| |
1443 | 1447 |
| |
1444 | 1448 |
| |
1445 |
| - | |
1446 |
| - | |
1447 |
| - | |
1448 |
| - | |
1449 |
| - | |
1450 |
| - | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
1451 | 1455 |
| |
1452 | 1456 |
| |
1453 |
| - | |
| 1457 | + | |
1454 | 1458 |
| |
1455 | 1459 |
| |
1456 | 1460 |
| |
| |||
1976 | 1980 |
| |
1977 | 1981 |
| |
1978 | 1982 |
| |
1979 |
| - | |
| 1983 | + | |
1980 | 1984 |
| |
1981 | 1985 |
| |
1982 | 1986 |
| |
| |||
2144 | 2148 |
| |
2145 | 2149 |
| |
2146 | 2150 |
| |
2147 |
| - | |
| 2151 | + | |
2148 | 2152 |
| |
2149 | 2153 |
| |
2150 | 2154 |
| |
2151 | 2155 |
| |
2152 | 2156 |
| |
2153 | 2157 |
| |
2154 |
| - | |
| 2158 | + | |
2155 | 2159 |
| |
2156 | 2160 |
| |
2157 | 2161 |
| |
2158 |
| - | |
| 2162 | + | |
2159 | 2163 |
| |
2160 | 2164 |
| |
2161 | 2165 |
| |
| |||
2406 | 2410 |
| |
2407 | 2411 |
| |
2408 | 2412 |
| |
2409 |
| - | |
| 2413 | + | |
2410 | 2414 |
| |
2411 |
| - | |
| 2415 | + | |
2412 | 2416 |
| |
2413 | 2417 |
| |
2414 | 2418 |
| |
2415 |
| - | |
| 2419 | + | |
2416 | 2420 |
| |
2417 | 2421 |
| |
2418 | 2422 |
| |
| |||
2573 | 2577 |
| |
2574 | 2578 |
| |
2575 | 2579 |
| |
2576 |
| - | |
| 2580 | + | |
2577 | 2581 |
| |
2578 | 2582 |
| |
2579 | 2583 |
| |
2580 | 2584 |
| |
2581 | 2585 |
| |
2582 |
| - | |
2583 |
| - | |
2584 |
| - | |
2585 |
| - | |
2586 |
| - | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
2587 | 2591 |
| |
2588 | 2592 |
| |
2589 |
| - | |
| 2593 | + | |
2590 | 2594 |
| |
2591 | 2595 |
| |
2592 | 2596 |
| |
2593 |
| - | |
| 2597 | + | |
2594 | 2598 |
| |
2595 | 2599 |
| |
2596 | 2600 |
| |
| |||
2630 | 2634 |
| |
2631 | 2635 |
| |
2632 | 2636 |
| |
2633 |
| - | |
| 2637 | + | |
2634 | 2638 |
| |
2635 | 2639 |
| |
2636 |
| - | |
| 2640 | + | |
| 2641 | + | |
2637 | 2642 |
| |
2638 | 2643 |
| |
2639 | 2644 |
| |
| |||
2673 | 2678 |
| |
2674 | 2679 |
| |
2675 | 2680 |
| |
2676 |
| - | |
| 2681 | + | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + | |
| 2685 | + | |
| 2686 | + | |
2677 | 2687 |
| |
2678 | 2688 |
| |
2679 | 2689 |
| |
| |||
2733 | 2743 |
| |
2734 | 2744 |
| |
2735 | 2745 |
| |
2736 |
| - | |
2737 |
| - | |
2738 |
| - | |
2739 |
| - | |
2740 |
| - | |
2741 | 2746 |
| |
2742 | 2747 |
| |
2743 | 2748 |
| |
| |||
2769 | 2774 |
| |
2770 | 2775 |
| |
2771 | 2776 |
| |
2772 |
| - | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
2773 | 2782 |
| |
2774 | 2783 |
| |
2775 | 2784 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1421 | 1421 |
| |
1422 | 1422 |
| |
1423 | 1423 |
| |
1424 |
| - | |
| 1424 | + | |
1425 | 1425 |
| |
1426 | 1426 |
| |
1427 | 1427 |
| |
|
Lines changed: 29 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
434 | 434 |
| |
435 | 435 |
| |
436 | 436 |
| |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
437 | 466 |
| |
438 | 467 |
| |
439 | 468 |
| |
|
Lines changed: 11 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
172 | 172 |
| |
173 | 173 |
| |
174 | 174 |
| |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
175 | 186 |
| |
176 | 187 |
| |
177 | 188 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2477 | 2477 |
| |
2478 | 2478 |
| |
2479 | 2479 |
| |
| 2480 | + | |
2480 | 2481 |
| |
2481 | 2482 |
| |
2482 | 2483 |
| |
|
0 commit comments
Comments
(0)