mirror of
https://github.com/postgres/postgres.git
synced 2026-05-16 03:19:53 -04:00
remove_useless_groupby_columns() uses a relation's unique indexes to
prove that some GROUP BY columns are functionally dependent on others,
and so can be dropped from the GROUP BY clause. The match between
index columns and GROUP BY columns was done by attno alone, ignoring
two equality-relation issues.
A type may belong to multiple btree opfamilies whose notions of
equality differ. The record type, for instance, has record_ops
(per-field equality) and record_image_ops (bytewise equality). A
unique index under one opfamily does not prove uniqueness under the
equality used by GROUP BY when the SortGroupClause's eqop comes from a
different opfamily.
Likewise, since nondeterministic collations were introduced in PG 12,
two collations may disagree on equality, and a unique index under one
collation does not prove uniqueness under another.
In either case, rows that the index considers distinct can collapse
into a single GROUP BY group, taking ungrouped columns of differing
values with them, so the planner drops a column that is not in fact
functionally dependent and produces wrong results.
Fix by requiring, for each unique-index key column, that some GROUP BY
item on the same column has an eqop in the index's opfamily and a
collation that agrees on equality with the index's collation. This
mirrors the combined check relation_has_unique_index_for() applies to
join clauses.
This is a v18 regression: commit
|
||
|---|---|---|
| .. | ||
| ci | ||
| editors | ||
| ifaddrs | ||
| perlcheck | ||
| pg_bsd_indent | ||
| pginclude | ||
| pgindent | ||
| add_commit_links.pl | ||
| ccsym | ||
| check_bison_recursion.pl | ||
| copyright.pl | ||
| darwin_sysroot | ||
| find_badmacros | ||
| find_meson | ||
| find_static | ||
| find_typedef | ||
| gen_export.pl | ||
| gen_keywordlist.pl | ||
| generate_editorconfig.py | ||
| git-external-diff | ||
| git_changelog | ||
| install_files | ||
| make_ctags | ||
| make_etags | ||
| make_mkid | ||
| mark_pgdllimport.pl | ||
| msvc_gendef.pl | ||
| PerfectHash.pm | ||
| pgflex | ||
| pgtest | ||
| rcgen | ||
| RELEASE_CHANGES | ||
| testwrap | ||
| valgrind.supp | ||
| version_stamp.pl | ||
| win32tzlist.pl | ||