Skip to content

Commit ba930a0

Browse files
committed
Add an opr_sanity check for misdefined aggregates that have transition
type different from input type but are expecting ExecAgg to insert the first non-null input as the starting transition value. This has always been verboten, but wasn't checked for until now...
1 parent 8b1b34f commit ba930a0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/test/regress/expected/opr_sanity.out

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,17 @@ WHERE p1.aggfinalfn = p2.oid AND
479479
-----+---------+-----+---------
480480
(0 rows)
481481

482+
-- If transfn is strict then either initval should be non-NULL, or
483+
-- basetype should equal transtype so that the first non-null input
484+
-- can be assigned as the state value.
485+
SELECT p1.oid, p1.aggname, p2.oid, p2.proname
486+
FROM pg_aggregate AS p1, pg_proc AS p2
487+
WHERE p1.aggtransfn = p2.oid AND p2.proisstrict AND
488+
p1.agginitval IS NULL AND p1.aggbasetype != p1.aggtranstype;
489+
oid | aggname | oid | proname
490+
-----+---------+-----+---------
491+
(0 rows)
492+
482493
-- **************** pg_opclass ****************
483494
-- There should not be multiple entries in pg_opclass with the same
484495
-- nonzero opcdeftype value, because there can be only one default opclass

src/test/regress/sql/opr_sanity.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,15 @@ WHERE p1.aggfinalfn = p2.oid AND
400400
p2.pronargs != 1 OR
401401
p1.aggtranstype != p2.proargtypes[0]);
402402

403+
-- If transfn is strict then either initval should be non-NULL, or
404+
-- basetype should equal transtype so that the first non-null input
405+
-- can be assigned as the state value.
406+
407+
SELECT p1.oid, p1.aggname, p2.oid, p2.proname
408+
FROM pg_aggregate AS p1, pg_proc AS p2
409+
WHERE p1.aggtransfn = p2.oid AND p2.proisstrict AND
410+
p1.agginitval IS NULL AND p1.aggbasetype != p1.aggtranstype;
411+
403412
-- **************** pg_opclass ****************
404413

405414
-- There should not be multiple entries in pg_opclass with the same

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