- Notifications
You must be signed in to change notification settings - Fork5
Commitc1d9579
committed
Avoid listing ungrouped Vars in the targetlist of Agg-underneath-Window.
Regular aggregate functions in combination with, or within the argumentsof, window functions are OK per spec; they have the semantics that theaggregate output rows are computed and then we run the window functionsover that row set. (Thus, this combination is not really useful unlessthere's a GROUP BY so that more than one aggregate output row is possible.)The case without GROUP BY could fail, as recently reported by Jeff Davis,because sloppy construction of the Agg node's targetlist resulted in extrareferences to possibly-ungrouped Vars appearing outside the aggregatefunction calls themselves. See the added regression test case for anexample.Fixing this requires modifying the API of flatten_tlist and its underlyingfunction pull_var_clause. I chose to make pull_var_clause's API foraggregates identical to what it was already doing for placeholders, sincethe useful behaviors turn out to be the same (error, report node as-is, orrecurse into it). I also tightened the error checking in this area a bit:if it was ever valid to see an uplevel Var, Aggref, or PlaceHolderVar here,that was a long time ago, so complain instead of ignoring them.Backpatch into 9.1. The failure exists in 8.4 and 9.0 as well, but seeingthat it only occurs in a basically-useless corner case, it doesn't seemworth the risks of changing a function API in a minor release. There mightbe third-party code using pull_var_clause.1 parent846af54 commitc1d9579
File tree
18 files changed
+119
-78
lines changed- src
- backend
- catalog
- commands
- optimizer
- path
- plan
- prep
- util
- utils/adt
- include/optimizer
- test/regress
- expected
- sql
18 files changed
+119
-78
lines changedLines changed: 6 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1874 | 1874 |
| |
1875 | 1875 |
| |
1876 | 1876 |
| |
1877 |
| - | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
1878 | 1880 |
| |
1879 | 1881 |
| |
1880 | 1882 |
| |
| |||
2171 | 2173 |
| |
2172 | 2174 |
| |
2173 | 2175 |
| |
2174 |
| - | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
2175 | 2179 |
| |
2176 | 2180 |
| |
2177 | 2181 |
| |
|
Lines changed: 3 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
313 | 313 |
| |
314 | 314 |
| |
315 | 315 |
| |
316 |
| - | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
317 | 319 |
| |
318 | 320 |
| |
319 | 321 |
| |
|
Lines changed: 5 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1304 | 1304 |
| |
1305 | 1305 |
| |
1306 | 1306 |
| |
1307 |
| - | |
| 1307 | + | |
| 1308 | + | |
1308 | 1309 |
| |
1309 | 1310 |
| |
1310 | 1311 |
| |
1311 | 1312 |
| |
1312 | 1313 |
| |
1313 | 1314 |
| |
1314 | 1315 |
| |
1315 |
| - | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
1316 | 1319 |
| |
1317 | 1320 |
| |
1318 | 1321 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
847 | 847 |
| |
848 | 848 |
| |
849 | 849 |
| |
| 850 | + | |
850 | 851 |
| |
851 | 852 |
| |
852 | 853 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3552 | 3552 |
| |
3553 | 3553 |
| |
3554 | 3554 |
| |
| 3555 | + | |
3555 | 3556 |
| |
3556 | 3557 |
| |
3557 | 3558 |
| |
|
Lines changed: 4 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
132 | 132 |
| |
133 | 133 |
| |
134 | 134 |
| |
| 135 | + | |
135 | 136 |
| |
136 | 137 |
| |
137 | 138 |
| |
| |||
1030 | 1031 |
| |
1031 | 1032 |
| |
1032 | 1033 |
| |
1033 |
| - | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
1034 | 1037 |
| |
1035 | 1038 |
| |
1036 | 1039 |
| |
|
Lines changed: 20 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1474 | 1474 |
| |
1475 | 1475 |
| |
1476 | 1476 |
| |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
1477 | 1483 |
| |
1478 |
| - | |
1479 |
| - | |
1480 |
| - | |
1481 |
| - | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
1482 | 1487 |
| |
1483 | 1488 |
| |
1484 | 1489 |
| |
| |||
2577 | 2582 |
| |
2578 | 2583 |
| |
2579 | 2584 |
| |
2580 |
| - | |
2581 |
| - | |
2582 |
| - | |
2583 |
| - | |
2584 |
| - | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
2585 | 2590 |
| |
2586 |
| - | |
2587 |
| - | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
2588 | 2597 |
| |
2589 | 2598 |
| |
2590 | 2599 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
154 | 154 |
| |
155 | 155 |
| |
156 | 156 |
| |
| 157 | + | |
157 | 158 |
| |
158 | 159 |
| |
159 | 160 |
| |
|
Lines changed: 0 additions & 36 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
84 | 84 |
| |
85 | 85 |
| |
86 | 86 |
| |
87 |
| - | |
88 | 87 |
| |
89 | 88 |
| |
90 | 89 |
| |
| |||
418 | 417 |
| |
419 | 418 |
| |
420 | 419 |
| |
421 |
| - | |
422 |
| - | |
423 |
| - | |
424 |
| - | |
425 |
| - | |
426 |
| - | |
427 |
| - | |
428 |
| - | |
429 |
| - | |
430 |
| - | |
431 |
| - | |
432 |
| - | |
433 |
| - | |
434 |
| - | |
435 |
| - | |
436 |
| - | |
437 |
| - | |
438 |
| - | |
439 |
| - | |
440 |
| - | |
441 |
| - | |
442 |
| - | |
443 |
| - | |
444 |
| - | |
445 |
| - | |
446 |
| - | |
447 |
| - | |
448 |
| - | |
449 |
| - | |
450 |
| - | |
451 |
| - | |
452 |
| - | |
453 |
| - | |
454 |
| - | |
455 |
| - | |
456 | 420 |
| |
457 | 421 |
| |
458 | 422 |
| |
|
Lines changed: 4 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
201 | 201 |
| |
202 | 202 |
| |
203 | 203 |
| |
204 |
| - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
205 | 207 |
| |
206 | 208 |
| |
207 | 209 |
| |
| |||
348 | 350 |
| |
349 | 351 |
| |
350 | 352 |
| |
| 353 | + | |
351 | 354 |
| |
352 | 355 |
| |
353 | 356 |
| |
|
Lines changed: 6 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
76 | 76 |
| |
77 | 77 |
| |
78 | 78 |
| |
79 |
| - | |
80 |
| - | |
81 |
| - | |
| 79 | + | |
| 80 | + | |
82 | 81 |
| |
83 | 82 |
| |
84 | 83 |
| |
| |||
88 | 87 |
| |
89 | 88 |
| |
90 | 89 |
| |
91 |
| - | |
| 90 | + | |
| 91 | + | |
92 | 92 |
| |
93 | 93 |
| |
94 |
| - | |
| 94 | + | |
| 95 | + | |
95 | 96 |
| |
96 | 97 |
| |
97 | 98 |
| |
|
Lines changed: 42 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
56 | 56 |
| |
57 | 57 |
| |
58 | 58 |
| |
59 |
| - | |
| 59 | + | |
| 60 | + | |
60 | 61 |
| |
61 | 62 |
| |
62 | 63 |
| |
| |||
616 | 617 |
| |
617 | 618 |
| |
618 | 619 |
| |
619 |
| - | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
620 | 627 |
| |
621 | 628 |
| |
622 |
| - | |
| 629 | + | |
623 | 630 |
| |
624 | 631 |
| |
625 | 632 |
| |
626 | 633 |
| |
627 |
| - | |
628 |
| - | |
| 634 | + | |
| 635 | + | |
629 | 636 |
| |
630 | 637 |
| |
631 | 638 |
| |
| |||
634 | 641 |
| |
635 | 642 |
| |
636 | 643 |
| |
637 |
| - | |
| 644 | + | |
| 645 | + | |
638 | 646 |
| |
639 | 647 |
| |
640 | 648 |
| |
641 | 649 |
| |
642 |
| - | |
| 650 | + | |
| 651 | + | |
643 | 652 |
| |
644 | 653 |
| |
645 | 654 |
| |
| |||
652 | 661 |
| |
653 | 662 |
| |
654 | 663 |
| |
655 |
| - | |
656 |
| - | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
657 | 667 |
| |
658 | 668 |
| |
659 |
| - | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
660 | 688 |
| |
661 |
| - | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
662 | 692 |
| |
663 | 693 |
| |
664 | 694 |
| |
665 | 695 |
| |
666 | 696 |
| |
667 |
| - | |
668 |
| - | |
| 697 | + | |
669 | 698 |
| |
670 | 699 |
| |
671 | 700 |
| |
|
Lines changed: 3 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3090 | 3090 |
| |
3091 | 3091 |
| |
3092 | 3092 |
| |
3093 |
| - | |
| 3093 | + | |
| 3094 | + | |
| 3095 | + | |
3094 | 3096 |
| |
3095 | 3097 |
| |
3096 | 3098 |
| |
|
Lines changed: 0 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
48 | 48 |
| |
49 | 49 |
| |
50 | 50 |
| |
51 |
| - | |
52 | 51 |
| |
53 | 52 |
| |
54 | 53 |
| |
|
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
14 | 14 |
| |
15 | 15 |
| |
16 | 16 |
| |
17 |
| - | |
| 17 | + | |
18 | 18 |
| |
19 | 19 |
| |
20 | 20 |
| |
21 | 21 |
| |
22 | 22 |
| |
23 |
| - | |
| 23 | + | |
| 24 | + | |
24 | 25 |
| |
25 | 26 |
| |
26 | 27 |
| |
|
0 commit comments
Comments
(0)