Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qDmfm-0003mR-Bj for pgsql-sql@arkaria.postgresql.org; Mon, 26 Jun 2023 13:54:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qDmfl-0005PJ-7f for pgsql-sql@arkaria.postgresql.org; Mon, 26 Jun 2023 13:54:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qDmfk-0005PA-UY for pgsql-sql@lists.postgresql.org; Mon, 26 Jun 2023 13:54:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qDmfi-000axU-2C for pgsql-sql@lists.postgresql.org; Mon, 26 Jun 2023 13:54:28 +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 35QDsNaS716590; Mon, 26 Jun 2023 09:54:23 -0400 From: Tom Lane To: Romain Carl cc: pgsql-sql@lists.postgresql.org Subject: Re: Window functions: frame-adhering aggregate without ORDER BY clause In-reply-to: <4ecad084-cf68-641c-ce02-b07b0b4625c9@aol.com> References: <4ecad084-cf68-641c-ce02-b07b0b4625c9.ref@aol.com> <4ecad084-cf68-641c-ce02-b07b0b4625c9@aol.com> Comments: In-reply-to Romain Carl message dated "Mon, 26 Jun 2023 13:44:39 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <716588.1687787663.1@sss.pgh.pa.us> Date: Mon, 26 Jun 2023 09:54:23 -0400 Message-ID: <716589.1687787663@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Romain Carl writes: > among the window tests (src/test/regress/expected/window.out), I noticed > the presence of tests that rely upon the order of rows not determined by > any ORDER BY clause, such as: Yeah ... > The current row's frame and, consequently, the result of the sum > aggregate depend on the order produced by the sequential scan of table > tenk1. Since such order is, in general, not part of PG's defined > behavior, what purpose do the tests that rely upon it serve? The tests are perfectly entitled to test PG's actual behavior. I don't see much difference between this particular case and the fact that we have any tests at all that lack ORDER BY, because formally speaking the engine could choose to emit the rows in some other order. In practice, if we ever did make the engine behave differently, it'd be on us to fix affected test cases. > Following up to that, how is an EXCLUDE GROUP defined to behave in > absence of any ORDER BY clause? I see in the docs EXCLUDE GROUP excludes the current row and its ordering peers from the frame. and a bit later Without ORDER BY, ... all rows become peers of the current row. so excluding the whole frame seems like the right behavior. regards, tom lane