/* * Eager aggregation is only possible if equality of grouping keys, as * defined by the equality operator, implies bitwise equality. * Otherwise, if we put keys with different byte images into the same * group, we may lose some information that could be needed to * evaluate upper qual clauses. * * For example, the NUMERIC data type is not supported because values * that fall into the same group according to the equality operator * (e.g. 0 and 0.0) can have different scale. */ tce = lookup_type_cache(exprType((Node *) tle->expr), TYPECACHE_BTREE_OPFAMILY); if (!OidIsValid(tce->btree_opf) || !OidIsValid(tce->btree_opintype)) return; equalimageproc = get_opfamily_proc(tce->btree_opf, tce->btree_opintype, tce->btree_opintype, BTEQUALIMAGE_PROC); if (!OidIsValid(equalimageproc) || !DatumGetBool(OidFunctionCall1Coll(equalimageproc, tce->typcollation,
ObjectIdGetDatum(tce->btree_opintype)))) return; I am confused by BTEQUALIMAGE_PROC. * To facilitate B-Tree deduplication, an operator class may choose to * offer a forth amproc procedure (BTEQUALIMAGE_PROC). For full details, * see doc/src/sgml/btree.sgml. the above is comments about BTEQUALIMAGE_PROC in src/include/access/nbtree.h equalimage Optionally, a btree operator family may provide equalimage (“equality implies image equality”) support functions, registered under support function number 4. These functions allow the core code to determine when it is safe to apply the btree deduplication optimization. Currently, equalimage functions are only called when building or rebuilding an index. the above is BTEQUALIMAGE_PROC on https://www.postgresql.org/docs/current/btree.html#BTREE-SUPPORT-FUNCS integers support eager aggregate. select amproc.*, amproclefttype::regtype from pg_amproc amproc join pg_opfamily opf on amproc.amprocfamily = opf.oid where amproc.amprocnum = 4 and amproc.amproclefttype = amproc.amprocrighttype and opf.opfmethod = 403 and amproc.amprocrighttype = 'int'::regtype; returns oid | amprocfamily | amproclefttype | amprocrighttype | amprocnum | amproc | amproclefttype -------+--------------+----------------+-----------------+-----------+--------------+---------------- 10052 | 1976 | 23 | 23 | 4 | btequalimage | integer but btequalimage returns true unconditionally. So overall I doubt here BTEQUALIMAGE_PROC flag usage is correct.