diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-04-07 12:54:22 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-04-07 12:54:22 -0400 |
commit | 159970bcadbbdefd312d75ce7ad90f19add19b40 (patch) | |
tree | 70b7fb8dd090f9918c8e4cb27d6f8827d45afe04 | |
parent | 03f9e5cba0ee1633af4abe734504df50af46fbd8 (diff) | |
download | postgresql-159970bcadbbdefd312d75ce7ad90f19add19b40.tar.gz postgresql-159970bcadbbdefd312d75ce7ad90f19add19b40.zip |
Clean up side-effects of commits ab5fcf2b0 et al.
Before those commits, partitioning-related code in the executor could
assume that ModifyTableState.resultRelInfo[] contains only leaf partitions.
However, now a fully-pruned update results in a dummy ModifyTable that
references the root partitioned table, and that breaks some stuff.
In v11, this led to an assertion or core dump in the tuple routing code.
Fix by disabling tuple routing, since we don't need that anyway.
(I chose to do that in HEAD as well for safety, even though the problem
doesn't manifest in HEAD as it stands.)
In v10, this confused ExecInitModifyTable's decision about whether it
needed to close the root table. But we can get rid of that altogether
by being smarter about where to find the root table.
Note that since the referenced commits haven't shipped yet, this
isn't fixing any bug the field has seen.
Amit Langote, per a report from me
Discussion: https://postgr.es/m/20710.1554582479@sss.pgh.pa.us
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 2 | ||||
-rw-r--r-- | src/test/regress/expected/inherit.out | 9 | ||||
-rw-r--r-- | src/test/regress/sql/inherit.sql | 3 |
3 files changed, 14 insertions, 0 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index cbd3fb8e0ea..5ed691c2e32 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -1732,6 +1732,8 @@ inheritance_planner(PlannerInfo *root) withCheckOptionLists = list_make1(parse->withCheckOptions); if (parse->returningList) returningLists = list_make1(parse->returningList); + /* Disable tuple routing, too, just to be safe */ + root->partColsUpdated = false; } else { diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out index 4725a159487..c6abcfc3cb1 100644 --- a/src/test/regress/expected/inherit.out +++ b/src/test/regress/expected/inherit.out @@ -665,6 +665,15 @@ select tableoid::regclass::text as relname, parted_tab.* from parted_tab order b parted_tab_part3 | 3 | a (3 rows) +-- modifies partition key, but no rows will actually be updated +explain update parted_tab set a = 2 where false; + QUERY PLAN +-------------------------------------------------------- + Update on parted_tab (cost=0.00..0.00 rows=0 width=0) + -> Result (cost=0.00..0.00 rows=0 width=0) + One-Time Filter: false +(3 rows) + drop table parted_tab; -- Check UPDATE with multi-level partitioned inherited target create table mlparted_tab (a int, b char, c text) partition by list (a); diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql index e91f61bc377..ae4358588c3 100644 --- a/src/test/regress/sql/inherit.sql +++ b/src/test/regress/sql/inherit.sql @@ -168,6 +168,9 @@ from where parted_tab.a = ss.a; select tableoid::regclass::text as relname, parted_tab.* from parted_tab order by 1,2; +-- modifies partition key, but no rows will actually be updated +explain update parted_tab set a = 2 where false; + drop table parted_tab; -- Check UPDATE with multi-level partitioned inherited target |