BUG #18904: INTERSECT with an impossible where should eliminate both from the query plan

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "jh(dot)lai(at)qq(dot)com" <jh(dot)lai(at)qq(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: BUG #18904: INTERSECT with an impossible where should eliminate both from the query plan
Date: 2025-04-27 17:32:22
Message-ID: CAKFQuwYDxYLNEODZhBL=7iR-7gGfrcFCz=AUBaw2=WEYrjMbhA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Sunday, April 27, 2025, PG Bug reporting form <noreply(at)postgresql(dot)org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference: 18904
> Logged by: jinhui lai
> Email address: jh(dot)lai(at)qq(dot)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.

In response to

Responses

Browse pgsql-bugs by date

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