Skip to content

Commit b9734c1

Browse files
committed
Fix crash in postgres_fdw for provably-empty remote UPDATE/DELETE.
In 86dc900, 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
1 parent 9d2a775 commit b9734c1

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6853,6 +6853,26 @@ DROP TRIGGER trig_row_before ON rem1;
68536853
DROP TRIGGER trig_row_after ON rem1;
68546854
DROP TRIGGER trig_local_before ON loc1;
68556855
-- Test direct foreign table modification functionality
6856+
EXPLAIN (verbose, costs off)
6857+
DELETE FROM rem1; -- can be pushed down
6858+
QUERY PLAN
6859+
---------------------------------------------
6860+
Delete on public.rem1
6861+
-> Foreign Delete on public.rem1
6862+
Remote SQL: DELETE FROM public.loc1
6863+
(3 rows)
6864+
6865+
EXPLAIN (verbose, costs off)
6866+
DELETE FROM rem1 WHERE false; -- currently can't be pushed down
6867+
QUERY PLAN
6868+
-------------------------------------------------------
6869+
Delete on public.rem1
6870+
Remote SQL: DELETE FROM public.loc1 WHERE ctid = $1
6871+
-> Result
6872+
Output: ctid
6873+
One-Time Filter: false
6874+
(5 rows)
6875+
68566876
-- Test with statement-level triggers
68576877
CREATE TRIGGER trig_stmt_before
68586878
BEFORE DELETE OR INSERT OR UPDATE ON rem1

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2370,7 +2370,9 @@ find_modifytable_subplan(PlannerInfo *root,
23702370
if (subplan_index < list_length(appendplan->appendplans))
23712371
subplan = (Plan *) list_nth(appendplan->appendplans, subplan_index);
23722372
}
2373-
else if (IsA(subplan, Result) && IsA(outerPlan(subplan), Append))
2373+
else if (IsA(subplan, Result) &&
2374+
outerPlan(subplan) != NULL &&
2375+
IsA(outerPlan(subplan), Append))
23742376
{
23752377
Append *appendplan = (Append *) outerPlan(subplan);
23762378

contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,10 @@ DROP TRIGGER trig_local_before ON loc1;
17381738

17391739

17401740
-- Test direct foreign table modification functionality
1741+
EXPLAIN (verbose, costs off)
1742+
DELETE FROM rem1; -- can be pushed down
1743+
EXPLAIN (verbose, costs off)
1744+
DELETE FROM rem1 WHERE false; -- currently can't be pushed down
17411745

17421746
-- Test with statement-level triggers
17431747
CREATE TRIGGER trig_stmt_before

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy