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 1rQ7Zb-00GdY5-Op for pgsql-performance@arkaria.postgresql.org; Wed, 17 Jan 2024 15:11:24 +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 1rQ7Za-00E0Ip-VO for pgsql-performance@arkaria.postgresql.org; Wed, 17 Jan 2024 15:11:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rQ7Za-00E0Ih-Lu for pgsql-performance@lists.postgresql.org; Wed, 17 Jan 2024 15:11:22 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rQ7ZX-0020Ky-U9 for pgsql-performance@lists.postgresql.org; Wed, 17 Jan 2024 15:11:21 +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 40HFBHJ72027068; Wed, 17 Jan 2024 10:11:17 -0500 From: Tom Lane To: Jerry Brenner cc: pgsql-performance@lists.postgresql.org Subject: Re: Why is a sort required for this query? (IS NULL predicate on leading key column) In-reply-to: References: Comments: In-reply-to Jerry Brenner message dated "Wed, 17 Jan 2024 06:39:06 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2027066.1705504277.1@sss.pgh.pa.us> Date: Wed, 17 Jan 2024 10:11:17 -0500 Message-ID: <2027067.1705504277@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jerry Brenner writes: > I'm wondering why a sort is required for this query, as the index should be > providing the required ordering to satisfy the ORDER BY clause. Does it > have to do with the IS NULL predicate on the leading key column in the > index? IS NULL is not seen as an equality condition, no. It's pretty much of a hack that makes it an indexable condition at all, and we don't really do any advanced optimization with it. regards, tom lane