BUG #18904: INTERSECT with an impossible where should eliminate both from the query plan - Mailing list pgsql-bugs

From David G. Johnston
Subject BUG #18904: INTERSECT with an impossible where should eliminate both from the query plan
Date
Msg-id CAKFQuwYDxYLNEODZhBL=7iR-7gGfrcFCz=AUBaw2=WEYrjMbhA@mail.gmail.com
Whole thread Raw
In response to BUG #18904: INTERSECT with an impossible where should eliminate both from the query plan  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #18904: INTERSECT with an impossible where should eliminate both from the query plan
List pgsql-bugs
On Sunday, April 27, 2025, PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:      18904
Logged by:          jinhui lai
Email address:      jh.lai@qq.com
PostgreSQL version: 17.4
Operating system:   ubuntu
Description:       

Dear Postgres Developer,
If you have a query of the form:
Q1 INTERSECT Q2 ... INTERSECT Qn,
In such cases,  you know that query Qn always returns an empty set(e.g., a
query with WHERE 1=2), then the entire intersection will always be empty.
I think that such queries should be eliminated during optimization, as they
will always return an empty set and should never consume execution time.

These failure to optimize requests are not bugs and are better discussed on the -general list where some sense of demand can be ascertained.

There is little desire to evaluate where clause expressions in the manner you propose, and while executing the subcomponents in most-restrictive to least-restrictive would be nice - stopping should any of them return no rows - it’s seems like quite a niche situation to spend time on.

David J.

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #18906: EXCEPT with identical left/right queries isn't eliminated
Next
From: "David G. Johnston"
Date:
Subject: Re: BUG #18905: The opposite WHERE clause intersects and is always an empty set. It should perform no action.