Skip to content

Commit 67999b3

Browse files
committed
Clean up side-effects of commits ab5fcf2 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
1 parent 7d18a55 commit 67999b3

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/backend/executor/nodeModifyTable.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,16 +1933,9 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
19331933

19341934
estate->es_result_relation_info = saved_resultRelInfo;
19351935

1936-
/* The root table RT index is at the head of the partitioned_rels list */
1937-
if (node->partitioned_rels)
1938-
{
1939-
Index root_rti;
1940-
Oid root_oid;
1941-
1942-
root_rti = linitial_int(node->partitioned_rels);
1943-
root_oid = getrelid(root_rti, estate->es_range_table);
1944-
rel = heap_open(root_oid, NoLock); /* locked by InitPlan */
1945-
}
1936+
/* Examine the root partition if we have one, else target table */
1937+
if (mtstate->rootResultRelInfo)
1938+
rel = mtstate->rootResultRelInfo->ri_RelationDesc;
19461939
else
19471940
rel = mtstate->resultRelInfo->ri_RelationDesc;
19481941

@@ -2134,10 +2127,6 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
21342127
mtstate->ps.ps_ExprContext = NULL;
21352128
}
21362129

2137-
/* Close the root partitioned rel if we opened it above. */
2138-
if (rel != mtstate->resultRelInfo->ri_RelationDesc)
2139-
heap_close(rel, NoLock);
2140-
21412130
/*
21422131
* If needed, Initialize target list, projection and qual for ON CONFLICT
21432132
* DO UPDATE.

src/test/regress/expected/inherit.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,15 @@ select tableoid::regclass::text as relname, parted_tab.* from parted_tab order b
665665
parted_tab_part3 | 3 | a
666666
(3 rows)
667667

668+
-- modifies partition key, but no rows will actually be updated
669+
explain update parted_tab set a = 2 where false;
670+
QUERY PLAN
671+
--------------------------------------------------------
672+
Update on parted_tab (cost=0.00..0.00 rows=0 width=0)
673+
-> Result (cost=0.00..0.00 rows=0 width=0)
674+
One-Time Filter: false
675+
(3 rows)
676+
668677
drop table parted_tab;
669678
drop table some_tab cascade;
670679
NOTICE: drop cascades to table some_tab_child

src/test/regress/sql/inherit.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ from
168168
where parted_tab.a = ss.a;
169169
select tableoid::regclass::text as relname, parted_tab.* from parted_tab order by 1,2;
170170

171+
-- modifies partition key, but no rows will actually be updated
172+
explain update parted_tab set a = 2 where false;
173+
171174
drop table parted_tab;
172175
drop table some_tab cascade;
173176

0 commit comments

Comments
 (0)