Re: Wrong results from self-join elimination with different restriction operators

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tender Wang <tndrwang(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Subject: Re: Wrong results from self-join elimination with different restriction operators
Date: 2026-10-15 16:45:25
Message-ID: 2439277.1792082725@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tender Wang <tndrwang(at)gmail(dot)com> writes:
> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> 于2026年10月15日周四 04:56写道:
>> If we're going to refuse that, I wonder if we couldn't simplify
>> match_unique_clauses a great deal: just insist that the two OpExpr
>> clauses be equal(), after the ChangeVarNodes substitution on the outer
>> clause. Your proposal already breaks commuted-clause cases, which
>> seem like the only justification for all the futzing around with left
>> and right operands. I doubt that detecting that is of any real-world
>> value anyway.

> Attached is v2, following your suggestion to compare the complete
> clauses with equal() after the ChangeVarNodes substitution. I also
> removed the test added in v1.

LGTM, pushed.

> I ran the regression tests and found no plan differences. This
> suggests the existing tests don't cover cases where matching commuted
> restrictions enables self-join elimination.

Yeah, that's evidence in favor of my opinion that this wasn't worth
the complexity. If somebody wanted to put that back, we could try
building a commuted clause (cf. CommuteOpExpr) and applying equal()
with that. But I really doubt it's worth the code and cycles.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Naga Appani 2026-10-15 16:53:24 Re: doc: fix pg_get_multixact_stats() num_mxids type (integer -> bigint)
Previous Message zengxx 2026-10-15 16:19:51 [PATCH 0/2] Improve ndistinct estimates for flattened UNION ALL