Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 10e3991

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 c2a5fb3 commit 10e3991

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/backend/optimizer/plan/planner.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,15 @@ inheritance_planner(PlannerInfo *root)
15991599
withCheckOptionLists = list_make1(parse->withCheckOptions);
16001600
if (parse->returningList)
16011601
returningLists = list_make1(parse->returningList);
1602+
1603+
/*
1604+
* Since no tuples will be updated, don't require ModifyTable to
1605+
* create tuple-routing info that will be left unused. In fact it's
1606+
* necessary to do so, because we're cheating here by putting the root
1607+
* table into resultRelations list, which the tuple-routing code is
1608+
* not expecting to be there.
1609+
*/
1610+
root->partColsUpdated = false;
16021611
}
16031612
else
16041613
{

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
-- Check UPDATE with multi-level partitioned inherited target
670679
create table mlparted_tab (a int, b char, c text) partition by list (a);

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

173176
-- Check UPDATE with multi-level partitioned inherited target

0 commit comments

Comments
 (0)