postgresql/src
Amit Langote 96f9b29a3e 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@qq.com>
Author: Webbo Han <1105066510@qq.com>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>
Reviewed-by: Jian He <jian.universality@gmail.com>
Discussion: https://postgr.es/m/18568-2a9afb6b9f7e6ed3@postgresql.org
Discussion: https://postgr.es/m/tencent_9D9103CDA420C07768349CC1DFF88465F90A@qq.com
Discussion: https://postgr.es/m/CAHewXNno_HKiQ6PqyLYfuqDtwp7KKHZiH1J7Pqyz0nr+PS2Dwg@mail.gmail.com
Backpatch-through: 12
2024-11-08 16:06:46 +09:00
..
backend Disallow partitionwise grouping when collations don't match 2024-11-08 16:06:46 +09:00
bin Replace pgwin32_is_junction() with lstat(). 2024-11-08 09:36:53 +10:30
common Replace pgwin32_is_junction() with lstat(). 2024-11-08 09:36:53 +10:30
fe_utils Don't spuriously report FD_SETSIZE exhaustion on Windows. 2023-10-14 15:54:49 -07:00
include Replace pgwin32_is_junction() with lstat(). 2024-11-08 09:36:53 +10:30
interfaces ecpg: Fix out-of-bound read in DecodeDateTime() 2024-10-23 08:35:05 +09:00
makefiles Add NO_INSTALL option to pgxs 2021-05-27 13:58:29 +02:00
pl Further refine _SPI_execute_plan's rule for atomic execution. 2024-10-16 17:36:30 -04:00
port Replace pgwin32_is_junction() with lstat(). 2024-11-08 09:36:53 +10:30
template On NetBSD, force dynamic symbol resolution at postmaster start. 2022-08-30 17:29:03 -04:00
test Disallow partitionwise grouping when collations don't match 2024-11-08 16:06:46 +09:00
timezone Update time zone data files to tzdata release 2024b. 2024-10-29 11:50:05 -04:00
tools Add missing include guard to win32ntdll.h. 2024-11-08 09:35:45 +10:30
tutorial Doc: sync src/tutorial/basics.source with SGML documentation. 2022-11-19 13:09:14 -05:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
DEVELOPERS
Makefile Remove the option to build thread_test.c outside configure. 2020-10-21 12:08:48 -04:00
Makefile.global.in Suppress macOS warnings about duplicate libraries in link commands. 2023-09-29 14:07:30 -04:00
Makefile.shlib Stop using "-multiply_defined suppress" on macOS. 2023-09-26 21:06:21 -04:00
nls-global.mk Add errhint_plural() function and make use of it 2021-03-31 09:16:25 +02:00