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

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Евгений Плискин <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 11:50:47
Message-ID: dcceae342f9ee16e84acf2f215dec73d0757b6a2.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 2022-09-18 at 18:24 +0300, Евгений Плискин wrote:
> This is not a bug report but rather a suggestion.
>
> Suppose database contains an index on a boolean column like this:
>       create table1(id int, amount float, best_record boolean);
>       create index index1 on table1(best_record) where best_record is true;
>
> And suppose we issue a query like this:
>       select * from table1 where best_record = true;
>
> The planner does not try to use an index for this query because an index condition (bflag is true) does not literally match the query (bflag = true).
> But is that reasonable?
> The index does not cover records where "best_record" is FALSE or NULL.
> And similarly the query is not interested in any records where "best_record" is FALSE or NULL.
> 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.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2022-09-19 14:29:00 Re: Where's the doc for "array()" — as in "select array(values (17), (42))"
Previous Message Pavel Stehule 2022-09-19 09:12:57 Re: What ist the standard setting of FETCH_COUNT?