pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Евгений Плискин <eugene.pliskin@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Suggest using boolean index with (bflag is true) condition for the query with (bflag = true) clause
Date: Mon, 19 Sep 2022 13:50:47 +0200
Message-ID: <dcceae342f9ee16e84acf2f215dec73d0757b6a2.camel@cybertec.at> (raw)
In-Reply-To: <519561082.20220918182435@gmail.com>
References: <519561082.20220918182435@gmail.com>

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





view thread (3+ messages)  latest in thread

Message-ID: <dcceae342f9ee16e84acf2f215dec73d0757b6a2.camel@cybertec.at>
Permalink:  ../dcceae342f9ee16e84acf2f215dec73d0757b6a2.camel@cybertec.at/
Also on:    postgresql.org/message-id/dcceae342f9ee16e84acf2f215dec73d0757b6a2.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, eugene.pliskin@gmail.com
  Subject: Re: Suggest using boolean index with (bflag is true) condition for the query with (bflag = true) clause
  In-Reply-To: <dcceae342f9ee16e84acf2f215dec73d0757b6a2.camel@cybertec.at>
  References: <519561082.20220918182435@gmail.com> <dcceae342f9ee16e84acf2f215dec73d0757b6a2.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox