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 1pU7d1-0000K6-23 for pgsql-general@arkaria.postgresql.org; Mon, 20 Feb 2023 14:58:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pU7cz-0007lM-JV for pgsql-general@arkaria.postgresql.org; Mon, 20 Feb 2023 14:58:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pU7cz-0007lD-8u for pgsql-general@lists.postgresql.org; Mon, 20 Feb 2023 14:58:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pU7cx-0006jD-2X for pgsql-general@lists.postgresql.org; Mon, 20 Feb 2023 14:58:52 +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 31KEwnWP3565867; Mon, 20 Feb 2023 09:58:49 -0500 From: Tom Lane To: David Rowley cc: Kirk Wolak , pgsql-general Subject: Re: A performance issue in ROW_NUMBER() OVER(ORDER BY NULL) [27 times slow than OVER()] V14.5 In-reply-to: References: <3330162.1676841487@sss.pgh.pa.us> <3452823.1676852265@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Mon, 20 Feb 2023 22:09:26 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3565865.1676905129.1@sss.pgh.pa.us> Date: Mon, 20 Feb 2023 09:58:49 -0500 Message-ID: <3565866.1676905129@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > On Mon, 20 Feb 2023 at 13:17, Tom Lane wrote: >> We could teach createplan.c to generate a WindowAgg plan node >> that omits the useless column from ordNumCols/ordColIdx/etc, but I'm not >> sure if that'd save much in itself. > I wonder what the comment had in mind when it said it doesn't seem > worth it. Doing an if (IsA(tle->expr, Const)) continue; seems pretty > simple and low-cost. The right way to do this would be to pass forward information about which window sort columns had been deemed redundant during make_pathkeys_for_sortclauses: there are a lot more ways for that to happen than "it's a constant". The recent addition of make_pathkeys_for_sortclauses_extended would make it pretty easy for make_pathkeys_for_window to obtain a reduced list of SortGroupClauses, and then in theory you could match that against the original lists to identify which sort columns are redundant (though repeated keys might make that tricky; might be better to provide another more-direct output representation). Pass the information forward in WindowAggPath, et voila. I remain doubtful that it's worth the trouble though. > I've not looked at what the comment mentions > about RANGE OFFSET. Assuming we'd need to not remove any ORDER BY > clauses when the WindowClause is doing that. There's some Asserts in nodeWindowAgg.c about ordNumCols being positive, probably related. regards, tom lane