Skip to content

Commit cbba55d

Browse files
committed
Support min/max index optimizations on boolean columns.
Since bool_and() is equivalent to min(), and bool_or() to max(), we might as well let them be index-optimized in the same way. The practical value of this is debatable at best, but it seems nearly cost-free to enable it. Code-wise, we need only adjust the entries in pg_aggregate. There is a measurable planning speed penalty for a query involving one of these aggregates, but it is only a few percent in simple cases, so that seems acceptable. Marti Raudsepp, reviewed by Abhijit Menon-Sen
1 parent 3db6524 commit cbba55d

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201202082
56+
#define CATALOG_VERSION_NO 201202083
5757

5858
#endif

src/include/catalog/pg_aggregate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ DATA(insert ( 2828 float8_regr_accum float8_covar_samp 0 1022 "{0,0,0,0,0,0}" )
205205
DATA(insert ( 2829 float8_regr_accum float8_corr 0 1022 "{0,0,0,0,0,0}" ));
206206

207207
/* boolean-and and boolean-or */
208-
DATA(insert ( 2517 booland_statefunc - 0 16 _null_ ));
209-
DATA(insert ( 2518 boolor_statefunc - 0 16 _null_ ));
210-
DATA(insert ( 2519 booland_statefunc - 0 16 _null_ ));
208+
DATA(insert ( 2517 booland_statefunc - 58 16 _null_ ));
209+
DATA(insert ( 2518 boolor_statefunc - 59 16 _null_ ));
210+
DATA(insert ( 2519 booland_statefunc - 58 16 _null_ ));
211211

212212
/* bitwise integer */
213213
DATA(insert ( 2236 int2and - 0 21 _null_ ));

src/test/regress/expected/opr_sanity.out

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -774,16 +774,19 @@ WHERE a.aggfnoid = p.oid AND
774774
(0 rows)
775775

776776
-- Cross-check aggsortop (if present) against pg_operator.
777-
-- We expect to find only "<" for "min" and ">" for "max".
777+
-- We expect to find entries for bool_and, bool_or, every, max, and min.
778778
SELECT DISTINCT proname, oprname
779779
FROM pg_operator AS o, pg_aggregate AS a, pg_proc AS p
780780
WHERE a.aggfnoid = p.oid AND a.aggsortop = o.oid
781-
ORDER BY 1;
782-
proname | oprname
783-
---------+---------
784-
max | >
785-
min | <
786-
(2 rows)
781+
ORDER BY 1, 2;
782+
proname | oprname
783+
----------+---------
784+
bool_and | <
785+
bool_or | >
786+
every | <
787+
max | >
788+
min | <
789+
(5 rows)
787790

788791
-- Check datatypes match
789792
SELECT a.aggfnoid::oid, o.oid
@@ -816,11 +819,14 @@ WHERE a.aggfnoid = p.oid AND a.aggsortop = o.oid AND
816819
amopopr = o.oid AND
817820
amopmethod = (SELECT oid FROM pg_am WHERE amname = 'btree')
818821
ORDER BY 1, 2;
819-
proname | oprname | amopstrategy
820-
---------+---------+--------------
821-
max | > | 5
822-
min | < | 1
823-
(2 rows)
822+
proname | oprname | amopstrategy
823+
----------+---------+--------------
824+
bool_and | < | 1
825+
bool_or | > | 5
826+
every | < | 1
827+
max | > | 5
828+
min | < | 1
829+
(5 rows)
824830

825831
-- Check that there are not aggregates with the same name and different
826832
-- numbers of arguments. While not technically wrong, we have a project policy

src/test/regress/sql/opr_sanity.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,12 @@ WHERE a.aggfnoid = p.oid AND
626626
NOT binary_coercible(p.proargtypes[0], a.aggtranstype);
627627

628628
-- Cross-check aggsortop (if present) against pg_operator.
629-
-- We expect to find only "<" for "min" and ">" for "max".
629+
-- We expect to find entries for bool_and, bool_or, every, max, and min.
630630

631631
SELECT DISTINCT proname, oprname
632632
FROM pg_operator AS o, pg_aggregate AS a, pg_proc AS p
633633
WHERE a.aggfnoid = p.oid AND a.aggsortop = o.oid
634-
ORDER BY 1;
634+
ORDER BY 1, 2;
635635

636636
-- Check datatypes match
637637

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