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 1we0iI-004Uf3-2U for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Jun 2026 01:23:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1we0iG-0006fA-1Z for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Jun 2026 01:23:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1we0iG-0006et-0m for pgsql-bugs@lists.postgresql.org; Mon, 29 Jun 2026 01:23:04 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1we0iE-00000000gSd-11pH for pgsql-bugs@lists.postgresql.org; Mon, 29 Jun 2026 01:23:03 +0000 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-697edb1bf6eso4077734a12.1 for ; Sun, 28 Jun 2026 18:23:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782696181; cv=none; d=google.com; s=arc-20260327; b=VHsFaPqNZuWTs0paNj5+dAbKN8mpnSJJ1qzaYByk839iAKqF+o9uRe7RQ/R5YVbhX0 qxbJW58+tScIY+9ZUTJz/sapd/SJdNQvFtPJ2KteCwNzetA0a4JdX2e/e/vN3llfjOUn HX26Yo5dtnAww5zWzgsFHWQMLefWDdf2BxymJztuU/abHZdrmGJVTI1ljl4ZEPGOGcvs j1pZ1ygotqyhQIk35nko7XzWDNwMYTqz6HVoTPMnlcTmdZjJDyWYMwBff6yBQ4SYIaz2 Nb2iJyo9bMC8KVfTtZpB3kUlA1iYQn7DNE6+D/84LqgXAdjFzKIDqW0uSya9EXIYFuix RE4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Z8ATbhYkEPxbTsrlriSoUMK9hDoK7+SpMiI1Ko5XlJ4=; fh=fs0TgDeUTxLri0lZSqWSH/qI9hj2AVriI59dwWvCq2A=; b=q6ax4vvj9tbvfn1WBmr4RHNJh0rQM0QkUmr3mUdjkhNo2RNhwx/1cnRmteOkFOG2ur bi8RVpmGcVSYpTqAoqtQskKtSRse0qwmGkHvtfBtvy8f/vxONBVSoCB05YlqMnbDSHbX Jj+dtvdzFIxqu0/Z8269pZYpzNxtNb9R9B8yKPf8gBNPkfXHfKVEZliSGTehWH6SZ6oO zYTMo56Mswn+gRzF2p+Ni13KNiqs79v9jkC3GGM5soK7oe7PDvgEt3hW3TTXCnZPelbh mO+UnbZarfuqNSmkjkcKvCJwTchxqktp3rO57Lb2dLZHxtdJrm8CVDJG4fWDsYxLy/Dt x5zA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782696181; x=1783300981; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Z8ATbhYkEPxbTsrlriSoUMK9hDoK7+SpMiI1Ko5XlJ4=; b=REolZhnx5GswZP/NYXVjz3/gVBbHuIwDuk1PEINwfJnM5/4UlHp6yYb9A+l+UWA5yu YKpsisnzYwPTVg1dtxHoXj939BbatJ22d0CKf28a3j44EBi78yPZJG5d2IakzW83yEYx GjrBZFzVADuwbzdPjgEHdXNMxZGTBYUMnCHm+hllPSSa2Ogtwe4PoMnHsiSiSXtrAH/h tuYSvHTpDzI95PwjdV6+Esiecsr5yPULmlSbdGEhLv4ZeRI46FOEe93tUKQijzRVzSWM TKVzenHtSwy5n5u4OpyEFBA2XRrVlnW67fw9JkA9TR8ipBX7KJKdYZosoz4RSM1RG0Fe YsQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782696181; x=1783300981; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Z8ATbhYkEPxbTsrlriSoUMK9hDoK7+SpMiI1Ko5XlJ4=; b=dNd6iGdPX5DY/Aj0+3G4rvRXKwWiSklf0JEVT9Es8M65k/r1O48hBOPfGFjg5VN94e mNEAOWOaO91BlwWLl6P6brn2jkF9rrRUGrwkhKxJnUN8upaX/TFBxF8tEF8tN9Viiova SWxpwIF0JNx7P+tdNC+RVkRVzEkT+wsoWu/jw7jxc2/ic/FvJUZbtB85y4UQqR/fDyPA MlnFFhjrAJzpsIYWSKz3mPZSdpnh747k6sUFujsQgt2vII+Ly/iFv9Q4qlwLOEoPPKfz ujN8BWoEFbJ5+sI2/jfs6B8JT3j8oMr6Qi7D6AMRZ108Dym2w3gsgMYIH3ZjzMWZzZdS IxWw== X-Forwarded-Encrypted: i=1; AHgh+RojcsaeMyvDpPq00Bj7yWdFRq6/eKU42IRO8fKH1lDAQH6w6EWxJ2xhi76wRbPmty1YpdwVnCfDH/g9@lists.postgresql.org X-Gm-Message-State: AOJu0YzLbFdU3HH+0vRqVG/V2zitCaBo3UycCcWD91rqyLkTd6H83HKY LXVcD63zISiiQHHKMxR5ZaFNl1N8NTT9R2eUTDZiFt//F4Ivr1CHRZZlEf/zrrgqoNQbUUjzaO/ YNH5mhJG/LFr+I+Oi8RoWhk1qyn+92zs= X-Gm-Gg: AfdE7cl2ssU5I8gjzeFr/nbLC77yusij+sig/PhryawFJw65Z8QTwo8KOLi7TIqP1B9 kB74v1HPxexYpiO9u/xtsW89LR5keb1vI1rDAPoqnbeOcsuG33g/bQ1/pMexJuDDHX7LSy2Mjfc KW1G0MYH/BwXzWe29Xxx2i3xBijHSmzHhJKRw6ReRI8niz31YD9UwOav8SGTbCM03CZwDFmMNHB mqkDe4ff5J2fQtUH36qogWptSqPcYTdkDicjacr5IOKjSJkNLjiHKDWMayJ8QZOV3F3IhXnpxKJ CgqpAPQR4eZr+/duSwIOYoUvYaUekzkAsLDDWg== X-Received: by 2002:a05:6402:1595:b0:698:48c4:361c with SMTP id 4fb4d7f45d1cf-69848c43763mr3119297a12.28.1782696180457; Sun, 28 Jun 2026 18:23:00 -0700 (PDT) MIME-Version: 1.0 References: <19534-9cdf4693c42033da@postgresql.org> <544F3673-0EC9-4440-9FC5-4BB4F0AA3037@outlook.com> In-Reply-To: <544F3673-0EC9-4440-9FC5-4BB4F0AA3037@outlook.com> From: Tender Wang Date: Mon, 29 Jun 2026 09:22:49 +0800 X-Gm-Features: AVVi8CfWjEq66IeWaIR4bJbMW1H0zE5UQl8T5lGUAMh-otzI7Xl0Vnm1wwA8zHU Message-ID: Subject: Re: BUG #19534: Qual pushdown across a window subquery is unsafe with nondeterministic partition collations To: Chengpeng Yan Cc: "imchifan@163.com" , "pgsql-bugs@lists.postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Chengpeng Yan =E4=BA=8E2026=E5=B9=B46=E6=9C=882= 8=E6=97=A5=E5=91=A8=E6=97=A5 21:43=E5=86=99=E9=81=93=EF=BC=9A > > Hi > > ``` > CREATE COLLATION case_insensitive > (provider =3D icu, locale =3D '@colStrength=3Dsecondary', > deterministic =3D false); > > CREATE TABLE t (x text COLLATE case_insensitive); > INSERT INTO t VALUES ('abc'), ('ABC'); > > SELECT x, c > FROM ( > SELECT x, count(*) OVER (PARTITION BY x) AS c > FROM t > ) s > WHERE ascii(x) =3D 97; > ``` > > Without the patch, the planner can push the `ascii(x) =3D 97` filter belo= w > `WindowAgg`, so the result is: > > ``` > x | c > -----+--- > abc | 1 > ``` > > The correct result is: > > ``` > x | c > -----+--- > abc | 2 > ``` Good catch. I didn't take this query into account. > Postgres only knows at this point that the column appears in every > window `PARTITION BY` list; it does not know that an arbitrary qual on > that column is constant over the partition equality class. The attached > v2 patch therefore takes a conservative approach: if the matching > partition key uses a nondeterministic collation, ordinary qual pushdown > is disabled for that column. > > The tradeoff is that we may miss some pushdown opportunities for quals > that really are constant over the partition. But for a wrong-result > case, that is safer than pushing a qual whose behavior over the > partition is not proven. Deterministic partition keys keep the existing > behavior. > > I ran `make check`; all tests passed. > > Any thoughts? The correct result is the most important thing. So I agree with you. The fix seems obvious: we should refuse quals pushed down to the subquery if the quals contain a nondeterministic partition clause var. --=20 Thanks, Tender Wang