Skip to content

Commit fd59b29

Browse files
committed
Fix STRICT check for strict aggregates with NULL ORDER BY columns.
I (Andres) broke this unintentionally in 69c3936, by checking strictness for all input expressions computed for an aggregate, rather than just the input for the aggregate transition function. Reported-By: Ondřej Bouda Bisected-By: Tom Lane Diagnosed-By: Andrew Gierth Discussion: https://postgr.es/m/2a505161-2727-2473-7c46-591ed108ac52@email.cz Backpatch: 11-, like 69c3936
1 parent bf4a956 commit fd59b29

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/backend/executor/execExpr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3028,7 +3028,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
30283028
scratch.opcode = EEOP_AGG_STRICT_INPUT_CHECK;
30293029
scratch.d.agg_strict_input_check.nulls = strictnulls;
30303030
scratch.d.agg_strict_input_check.jumpnull = -1; /* adjust later */
3031-
scratch.d.agg_strict_input_check.nargs = numInputs;
3031+
scratch.d.agg_strict_input_check.nargs = pertrans->numTransInputs;
30323032
ExprEvalPushStep(state, &scratch);
30333033
adjust_bailout = lappend_int(adjust_bailout,
30343034
state->steps_len - 1);

src/test/regress/expected/aggregates.out

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,3 +2101,18 @@ SELECT dense_rank(x) WITHIN GROUP (ORDER BY x) FROM (VALUES (1),(1),(2),(2),(3),
21012101
1
21022102
(3 rows)
21032103

2104+
-- Ensure that the STRICT checks for aggregates does not take NULLness
2105+
-- of ORDER BY columns into account. See bug report around
2106+
-- 2a505161-2727-2473-7c46-591ed108ac52@email.cz
2107+
SELECT min(x ORDER BY y) FROM (VALUES(1, NULL)) AS d(x,y);
2108+
min
2109+
-----
2110+
1
2111+
(1 row)
2112+
2113+
SELECT min(x ORDER BY y) FROM (VALUES(1, 2)) AS d(x,y);
2114+
min
2115+
-----
2116+
1
2117+
(1 row)
2118+

src/test/regress/sql/aggregates.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,3 +928,10 @@ ROLLBACK;
928928

929929
-- test coverage for dense_rank
930930
SELECT dense_rank(x) WITHIN GROUP (ORDER BY x) FROM (VALUES (1),(1),(2),(2),(3),(3)) v(x) GROUP BY (x) ORDER BY 1;
931+
932+
933+
-- Ensure that the STRICT checks for aggregates does not take NULLness
934+
-- of ORDER BY columns into account. See bug report around
935+
-- 2a505161-2727-2473-7c46-591ed108ac52@email.cz
936+
SELECT min(x ORDER BY y) FROM (VALUES(1, NULL)) AS d(x,y);
937+
SELECT min(x ORDER BY y) FROM (VALUES(1, 2)) AS d(x,y);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy