Re: Non-trivial condition is only propagated to one side of JOIN - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: Non-trivial condition is only propagated to one side of JOIN
Date
Msg-id CAKFQuwZ3jMCfy=cMS5BrzVR7M-ZN2N_2Ocgh+6Rj89f6=an-ZA@mail.gmail.com
Whole thread Raw
In response to Non-trivial condition is only propagated to one side of JOIN  (Tobias Hoffmann <ldev-list@thax.hardliners.org>)
Responses Re: Non-trivial condition is only propagated to one side of JOIN
Re: Non-trivial condition is only propagated to one side of JOIN
List pgsql-hackers
On Sunday, August 25, 2024, Tobias Hoffmann <ldev-list@thax.hardliners.org> wrote:

3) Problematic example:

# EXPLAIN SELECT * FROM tbl1 JOIN tbl2 ON tbl2.site_id = tbl1.site_id WHERE tbl1.site_id = 1 OR tbl1.site_id IS NULL; 

The “is null” predicate in this query is doing nothing as your next comment alludes to; you will produce no rows out of the join with a null site_id due to the use of the equals operator in the join.
 
    
Also, `ON tbl1.site_id IS NOT DISTINCT FROM tbl2.site_id` does not help,

Others may correct me but I’m guessing that indeed the optimizer has a gap here that could be filled in, it’s just it feels like adding code to deal with broken queries so isn’t overly motivated to work on. Joining using distinct instead of equality is uncommon, since nearly all models join primary keys to foreign keys and both of those are almost always non-null.

David J.

pgsql-hackers by date:

Previous
From: Tobias Hoffmann
Date:
Subject: Non-trivial condition is only propagated to one side of JOIN
Next
From: Alena Rybakina
Date:
Subject: Re: Vacuum statistics