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
v1-0001-Wrap-variable-free-virtual-column-expansions-in-F.patch
Description: Binary data
