forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit2657283
committed
Minimally fix partial aggregation for aggregates that don't have one argument.
For partial aggregation combine steps,AggStatePerTrans->numTransInputs was set to the transition function'snumber of inputs, rather than the combine function's number ofinputs (always 1).That lead to partial aggregates with strict combine functions towrongly check for NOT NULL input as required by strictness. When theaggregate wasn't exactly passed one argument, the strictness check waseither omitted (in the 0 args case) or too many arguments werechecked. In the latter case we'd read beyond the end ofFunctionCallInfoData->args (only in master).AggStatePerTrans->numTransInputs actually has been wrong since since9.6, where partial aggregates were added. But it turns out to not bean active problem in 9.6 and 10, because numTransInputs wasn't used atall for combine functions: Beforec253b72 there simply was no NULLcheck for the input to strict trans functions, and after that thecheck was simply hardcoded for the right offset in fcinfo, as it'sdone by code specific to combine functions.Inbf6c614 (11) the strictness check was generalized, with commoncode doing the strictness checks for both plain and combine transitionfunctions, based on numTransInputs. For combine functions this lead tonot emitting an expression step to check for strict input in the 0arguments case, and in the > 1 arguments case, we'd check too manyarguments.Due to the fact that the relevant fcinfo->isnull[2..] wasalways zero-initialized (more or less by accident, by being part ofthe AggStatePerTrans struct, which is palloc0'ed), there was noobservable damage in the latter case beforea9c35cf, we justchecked too many array elements.Due to the changes ina9c35cf, > 1 argument bug became visible,because these days fcinfo is a) dynamically allocated without beingzeroed b) exactly the length required for the number of specifiedarguments (hardcoded to 2 in this case).This commit only contains a fairly minimal fix, setting numTransInputsto a hardcoded 1 when building a pertrans for a combine function. Itseems likely that we'll want to clean this up further (e.g. thearguments build_pertrans_for_aggref() aren't particularly meaningfulfor combine functions). But the wrap date for 12 beta1 is coming upfast, so it seems good to have a minimal fix in place.Backpatch to 11. While AggStatePerTrans->numTransInputs was setwrongly before that, the value was not used for combine functions.Reported-By: Rajkumar RaghuwanshiDiagnosed-By: Kyotaro Horiguchi, Jeevan Chalke, Andres Freund, David RowleyAuthor: David Rowley, Kyotaro Horiguchi, Andres FreundDiscussion:https://postgr.es/m/CAKcux6=uZEyWyLw0N7HtR9OBc-sWEFeByEZC7t-KDf15FKxVew@mail.gmail.com1 parent03310db commit2657283
File tree
3 files changed
+43
-23
lines changed- src
- backend/executor
- test/regress
- expected
- sql
3 files changed
+43
-23
lines changedLines changed: 24 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2911 | 2911 |
| |
2912 | 2912 |
| |
2913 | 2913 |
| |
2914 |
| - | |
2915 |
| - | |
2916 |
| - | |
2917 |
| - | |
2918 |
| - | |
2919 |
| - | |
2920 | 2914 |
| |
2921 | 2915 |
| |
2922 | 2916 |
| |
| |||
2926 | 2920 |
| |
2927 | 2921 |
| |
2928 | 2922 |
| |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
2929 | 2934 |
| |
2930 | 2935 |
| |
2931 | 2936 |
| |
| |||
2938 | 2943 |
| |
2939 | 2944 |
| |
2940 | 2945 |
| |
2941 |
| - | |
| 2946 | + | |
2942 | 2947 |
| |
2943 | 2948 |
| |
2944 | 2949 |
| |
| |||
2956 | 2961 |
| |
2957 | 2962 |
| |
2958 | 2963 |
| |
2959 |
| - | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
2960 | 2974 |
| |
2961 | 2975 |
| |
2962 | 2976 |
| |
| |||
2976 | 2990 |
| |
2977 | 2991 |
| |
2978 | 2992 |
| |
2979 |
| - | |
| 2993 | + | |
2980 | 2994 |
| |
2981 | 2995 |
| |
2982 |
| - | |
| 2996 | + | |
2983 | 2997 |
| |
2984 | 2998 |
| |
2985 | 2999 |
| |
|
Lines changed: 15 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2204 | 2204 |
| |
2205 | 2205 |
| |
2206 | 2206 |
| |
2207 |
| - | |
2208 |
| - | |
2209 |
| - | |
2210 |
| - | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
2211 | 2212 |
| |
| 2213 | + | |
2212 | 2214 |
| |
| 2215 | + | |
2213 | 2216 |
| |
2214 | 2217 |
| |
2215 |
| - | |
2216 |
| - | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
2217 | 2222 |
| |
2218 |
| - | |
2219 |
| - | |
2220 |
| - | |
2221 |
| - | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
2222 | 2227 |
| |
2223 | 2228 |
| |
2224 | 2229 |
| |
|
Lines changed: 4 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
963 | 963 |
| |
964 | 964 |
| |
965 | 965 |
| |
966 |
| - | |
967 |
| - | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
968 | 969 |
| |
969 |
| - | |
| 970 | + | |
970 | 971 |
| |
971 | 972 |
| |
972 | 973 |
| |
|
0 commit comments
Comments
(0)