| From: | Richard Guo <guofenglinux(at)gmail(dot)com> |
|---|---|
| To: | Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | FULL JOIN planning failure with virtual generated columns |
| Date: | 2026-12-05 08:40:33 |
| Message-ID: | CAMbWs49sJWD6_pSaS_JVjKfks6A6iSUCcAcNYoPCZ+oycasE9Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
While using Opus 5.5 to test my patch for bug #19976, it ran into
another issue with virtual generated columns:
create table t (a int, k int generated always as (1) virtual);
select * from t t1 full join t t2 on t1.k = t2.a;
ERROR: FULL JOIN is only supported with merge-joinable or
hash-joinable join conditions
The same thing happens when the generation expression only simplifies
to a constant, eg coalesce(1, a). It works fine with a stored column.
The problem is that the expansion turns the join qual into "1 = t2.a",
which references only one side of the join. Subquery pullup already
deals with this case: replace_vars_in_jointree() wraps variable-free
expressions in PHVs within FULL JOIN quals. But
expand_virtual_generated_columns() runs pullup_replace_vars() on the
whole query in one go, so it never gets that treatment.
The attached patch detaches the jointree before expanding the rest of
the query, and then expands its quals with replace_vars_in_jointree().
LATERAL RTEs have already been taken care of by then, so I added a
field to pullup_replace_vars_context to tell replace_vars_in_jointree()
to leave them alone.
I did ask Opus to write a fix at first, but I didn't like what it came
up with: it pulled the FULL JOIN quals out before the expansion and
then had to walk the jointree a second time to find the FULL JOINs
again and put the quals back. So I wrote the attached fix myself.
Any thoughts?
- Richard
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Wrap-variable-free-virtual-column-expansions-in-F.patch | application/octet-stream | 7.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Zhijie Hou | 2026-12-05 10:19:06 | Re: DROP SUBSCRIPTION deadlock with ALTER SUBSCRIPTION OWNER TO |
| Previous Message | Ivan Alekseev | 2026-12-05 07:33:25 | Re: Reduce SyncRepLock contention on the commit path |