WHERE column = X AND column = Y will always be zero matching rows - Mailing list pgsql-bugs

Hello PostgreSQL Developers,

 

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!

 

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.

 

This can be seen as a chance to add an optimization („col = X AND col = Y always is zero matching rows), or in case such an optimization already exists in PostgreSQL, as a bug.  

 

BTW the same happens for column IS NULL AND column = Y.

 

Regards,

-Markus

 

pgsql-bugs by date:

Previous
From: David Rowley
Date:
Subject: Re: BUG #18048: Database process terminated automatically
Next
From: Justin Tocci
Date:
Subject: Re: BUG #18047: ODBC to PG long transaction causes PANIC