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 1pTtsP-0007ra-Eu for pgsql-general@arkaria.postgresql.org; Mon, 20 Feb 2023 00:17:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pTtsM-0004eD-Jk for pgsql-general@arkaria.postgresql.org; Mon, 20 Feb 2023 00:17:50 +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 1pTtsM-0004e4-0g for pgsql-general@lists.postgresql.org; Mon, 20 Feb 2023 00:17:50 +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 1pTtsJ-0007MK-Cq for pgsql-general@lists.postgresql.org; Mon, 20 Feb 2023 00:17:48 +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 31K0Hjw13452824; Sun, 19 Feb 2023 19:17:45 -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> Comments: In-reply-to David Rowley message dated "Mon, 20 Feb 2023 12:26:17 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3452822.1676852265.1@sss.pgh.pa.us> Date: Sun, 19 Feb 2023 19:17:45 -0500 Message-ID: <3452823.1676852265@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > I suspect ed1a88dda would be what made this faster in master. We'll > check for peer rows to check "NULL IS NOT DISTINCT FROM NULL" prior to > that change with the ORDER BY NULL query. Mmm, yeah, probably so: "order by null rows between unbounded preceding and current row" has about the same performance in v15 as HEAD has with just "order by null". I suspect most of the remaining performance discrepancy is just triggered by having to pass the extra always-NULL column forward through the various plan steps. 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. (The comment in create_windowagg_plan shows we already thought about that and decided it wasn't worth the trouble.) Getting rid of the useless targetlist column altogether would be way more invasive, and I'm not inclined to try. regards, tom lane