Fix collation handling for grouping keys in eager aggregation
Richard Guo <rguo@postgresql.org>
Fix collation handling for grouping keys in eager aggregation When determining if it is safe to use an expression as a grouping key for partial aggregation, eager aggregation relies on the B-tree equalimage support function to ensure that equality implies image equality. Previously, the code incorrectly passed the default collation of the expression's data type to the equalimage procedure, rather than the expression's actual collation. As a result, if a column used a non-deterministic collation but the base type's default collation was deterministic, eager aggregation would incorrectly assume that the column was safe for byte-level grouping. This could cause rows to be prematurely grouped and subsequently discarded by strict join conditions, resulting in incorrect query results. This patch fixes the issue by passing the expression's actual collation to the equalimage procedure. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com> Discussion: https://postgr.es/m/CAMbWs48A53PY1Y4zoj7YhxPww9fO1hfnbdntKfA855zpXfVFRA@mail.gmail.com
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/optimizer/plan/initsplan.c | modified | +9 −1 |
| src/backend/optimizer/util/relnode.c | modified | +9 −1 |
| src/test/regress/expected/collate.icu.utf8.out | modified | +80 −18 |
| src/test/regress/sql/collate.icu.utf8.sql | modified | +45 −0 |
Discussion
- Eager aggregation, take 3 134 messages · 2024-03-04 → 2026-06-03