pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: [Quipsy] Markus Karg <karg@quipsy.de>
To: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: WHERE column = X AND column = Y will always be zero matching rows
Date: Thu, 03 Aug 2023 16:53:13 +0200
Message-ID: <3753bdabfae96325e8f5a8ba27afd1bf96912dd1.camel@cybertec.at> (raw)
In-Reply-To: <1e15568107854a75ae8dd35a5a75daa7@quipsy.de>
References: <1e15568107854a75ae8dd35a5a75daa7@quipsy.de>

On Thu, 2023-08-03 at 14:20 +0000, [Quipsy] Markus Karg wrote:
> I am using PostgreSQL 15.3 (Debian 15.3-1.pgdg120+1) on aarch64-unknown-linux-gnu,
> compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit.
>  
> (In the following X and Y are literals; X <> Y)
>  
> I noticed is that…
>  
> EXPLAIN SELECT column FROM Table WHERE column = X AND column = Y
>  
> …says that PostgreSQL actually wants to perform a Scan!

This is not a bug.

> I wonder why squandering any resources into a Scan here, as it is pretty obvious that the
> result is guaranteed to be always, under any conditions, and will always be: zero matching
> rows – at least in a universe where a single value cannot be X AND Y at the same time.

Such an optimization, while certainly possible, would not be free, and each
query with more than one WHERE condition would have to pay the price.
On the other hand, only ill-written queries would benefit.

Since PostgreSQL only caches execution plans in special cases, anything that
slows down the optimizer should improve enough statements that it is a net win.
I don't see that here (but that is of course a matter of opinion).

Yours,
Laurenz Albe





view thread (6+ messages)  latest in thread

Message-ID: <3753bdabfae96325e8f5a8ba27afd1bf96912dd1.camel@cybertec.at>
Permalink:  ../3753bdabfae96325e8f5a8ba27afd1bf96912dd1.camel@cybertec.at/
Also on:    postgresql.org/message-id/3753bdabfae96325e8f5a8ba27afd1bf96912dd1.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-bugs@postgresql.org
  Cc: laurenz.albe@cybertec.at, karg@quipsy.de
  Subject: Re: WHERE column = X AND column = Y will always be zero matching rows
  In-Reply-To: <3753bdabfae96325e8f5a8ba27afd1bf96912dd1.camel@cybertec.at>
  References: <1e15568107854a75ae8dd35a5a75daa7@quipsy.de> <3753bdabfae96325e8f5a8ba27afd1bf96912dd1.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