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 1oaHqJ-0004WU-0Q for pgsql-general@arkaria.postgresql.org; Mon, 19 Sep 2022 14:33:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oaHqH-0001kj-JK for pgsql-general@arkaria.postgresql.org; Mon, 19 Sep 2022 14:33:49 +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 1oaHqH-0001kH-8d for pgsql-general@lists.postgresql.org; Mon, 19 Sep 2022 14:33:49 +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 1oaHqF-00065r-3w for pgsql-general@lists.postgresql.org; Mon, 19 Sep 2022 14:33: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 28JEXgsQ337634; Mon, 19 Sep 2022 10:33:44 -0400 From: Tom Lane To: Laurenz Albe cc: =?UTF-8?Q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9_?= =?UTF-8?Q?=D0=9F=D0=BB=D0=B8=D1=81=D0=BA=D0=B8=D0=BD?= , pgsql-general@lists.postgresql.org Subject: Re: Suggest using boolean index with (bflag is true) condition for the query with (bflag = true) clause In-reply-to: References: <519561082.20220918182435@gmail.com> Comments: In-reply-to Laurenz Albe message dated "Mon, 19 Sep 2022 13:50:47 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <337632.1663598022.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 19 Sep 2022 10:33:42 -0400 Message-ID: <337633.1663598022@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: > On Sun, 2022-09-18 at 18:24 +0300, Евгений Плискин wrote: >> So why not use this index for this query? > Because the conditions are different: > SELECT NULL = TRUE, NULL IS TRUE; > ?column? │ ?column? > ══════════╪══════════ > │ f > (1 row) > The first result is NULL. Nonetheless, indxpath.c knows it can transform between "bool = true" and "bool IS TRUE" for the purpose of making an index search qualification, so it seems a bit odd that we fail to do the equivalent transformation when attempting to prove an index predicate. It'd be possible to improve this by adding some proof rules to predicate_implied_by_simple_clause: I think both "x => x IS TRUE" and the converse would be valid per the proof requirements, and if you wanted to gild the lily it'd likely be possible to handle some related cases like "x => x IS NOT FALSE". Whether it's worth the cycles isn't too clear to me, but we could argue about that if somebody submitted a patch. regards, tom lane