Re: Eager aggregation, take 3
jian he <jian.universality@gmail.com>
/*
* 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.
Commits
-
Fix eager aggregation for semi/antijoin inner rels
- ffeda04259bb 19 (unreleased) landed
-
Cover additional errors and corner conditions in repack.c
- 2670cc298f42 19 (unreleased) cited
-
Fix volatile function evaluation in eager aggregation
- 3a08a2a8b4fd 19 (unreleased) landed
-
Fix collation handling for grouping keys in eager aggregation
- bd94845e8c90 19 (unreleased) landed
-
Rename apply_at to apply_agg_at for clarity
- 1206df04c200 19 (unreleased) landed
-
Fix comment in eager_aggregate.sql
- 36fd8bde1b77 19 (unreleased) landed
-
Remove unnecessary include of "utils/fmgroids.h"
- f997d777adf7 19 (unreleased) landed
-
Implement Eager Aggregation
- 8e11859102f9 19 (unreleased) landed
-
Allow negative aggtransspace to indicate unbounded state size
- 185e30426334 19 (unreleased) landed
-
Add macros for looping through a List without a ListCell.
- 14dd0f27d7cd 17.0 cited
-
Account for the effect of lossy pages when costing bitmap scans.
- 5edc63bda68a 11.0 cited
-
Fix a thinko in join_is_legal: when we decide we can implement a semijoin
- a43b190e3c71 9.0.0 cited