pgsql: Disallow partitionwise grouping when collations don't match

From: Amit Langote <amitlan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Disallow partitionwise grouping when collations don't match
Date: 2024-11-08 07:14:35
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Disallow partitionwise grouping when collations don't match

If the collation of any grouping column doesn’t match the collation of
the corresponding partition key, partitionwise grouping can yield
incorrect results. For example, rows that would be grouped under the
grouping collation may end up in different partitions under the
partitioning collation. In such cases, full partitionwise grouping
would produce results that differ from those without partitionwise
grouping, so disallowed that.

Partial partitionwise aggregation is still allowed, as the Finalize
step reconciles partition-level aggregates with grouping requirements
across all partitions, ensuring that the final output remains
consistent.

This commit also fixes group_by_has_partkey() by ensuring the
RelabelType node is stripped from grouping expressions when matching
them to partition key expressions to avoid false mismatches.

Bug: #18568
Reported-by: Webbo Han <1105066510(at)qq(dot)com>
Author: Webbo Han <1105066510(at)qq(dot)com>
Reviewed-by: Tender Wang <tndrwang(at)gmail(dot)com>
Reviewed-by: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Reviewed-by: Jian He <jian(dot)universality(at)gmail(dot)com>
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/CAHewXNno_HKiQ6PqyLYfuqDtwp7KKHZiH1J7Pqyz0nr+PS2Dwg@mail.gmail.com
Backpatch-through: 12

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/96f9b29a3e1ea3dd58e728814bf630d40ff77caa

Modified Files
--------------
src/backend/optimizer/plan/planner.c | 44 ++++++++++---
src/test/regress/expected/collate.icu.utf8.out | 90 ++++++++++++++++++++++++++
src/test/regress/sql/collate.icu.utf8.sql | 37 +++++++++++
3 files changed, 163 insertions(+), 8 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Langote 2024-11-08 07:14:49 pgsql: Disallow partitionwise grouping when collations don't match
Previous Message Amit Langote 2024-11-08 07:14:22 pgsql: Disallow partitionwise grouping when collations don't match