summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2023-02-05 19:25:10 +0000
committerTom Lane2023-02-05 19:25:10 +0000
commitb2d0e13a0a4c31167d01e9871f907060c80b8fae (patch)
treee09a0d7f39c78b6b6b77d4bfc35f7f8926bfd6b9 /src/test
parent9f452feeeb830534dc2ce743a2a14b109128326d (diff)
Fix over-optimistic updating of info about commutable outer joins.
make_outerjoininfo was set up to update SpecialJoinInfo's commute_below, commute_above_l, commute_above_r fields as soon as it found a pair of outer joins that look like they can commute. However, this decision could be negated later in the same loop due to finding an intermediate outer join that prevents commutation. That left us with commute_xxx fields that were contradictory to the join order restrictions expressed in min_lefthand/min_righthand. The latter fields would keep us from actually choosing a bad join order; but the inconsistent commute_xxx fields could bollix details such as the varnullingrels values created for intermediate join relation targetlists, ending in an assertion failure in setrefs.c. To fix, wait till the end of make_outerjoininfo where we have accurate values for min_lefthand/min_righthand, and then insert only relids not present in those sets into the commute_xxx fields. Per SQLSmith testing by Robins Tharakan. Note that while Robins bisected the failure to commit b448f1c8d, it's really the fault of 2489d76c4. The outerjoin_delayed logic removed in the later commit was keeping us from deciding that troublesome join pairs commute, at least in the specific example seen here. Discussion: https://postgr.es/m/CAEP4nAyAORgE8K_RHSmvWbE9UaChhjbEL1RrDU3neePwwRUB=A@mail.gmail.com
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/join.out30
-rw-r--r--src/test/regress/sql/join.sql11
2 files changed, 41 insertions, 0 deletions
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 9762952efd..037c7d0d56 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -4469,6 +4469,36 @@ left join
One-Time Filter: false
(5 rows)
+-- check handling of apparently-commutable outer joins with non-commutable
+-- joins between them
+explain (costs off)
+select 1 from
+ int4_tbl i4
+ left join int8_tbl i8 on i4.f1 is not null
+ left join (select 1 as a) ss1 on null
+ join int4_tbl i42 on ss1.a is null or i8.q1 <> i8.q2
+ right join (select 2 as b) ss2
+ on ss2.b < i4.f1;
+ QUERY PLAN
+-----------------------------------------------------------
+ Nested Loop Left Join
+ -> Result
+ -> Nested Loop
+ -> Nested Loop Left Join
+ Join Filter: NULL::boolean
+ Filter: (((1) IS NULL) OR (i8.q1 <> i8.q2))
+ -> Nested Loop Left Join
+ Join Filter: (i4.f1 IS NOT NULL)
+ -> Seq Scan on int4_tbl i4
+ Filter: (2 < f1)
+ -> Materialize
+ -> Seq Scan on int8_tbl i8
+ -> Result
+ One-Time Filter: false
+ -> Materialize
+ -> Seq Scan on int4_tbl i42
+(16 rows)
+
--
-- test for appropriate join order in the presence of lateral references
--
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 3ef2996040..1f2b7f62f0 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1545,6 +1545,17 @@ left join
where c.relkind = 'r'
) ss2 on false;
+-- check handling of apparently-commutable outer joins with non-commutable
+-- joins between them
+explain (costs off)
+select 1 from
+ int4_tbl i4
+ left join int8_tbl i8 on i4.f1 is not null
+ left join (select 1 as a) ss1 on null
+ join int4_tbl i42 on ss1.a is null or i8.q1 <> i8.q2
+ right join (select 2 as b) ss2
+ on ss2.b < i4.f1;
+
--
-- test for appropriate join order in the presence of lateral references
--