Re: Suggest using boolean index with (bflag is true) condition for the query with (bflag = true) clause

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Евгений Плискин <eugene(dot)pliskin(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Suggest using boolean index with (bflag is true) condition for the query with (bflag = true) clause
Date: 2022-09-19 14:33:42
Message-ID: 337633.1663598022@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bryn Llewellyn 2022-09-19 16:23:57 Re: Where's the doc for "array()" — as in "select array(values (17), (42))"
Previous Message Adrian Klaver 2022-09-19 14:29:00 Re: Where's the doc for "array()" — as in "select array(values (17), (42))"