- Notifications
You must be signed in to change notification settings - Fork5
Commit84f9a35
committed
Improve estimate of distinct values in estimate_num_groups().
When adjusting the estimate for the number of distinct values from arel in a grouped query to take into account the selectivity of therel's restrictions, use a formula that is less likely to produceunder-estimates.The old formula simply multiplied the number of distinct values in therel by the restriction selectivity, which would be correct if therestrictions were fully correlated with the grouping expressions, butcan produce significant under-estimates in cases where they are notwell correlated.The new formula is based on the random selection probability, and soassumes that the restrictions are not correlated with the groupingexpressions. This is guaranteed to produce larger estimates, and ofcourse risks over-estimating in cases where the restrictions arecorrelated, but that has less severe consequences thanunder-estimating, which might lead to a HashAgg that consumes anexcessive amount of memory.This could possibly be improved upon in the future by identifyingcorrelated restrictions and using a hybrid of the old and newformulae.Author: Tomas Vondra, with some hacking be meReviewed-by: Mark Dilger, Alexander Korotkov, Dean Rasheed and Tom LaneDiscussion:http://www.postgresql.org/message-id/flat/56CD0381.5060502@2ndquadrant.com1 parentbf08f22 commit84f9a35
File tree
2 files changed
+64
-25
lines changed- src
- backend/utils/adt
- test/regress/expected
2 files changed
+64
-25
lines changedLines changed: 53 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3237 | 3237 |
| |
3238 | 3238 |
| |
3239 | 3239 |
| |
3240 |
| - | |
3241 |
| - | |
3242 |
| - | |
3243 |
| - | |
3244 |
| - | |
3245 |
| - | |
3246 |
| - | |
3247 |
| - | |
3248 |
| - | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
| 3243 | + | |
| 3244 | + | |
| 3245 | + | |
| 3246 | + | |
| 3247 | + | |
| 3248 | + | |
3249 | 3249 |
| |
3250 | 3250 |
| |
3251 | 3251 |
| |
| |||
3439 | 3439 |
| |
3440 | 3440 |
| |
3441 | 3441 |
| |
3442 |
| - | |
| 3442 | + | |
| 3443 | + | |
| 3444 | + | |
3443 | 3445 |
| |
3444 |
| - | |
| 3446 | + | |
| 3447 | + | |
| 3448 | + | |
| 3449 | + | |
| 3450 | + | |
| 3451 | + | |
| 3452 | + | |
| 3453 | + | |
| 3454 | + | |
| 3455 | + | |
| 3456 | + | |
| 3457 | + | |
| 3458 | + | |
| 3459 | + | |
| 3460 | + | |
| 3461 | + | |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
| 3466 | + | |
| 3467 | + | |
| 3468 | + | |
| 3469 | + | |
| 3470 | + | |
| 3471 | + | |
| 3472 | + | |
| 3473 | + | |
| 3474 | + | |
| 3475 | + | |
| 3476 | + | |
| 3477 | + | |
| 3478 | + | |
| 3479 | + | |
| 3480 | + | |
| 3481 | + | |
| 3482 | + | |
| 3483 | + | |
| 3484 | + | |
| 3485 | + | |
| 3486 | + | |
3445 | 3487 |
| |
3446 | 3488 |
| |
3447 | 3489 |
| |
|
Lines changed: 11 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
807 | 807 |
| |
808 | 808 |
| |
809 | 809 |
| |
810 |
| - | |
811 |
| - | |
812 |
| - | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
813 | 813 |
| |
814 | 814 |
| |
815 | 815 |
| |
816 | 816 |
| |
817 | 817 |
| |
818 | 818 |
| |
819 |
| - | |
| 819 | + | |
820 | 820 |
| |
821 |
| - | |
822 |
| - | |
823 |
| - | |
824 |
| - | |
825 |
| - | |
826 |
| - | |
827 |
| - | |
828 |
| - | |
829 |
| - | |
830 |
| - | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
831 | 828 |
| |
832 | 829 |
| |
833 | 830 |
| |
|
0 commit comments
Comments
(0)