summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2023-02-04 20:19:54 +0000
committerTom Lane2023-02-04 20:19:54 +0000
commit8538519db107777a6b06b7277185e6605caf8d4c (patch)
treeef0edc9e36c7de2c587fd207443bd5a62aaecb31 /src/test
parent5840c2027264d5dfad743c50874e0ebf8b840f3f (diff)
Fix thinko in outer-join removal.
If we have a RestrictInfo that mentions both the removal-candidate relation and the outer join's relid, then that is a pushed-down condition not a join condition, so it should be grounds for deciding that we can't remove the outer join. In commit 2489d76c4, I'd blindly included the OJ's relid into "joinrelids" as per the new standard convention, but the checks of attr_needed and ph_needed should only allow the join's input rels to be mentioned. Having done that, the check for references in pushed-down quals a few lines further down should be redundant. I left it in place as an Assert, though. While researching this I happened across a couple of comments that worried about the effects of update_placeholder_eval_levels. That's gone as of b448f1c8d, so we can remove some worry. Per bug #17769 from Robins Tharakan. The submitted test case triggers this more or less accidentally because we flatten out a LATERAL sub-select after we've done join strength reduction; if we did that in the other order, this problem would be masked because the outer join would get simplified to an inner join. To ensure that the committed test case will continue to test what it means to even if we make that happen someday, use a test clause involving COALESCE(), which will prevent us from using it to do join strength reduction. Patch by me, but thanks to Richard Guo for initial investigation. Discussion: https://postgr.es/m/17769-e4f7a5c9d84a80a7@postgresql.org
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/join.out15
-rw-r--r--src/test/regress/sql/join.sql7
2 files changed, 22 insertions, 0 deletions
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 8d7bd937a7..c520839bf7 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -5150,6 +5150,21 @@ SELECT * FROM
1 | 4567890123456789 | -4567890123456789 | 4567890123456789
(5 rows)
+-- join removal bug #17769: can't remove if there's a pushed-down reference
+EXPLAIN (COSTS OFF)
+SELECT q2 FROM
+ (SELECT *
+ FROM int8_tbl LEFT JOIN innertab ON q2 = id) ss
+ WHERE COALESCE(dat1, 0) = q1;
+ QUERY PLAN
+----------------------------------------------------------------
+ Nested Loop Left Join
+ Filter: (COALESCE(innertab.dat1, '0'::bigint) = int8_tbl.q1)
+ -> Seq Scan on int8_tbl
+ -> Index Scan using innertab_pkey on innertab
+ Index Cond: (id = int8_tbl.q2)
+(5 rows)
+
rollback;
-- another join removal bug: we must clean up correctly when removing a PHV
begin;
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index 9f55147be7..b0e8d559cd 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1860,6 +1860,13 @@ SELECT * FROM
FROM int8_tbl LEFT JOIN innertab ON q2 = id) ss2
ON true;
+-- join removal bug #17769: can't remove if there's a pushed-down reference
+EXPLAIN (COSTS OFF)
+SELECT q2 FROM
+ (SELECT *
+ FROM int8_tbl LEFT JOIN innertab ON q2 = id) ss
+ WHERE COALESCE(dat1, 0) = q1;
+
rollback;
-- another join removal bug: we must clean up correctly when removing a PHV