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.94.2) (envelope-from ) id 1trKRL-002CT1-Q2 for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Mar 2025 17:27:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1trKRK-00Apto-3H for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Mar 2025 17:27:50 +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.94.2) (envelope-from ) id 1trKRJ-00Aptg-RJ for pgsql-bugs@lists.postgresql.org; Sun, 09 Mar 2025 17:27:49 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1trKRG-001suk-1I for pgsql-bugs@lists.postgresql.org; Sun, 09 Mar 2025 17:27:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 529HRjvK398523; Sun, 9 Mar 2025 13:27:45 -0400 From: Tom Lane To: "David G. Johnston" cc: Christopher Inokuchi , Greg Sabino Mullane , pgsql-bugs@lists.postgresql.org Subject: Re: Window Functions with identical PARTITION BY and ORDER BY clauses evaluated separately In-reply-to: References: <1147307.1741392351@sss.pgh.pa.us> <29119.1741463452@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Sat, 08 Mar 2025 18:07:26 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <398521.1741541265.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Sun, 09 Mar 2025 13:27:45 -0400 Message-ID: <398522.1741541265@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Sat, Mar 8, 2025 at 12:50 PM Tom Lane wrote: >> For a shorter fix >> When multiple window functions are used, all the window functions >> having syntactically equivalent PARTITION BY and ORDER BY clauses >> in their window definitions are guaranteed to see the same >> ordering of the input rows, even if the ORDER BY does not uniquely >> determine the ordering. > WFM, the key point is removing the problematic wording and I do find this > reads better in the end. > However, I'm having trouble understanding the purpose of the word > "syntactically" here. Or even using the "clauses" at all. Why not: > "When multiple window functions are used, all the window functions having > the same partitioning and ordering expressions in their window definitions > are guaranteed to see the same ordering of the input rows, even if > the ordering is not deterministic." Sure, we can lose "syntactically" --- it's probably not even strictly correct anyway, given that what we really look for is equal() parsed expression trees. By the same token though, I don't love "same" here, because what is "same"? In particular, in your phrasing it's not clear whether "PARTITION BY foo" and "ORDER BY foo" are considered equivalent for this purpose. So let's go with my wording less the "syntactically". regards, tom lane