Re: Eager aggregation, take 3

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Tender Wang <tndrwang(at)gmail(dot)com>, Paul George <p(dot)a(dot)george19(at)gmail(dot)com>, Andy Fan <zhihuifan1213(at)163(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Eager aggregation, take 3
Date: 2024-10-18 13:22:00
Message-ID: CACJufxEc2BHzQzzUg_Vto9eLQ5fK9o1Ht00iSuVugn870wKM7g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

/*
* 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.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Laurenz Albe 2024-10-18 13:24:29 Re: Wrong security context for deferred triggers?
Previous Message Alvaro Herrera 2024-10-18 13:20:00 Re: Use more CppAsString2() in pg_amcheck.c