- Notifications
You must be signed in to change notification settings - Fork28
Commit4867d7f
committed
Avoid out-of-memory in a hash join with many duplicate inner keys.
The executor is capable of splitting buckets during a hash join iftoo much memory is being used by a small number of buckets. However,this only helps if a bucket's population is actually divisible; ifall the hash keys are alike, the tuples still end up in the samenew bucket. This can result in an OOM failure if there are enoughinner keys with identical hash values. The planner's cost estimateswill bias it against choosing a hash join in such situations, but notby so much that it will never do so. To mitigate the OOM hazard,explicitly estimate the hash bucket space needed by just the innerside's most common value, and if that would exceed work_mem thenadd disable_cost to the hash cost estimate.This approach doesn't account for the possibility that two or morecommon values would share the same hash value. On the other hand,work_mem is normally a fairly conservative bound, so that eatingtwo or more times that much space is probably not going to kill us.If we have no stats about the inner side, ignore this consideration.There was some discussion of making a conservative assumption, but thatwould effectively result in disabling hash join whenever we lack stats,which seems like an overreaction given how seldom the problem manifestsin the field.Per a complaint from David Hinkle. Although this could be viewedas a bug fix, the lack of similar complaints weighs against back-patching; indeed we waited for v11 because it seemed already ratherlate in the v10 cycle to be making plan choice changes like this one.Discussion:https://postgr.es/m/32013.1487271761@sss.pgh.pa.us1 parentd9a622c commit4867d7f
File tree
7 files changed
+100
-49
lines changed- src
- backend
- nodes
- optimizer
- path
- prep
- util
- utils/adt
- include
- nodes
- utils
7 files changed
+100
-49
lines changedLines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2185 | 2185 |
| |
2186 | 2186 |
| |
2187 | 2187 |
| |
| 2188 | + | |
| 2189 | + | |
2188 | 2190 |
| |
2189 | 2191 |
| |
2190 | 2192 |
| |
|
Lines changed: 40 additions & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3028 | 3028 |
| |
3029 | 3029 |
| |
3030 | 3030 |
| |
| 3031 | + | |
3031 | 3032 |
| |
3032 | 3033 |
| |
3033 | 3034 |
| |
| |||
3060 | 3061 |
| |
3061 | 3062 |
| |
3062 | 3063 |
| |
3063 |
| - | |
3064 |
| - | |
3065 |
| - | |
| 3064 | + | |
| 3065 | + | |
| 3066 | + | |
3066 | 3067 |
| |
3067 | 3068 |
| |
3068 | 3069 |
| |
3069 | 3070 |
| |
3070 | 3071 |
| |
3071 | 3072 |
| |
3072 | 3073 |
| |
| 3074 | + | |
3073 | 3075 |
| |
| 3076 | + | |
| 3077 | + | |
3074 | 3078 |
| |
3075 | 3079 |
| |
3076 | 3080 |
| |
| 3081 | + | |
3077 | 3082 |
| |
3078 | 3083 |
| |
3079 | 3084 |
| |
3080 | 3085 |
| |
| 3086 | + | |
3081 | 3087 |
| |
3082 | 3088 |
| |
3083 | 3089 |
| |
3084 | 3090 |
| |
3085 | 3091 |
| |
3086 | 3092 |
| |
3087 |
| - | |
3088 |
| - | |
| 3093 | + | |
| 3094 | + | |
3089 | 3095 |
| |
3090 | 3096 |
| |
3091 | 3097 |
| |
| |||
3095 | 3101 |
| |
3096 | 3102 |
| |
3097 | 3103 |
| |
3098 |
| - | |
3099 |
| - | |
3100 |
| - | |
3101 |
| - | |
3102 |
| - | |
| 3104 | + | |
| 3105 | + | |
| 3106 | + | |
| 3107 | + | |
| 3108 | + | |
| 3109 | + | |
3103 | 3110 |
| |
| 3111 | + | |
3104 | 3112 |
| |
3105 | 3113 |
| |
3106 | 3114 |
| |
| |||
3111 | 3119 |
| |
3112 | 3120 |
| |
3113 | 3121 |
| |
3114 |
| - | |
3115 |
| - | |
3116 |
| - | |
3117 |
| - | |
3118 |
| - | |
| 3122 | + | |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
| 3127 | + | |
3119 | 3128 |
| |
| 3129 | + | |
3120 | 3130 |
| |
3121 | 3131 |
| |
3122 | 3132 |
| |
3123 | 3133 |
| |
| 3134 | + | |
| 3135 | + | |
3124 | 3136 |
| |
3125 | 3137 |
| |
3126 | 3138 |
| |
| 3139 | + | |
| 3140 | + | |
| 3141 | + | |
| 3142 | + | |
| 3143 | + | |
| 3144 | + | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
3127 | 3152 |
| |
3128 | 3153 |
| |
3129 | 3154 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2067 | 2067 |
| |
2068 | 2068 |
| |
2069 | 2069 |
| |
| 2070 | + | |
| 2071 | + | |
2070 | 2072 |
| |
2071 | 2073 |
| |
2072 | 2074 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
199 | 199 |
| |
200 | 200 |
| |
201 | 201 |
| |
| 202 | + | |
| 203 | + | |
202 | 204 |
| |
203 | 205 |
| |
204 | 206 |
| |
|
Lines changed: 48 additions & 32 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3559 | 3559 |
| |
3560 | 3560 |
| |
3561 | 3561 |
| |
3562 |
| - | |
3563 |
| - | |
3564 |
| - | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
3565 | 3572 |
| |
3566 | 3573 |
| |
3567 | 3574 |
| |
| |||
3587 | 3594 |
| |
3588 | 3595 |
| |
3589 | 3596 |
| |
| 3597 | + | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
| 3601 | + | |
| 3602 | + | |
3590 | 3603 |
| |
3591 |
| - | |
3592 |
| - | |
| 3604 | + | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
3593 | 3608 |
| |
3594 | 3609 |
| |
3595 | 3610 |
| |
3596 | 3611 |
| |
3597 | 3612 |
| |
3598 |
| - | |
3599 | 3613 |
| |
3600 | 3614 |
| |
3601 | 3615 |
| |
3602 | 3616 |
| |
3603 | 3617 |
| |
3604 | 3618 |
| |
| 3619 | + | |
| 3620 | + | |
| 3621 | + | |
| 3622 | + | |
| 3623 | + | |
| 3624 | + | |
| 3625 | + | |
| 3626 | + | |
| 3627 | + | |
| 3628 | + | |
| 3629 | + | |
| 3630 | + | |
| 3631 | + | |
| 3632 | + | |
| 3633 | + | |
| 3634 | + | |
| 3635 | + | |
| 3636 | + | |
3605 | 3637 |
| |
3606 | 3638 |
| |
3607 | 3639 |
| |
3608 |
| - | |
| 3640 | + | |
| 3641 | + | |
| 3642 | + | |
| 3643 | + | |
3609 | 3644 |
| |
3610 | 3645 |
| |
| 3646 | + | |
3611 | 3647 |
| |
3612 |
| - | |
| 3648 | + | |
3613 | 3649 |
| |
3614 | 3650 |
| |
3615 | 3651 |
| |
| |||
3650 | 3686 |
| |
3651 | 3687 |
| |
3652 | 3688 |
| |
3653 |
| - | |
3654 |
| - | |
3655 |
| - | |
3656 |
| - | |
3657 |
| - | |
3658 |
| - | |
3659 |
| - | |
3660 |
| - | |
3661 |
| - | |
3662 |
| - | |
3663 |
| - | |
3664 |
| - | |
3665 |
| - | |
3666 |
| - | |
3667 |
| - | |
3668 |
| - | |
3669 |
| - | |
3670 |
| - | |
3671 |
| - | |
3672 |
| - | |
3673 | 3689 |
| |
3674 | 3690 |
| |
3675 | 3691 |
| |
3676 |
| - | |
3677 |
| - | |
| 3692 | + | |
| 3693 | + | |
3678 | 3694 |
| |
3679 | 3695 |
| |
3680 | 3696 |
| |
| |||
3686 | 3702 |
| |
3687 | 3703 |
| |
3688 | 3704 |
| |
3689 |
| - | |
| 3705 | + | |
3690 | 3706 |
| |
3691 |
| - | |
| 3707 | + | |
3692 | 3708 |
| |
3693 | 3709 |
| |
3694 | 3710 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1807 | 1807 |
| |
1808 | 1808 |
| |
1809 | 1809 |
| |
| 1810 | + | |
| 1811 | + | |
1810 | 1812 |
| |
1811 | 1813 |
| |
1812 | 1814 |
| |
|
Lines changed: 4 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
206 | 206 |
| |
207 | 207 |
| |
208 | 208 |
| |
209 |
| - | |
210 |
| - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
211 | 213 |
| |
212 | 214 |
| |
213 | 215 |
| |
|
0 commit comments
Comments
(0)