Re: Wrong query results caused by loss of join quals - Mailing list pgsql-hackers

From Richard Guo
Subject Re: Wrong query results caused by loss of join quals
Date
Msg-id CAMbWs49dONbxqs8Yz8JOD45+76pUk0QhCG1pGvD5+RM2aRrBfg@mail.gmail.com
Whole thread Raw
In response to Re: Wrong query results caused by loss of join quals  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Wrong query results caused by loss of join quals
List pgsql-hackers

On Thu, Feb 23, 2023 at 4:50 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
I thought about this and decided that it's not really a problem.
have_relevant_joinclause is just a heuristic, and I don't think we
need to prioritize forming a join if the only relevant clauses look
like this.  We won't be able to use such clauses for merge or hash,
so we're going to end up with an unconstrained nestloop, which isn't
something to be eager to form.  The join ordering rules will take
care of forcing us to make the join when necessary.

Agreed.  And as I tried, in lots of cases joins with such clauses would
be accepted by have_join_order_restriction(), which always appears with
have_relevant_joinclause().
 
The only easy improvement I can see to make here is to apply the old
rules at inner joins.  Maybe it's worth complicating the data structures
to be smarter at outer joins, but I rather doubt it: we could easily
expend more overhead than we'll save here by examining irrelevant ECs.
In any case, if there is a useful optimization here, it can be pursued
later.

This makes sense.
 
I changed it anyway after noting that (a) passing in the ojrelid is
needful to be able to distinguish inner and outer joins, and
(b) the existing comment about the join_relids input is now wrong.
Even if it happens to not be borked for current callers, that seems
like a mighty fragile assumption.

Agreed. This is reasonable.
 
Less-hasty v2 patch attached.
 
I think the patch is in good shape now.

Thanks
Richard

pgsql-hackers by date:

Previous
From: "shiy.fnst@fujitsu.com"
Date:
Subject: RE: Allow logical replication to copy tables in binary format
Next
From: John Naylor
Date:
Subject: Re: [PoC] Improve dead tuple storage for lazy vacuum