| From: | Jacob Brazeal <jacob(dot)brazeal(at)gmail(dot)com> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Self-join elimination drops an equality qual |
| Date: | 2026-07-26 00:10:30 |
| Message-ID: | CA+COZaDJZC_c=oNv2mufNmEt-oEEPWrjRCwo07_CRmYaSDWRVQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Great! We can close this discussion then, I think. Thank you for looking
and for your work on the other thread.
On Sat, Jul 25, 2026 at 3:51 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Jacob Brazeal <jacob(dot)brazeal(at)gmail(dot)com> writes:
> > Self-join elimination can drop an equality qual in a three-way self-join,
> > producing wrong results.
> > ...
> > The two qualifications t1.a = t2.b and t3.c = t2.b form an
> EquivalenceClass
> > containing a, b, and c. It appears that, after the self-joined relations
> > are collapsed, two distinct single-relation equality clauses sharing the
> > same parent EquivalenceClass are incorrectly treated as redundant.
>
> I think this is the same as, or closely related to, bug #19560.
> The patchset I posted at [1] seems to have the desired behavior:
>
> regression=# explain SELECT t3.id, t3.a, t3.b, t3.c
> FROM t t1
> JOIN t t2 ON t2.id = t1.id
> JOIN t t3 ON t3.id = t2.id
> WHERE t1.a = t2.b
> AND t3.c = t2.b
> ORDER BY t3.id;
> QUERY PLAN
> ------------------------------------------------------------
> Sort (cost=37.76..37.77 rows=1 width=16)
> Sort Key: t3.id
> -> Seq Scan on t t3 (cost=0.00..37.75 rows=1 width=16)
> Filter: ((a = b) AND (b = c))
> (4 rows)
>
> regression=# SELECT t3.id, t3.a, t3.b, t3.c
> FROM t t1
> JOIN t t2 ON t2.id = t1.id
> JOIN t t3 ON t3.id = t2.id
> WHERE t1.a = t2.b
> AND t3.c = t2.b
> ORDER BY t3.id;
> id | a | b | c
> ----+---+---+---
> 1 | 1 | 1 | 1
> 2 | 2 | 2 | 2
> (2 rows)
>
>
> regards, tom lane
>
> [1]
> https://www.postgresql.org/message-id/2727652.1784997994%40sss.pgh.pa.us
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2026-07-26 00:19:03 | Re: [PATCH v1] Fix propagation of indimmediate flag in index_create_copy |
| Previous Message | Michael Paquier | 2026-07-25 23:36:42 | Re: NULL pointer dereference in syslogger with load_libraries() and -DEXEC_BACKEND at startup |