- Notifications
You must be signed in to change notification settings - Fork5
Commit269c5dd
committed
Fix window functions that sort by expressions involving aggregates.
In commitc1d9579, I changed things sothat the output of the Agg node that feeds the window functions would notlist any ungrouped Vars directly. Formerly, for example, the Agg tlistmight have included both "x" and "sum(x)", which is not really valid if"x" isn't a grouping column. If we then had a window function ordering onsomething like "sum(x) + 1", prepare_sort_from_pathkeys would find no exactmatch for this in the Agg tlist, and would conclude that it must recomputethe expression. But it would break the expression down to just the Var"x", which it would find in the tlist, and then rebuild the ORDER BYexpression using a reference to the subplan's "x" output. Now, after theabove-referenced changes, "x" isn't in the Agg tlist if it's not a groupingcolumn, so that prepare_sort_from_pathkeys fails with "could not findpathkey item to sort", as reported by Bricklen Anderson.The fix is to not break down Aggrefs into their component parts, but justtreat them as irreducible expressions to be sought in the subplan tlist.This is definitely OK for the use with respect to window functions ingrouping_planner, since it just built the tlist being used on the samebasis. AFAICT it is safe for other uses too; most of the other call sitescouldn't encounter Aggrefs anyway.1 parent57eb009 commit269c5dd
File tree
3 files changed
+35
-2
lines changed- src
- backend/optimizer/plan
- test/regress
- expected
- sql
3 files changed
+35
-2
lines changedLines changed: 8 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3533 | 3533 |
| |
3534 | 3534 |
| |
3535 | 3535 |
| |
3536 |
| - | |
| 3536 | + | |
| 3537 | + | |
| 3538 | + | |
| 3539 | + | |
| 3540 | + | |
| 3541 | + | |
| 3542 | + | |
3537 | 3543 |
| |
3538 | 3544 |
| |
3539 | 3545 |
| |
| |||
3546 | 3552 |
| |
3547 | 3553 |
| |
3548 | 3554 |
| |
3549 |
| - | |
| 3555 | + | |
3550 | 3556 |
| |
3551 | 3557 |
| |
3552 | 3558 |
| |
|
Lines changed: 20 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
594 | 594 |
| |
595 | 595 |
| |
596 | 596 |
| |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
597 | 617 |
| |
598 | 618 |
| |
599 | 619 |
| |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
138 | 138 |
| |
139 | 139 |
| |
140 | 140 |
| |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
141 | 148 |
| |
142 | 149 |
| |
143 | 150 |
| |
|
0 commit comments
Comments
(0)