Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wdSc8-00477o-0G for pgsql-bugs@arkaria.postgresql.org; Sat, 27 Jun 2026 12:58:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wdSc7-00FLwH-06 for pgsql-bugs@arkaria.postgresql.org; Sat, 27 Jun 2026 12:58:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wcOrj-001IYT-1v for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 14:46:11 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wcOrf-000000002So-19eS for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 14:46:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=tELyIrdDfiUADI8buydNbOhkGNyufETZYEAZitvX8NU=; b=Ru3SNDaqdFRvNf4kiQlFUiPvyD RJwCFhq3w03Nmr5OdchVHJZCTZQ78CeohgZElX+IrTiXiPOlQkvxzVXNlXaK4KrdgieGqUXsWOyrA pI/TaZz0hZbEnqS2lJN4RbdYVf1NQTQNq36kCWMYyA2zmQxFg2RPcsCT03J2Bxt4voU3Y2smCucxm 8o57BVtGEVvMNq9nqAfoZmOYg5SLHc2K4NiieifKkb22je+n8YK+/f+0uUYRHtMGV7XK8KHM5nsJ6 uUhshc+MFxvPUi6CLhOqE4E6vsTbLovMWLIDBg4KgUI3VqVmmPDaq+XofopVZ2wDkUpjtzYsHpdZ8 yImo0fOA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wcOrc-005uDB-0h for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 14:46:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wcOrZ-000Ovk-2x for pgsql-bugs@lists.postgresql.org; Wed, 24 Jun 2026 14:46:02 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19534: Qual pushdown across a window subquery is unsafe with nondeterministic partition collations To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: imchifan@163.com Reply-To: imchifan@163.com, pgsql-bugs@lists.postgresql.org Date: Wed, 24 Jun 2026 14:45:18 +0000 Message-ID: <19534-9cdf4693c42033da@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19534 Logged by: Qifan Liu Email address: imchifan@163.com PostgreSQL version: 18.4 Operating system: Ubuntu 20.04 x86-64, docker image postgres:18.4 Description: =20 ## PoC ```sql DROP TABLE IF EXISTS t_window_ci; DROP COLLATION IF EXISTS case_sensitive; DROP COLLATION IF EXISTS case_insensitive; CREATE COLLATION case_sensitive (provider =3D icu, locale =3D 'und', deterministic =3D true); CREATE COLLATION case_insensitive (provider =3D icu, locale =3D 'und-u-ks-level2', deterministic =3D false); CREATE TABLE t_window_ci ( x text COLLATE case_insensitive, y int ); INSERT INTO t_window_ci VALUES ('abc', 1), ('ABC', 2), ('def', 10); -- Window query SELECT x, y, part_sum FROM ( SELECT x, y, sum(y) OVER (PARTITION BY x) AS part_sum FROM t_window_ci ) s WHERE x =3D 'abc' COLLATE case_sensitive ORDER BY x, y; -- Reference query SELECT t1.x, t1.y, ( SELECT sum(t2.y) FROM t_window_ci t2 WHERE t2.x =3D t1.x ) AS part_sum FROM t_window_ci t1 WHERE t1.x =3D 'abc' COLLATE case_sensitive ORDER BY t1.x, t1.y; EXPLAIN (COSTS OFF) SELECT x, y, part_sum FROM ( SELECT x, y, sum(y) OVER (PARTITION BY x) AS part_sum FROM t_window_ci ) s WHERE x =3D 'abc' COLLATE case_sensitive ORDER BY x, y; ``` ## Expected Behavior The window query should return the same result as the reference query. Since `'abc'` and `'ABC'` are in the same nondeterministic partition, the partition sum for row `'abc'` should be `3`. ## Actual Behavior The window query returns `abc | 1 | 1`, while the reference query returns `abc | 1 | 3`. `EXPLAIN` shows that the strict-collation filter is pushed below `WindowAgg`, which changes the partition before the window sum is computed.