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 1pTr4Y-0007aX-EN for pgsql-general@arkaria.postgresql.org; Sun, 19 Feb 2023 21:18:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pTr4W-0003v1-JQ for pgsql-general@arkaria.postgresql.org; Sun, 19 Feb 2023 21:18:12 +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 1pTr4W-0003ur-8T for pgsql-general@lists.postgresql.org; Sun, 19 Feb 2023 21:18:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pTr4T-0002hf-No for pgsql-general@lists.postgresql.org; Sun, 19 Feb 2023 21:18:11 +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 31JLI7Z63330163; Sun, 19 Feb 2023 16:18:07 -0500 From: Tom Lane To: Kirk Wolak cc: 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: Comments: In-reply-to Kirk Wolak message dated "Sun, 19 Feb 2023 14:43:16 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3330161.1676841487.1@sss.pgh.pa.us> Date: Sun, 19 Feb 2023 16:18:07 -0500 Message-ID: <3330162.1676841487@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Kirk Wolak writes: > I have some converted code that uses this syntax. Seems kinda dumb, but ... > The solution is to remove the ORDER BY NULL. [since that is not > sortable, should it be ignored?] > This does NOT SHOW UP with 1 million rows. I don't see it at all. Comparing your two test queries on released branches, I see maybe 2x penalty for the ORDER BY NULL, not 30x. (In HEAD there's only about 13% penalty.) I wonder what PG version you are testing. regards, tom lane