From 30a35bca3f9306f87ca8db095ddac2ba62156934 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 7 Jul 2021 15:21:25 -0400 Subject: Fix crash in postgres_fdw for provably-empty remote UPDATE/DELETE. In 86dc90056, I'd written find_modifytable_subplan with the assumption that if the immediate child of a ModifyTable is a Result, it must be a projecting Result with a subplan. However, if the UPDATE or DELETE has a provably-constant-false WHERE clause, that's not so: we'll generate a dummy subplan with a childless Result. Add the missing null-check so we don't crash on such cases. Per report from Alexander Pyhalov. Discussion: https://postgr.es/m/b9a6f53549456b2f3e2fd150dcd79d72@postgrespro.ru --- contrib/postgres_fdw/sql/postgres_fdw.sql | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'contrib/postgres_fdw/sql') diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql index 911f171d812..c283e747154 100644 --- a/contrib/postgres_fdw/sql/postgres_fdw.sql +++ b/contrib/postgres_fdw/sql/postgres_fdw.sql @@ -1738,6 +1738,10 @@ DROP TRIGGER trig_local_before ON loc1; -- Test direct foreign table modification functionality +EXPLAIN (verbose, costs off) +DELETE FROM rem1; -- can be pushed down +EXPLAIN (verbose, costs off) +DELETE FROM rem1 WHERE false; -- currently can't be pushed down -- Test with statement-level triggers CREATE TRIGGER trig_stmt_before -- cgit v1.2.3