- Notifications
You must be signed in to change notification settings - Fork4.9k
Commitdf3a66e
committed
Improve planner's handling of set-returning functions in grouping columns.
Improve query_is_distinct_for() to accept SRFs in the targetlist whenwe can prove distinctness from a DISTINCT clause. In that case thede-duplication will surely happen after SRF expansion, so the proofstill works. Continue to punt in the case where we'd try to provedistinctness from GROUP BY (or, in the future, source relations).To do that, we'd have to determine whether the SRFs were in thegrouping columns or elsewhere in the tlist, and it still doesn'tseem worth the trouble. But this trivial change allows us torecognize that "SELECT DISTINCT unnest(foo) FROM ..." producesunique-ified output, which seems worth having.Also, fix estimate_num_groups() to consider the possibility of SRFs inthe grouping columns. Its failure to do so was masked before v10 becausegrouping_planner() scaled up plan rowcount estimates by the estimated SRFmultiplier after performing grouping. That doesn't happen anymore, whichis more correct, but it means we need an adjustment in the estimate forthe number of groups. Failure to do this leads to an underestimate forthe number of output rows of subqueries like "SELECT DISTINCT unnest(foo)"compared to what 9.6 and earlier estimated, thus breaking plan choicesin some cases.Per report from Dmitry Shalashov. Back-patch to v10 to avoid degradedplan choices compared to previous releases.Discussion:https://postgr.es/m/CAKPeCUGAeHgoh5O=SvcQxREVkoX7UdeJUMj1F5=aBNvoTa+O8w@mail.gmail.com1 parentb10967e commitdf3a66e
File tree
2 files changed
+41
-14
lines changed- src/backend
- optimizer/plan
- utils/adt
2 files changed
+41
-14
lines changedLines changed: 14 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
744 | 744 |
| |
745 | 745 |
| |
746 | 746 |
| |
747 |
| - | |
748 |
| - | |
| 747 | + | |
| 748 | + | |
749 | 749 |
| |
750 | 750 |
| |
751 | 751 |
| |
| |||
786 | 786 |
| |
787 | 787 |
| |
788 | 788 |
| |
789 |
| - | |
790 |
| - | |
791 |
| - | |
792 |
| - | |
793 |
| - | |
794 |
| - | |
795 |
| - | |
796 |
| - | |
797 |
| - | |
798 |
| - | |
799 |
| - | |
800 | 789 |
| |
801 | 790 |
| |
802 | 791 |
| |
803 |
| - | |
| 792 | + | |
| 793 | + | |
804 | 794 |
| |
805 | 795 |
| |
806 | 796 |
| |
| |||
819 | 809 |
| |
820 | 810 |
| |
821 | 811 |
| |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
822 | 822 |
| |
823 | 823 |
| |
824 | 824 |
| |
|
Lines changed: 27 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3361 | 3361 |
| |
3362 | 3362 |
| |
3363 | 3363 |
| |
| 3364 | + | |
3364 | 3365 |
| |
3365 | 3366 |
| |
3366 | 3367 |
| |
| |||
3394 | 3395 |
| |
3395 | 3396 |
| |
3396 | 3397 |
| |
| 3398 | + | |
3397 | 3399 |
| |
3398 | 3400 |
| |
3399 | 3401 |
| |
| |||
3402 | 3404 |
| |
3403 | 3405 |
| |
3404 | 3406 |
| |
| 3407 | + | |
| 3408 | + | |
| 3409 | + | |
| 3410 | + | |
| 3411 | + | |
| 3412 | + | |
| 3413 | + | |
| 3414 | + | |
| 3415 | + | |
| 3416 | + | |
| 3417 | + | |
| 3418 | + | |
| 3419 | + | |
| 3420 | + | |
| 3421 | + | |
3405 | 3422 |
| |
3406 | 3423 |
| |
3407 | 3424 |
| |
| |||
3467 | 3484 |
| |
3468 | 3485 |
| |
3469 | 3486 |
| |
| 3487 | + | |
| 3488 | + | |
| 3489 | + | |
| 3490 | + | |
3470 | 3491 |
| |
3471 | 3492 |
| |
3472 | 3493 |
| |
| 3494 | + | |
| 3495 | + | |
3473 | 3496 |
| |
3474 | 3497 |
| |
3475 | 3498 |
| |
| |||
3638 | 3661 |
| |
3639 | 3662 |
| |
3640 | 3663 |
| |
| 3664 | + | |
| 3665 | + | |
| 3666 | + | |
| 3667 | + | |
3641 | 3668 |
| |
3642 | 3669 |
| |
3643 | 3670 |
| |
|
0 commit comments
Comments
(0)