]> granicus.if.org Git - postgresql/commitdiff
Clean up side-effects of commits ab5fcf2b0 et al.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 7 Apr 2019 16:54:26 +0000 (12:54 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 7 Apr 2019 16:54:26 +0000 (12:54 -0400)
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

src/backend/executor/nodeModifyTable.c
src/test/regress/expected/inherit.out
src/test/regress/sql/inherit.sql

index 7de4568b03e553502b13a162437abdfccf0da197..e86ed44a476fdd3a38114ca18e57cb8b1342f826 100644 (file)
@@ -1933,16 +1933,9 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
 
        estate->es_result_relation_info = saved_resultRelInfo;
 
-       /* The root table RT index is at the head of the partitioned_rels list */
-       if (node->partitioned_rels)
-       {
-               Index           root_rti;
-               Oid                     root_oid;
-
-               root_rti = linitial_int(node->partitioned_rels);
-               root_oid = getrelid(root_rti, estate->es_range_table);
-               rel = heap_open(root_oid, NoLock);      /* locked by InitPlan */
-       }
+       /* Examine the root partition if we have one, else target table */
+       if (mtstate->rootResultRelInfo)
+               rel = mtstate->rootResultRelInfo->ri_RelationDesc;
        else
                rel = mtstate->resultRelInfo->ri_RelationDesc;
 
@@ -2134,10 +2127,6 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
                mtstate->ps.ps_ExprContext = NULL;
        }
 
-       /* Close the root partitioned rel if we opened it above. */
-       if (rel != mtstate->resultRelInfo->ri_RelationDesc)
-               heap_close(rel, NoLock);
-
        /*
         * If needed, Initialize target list, projection and qual for ON CONFLICT
         * DO UPDATE.
index da7608734ca4223b8f56ba7437240228ca15f7a6..79ea0c5774ee9a2bafcf1b820de0edd3e7a39960 100644 (file)
@@ -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;
 drop table some_tab cascade;
 NOTICE:  drop cascades to table some_tab_child
index bbe453cf26e453f5ea4ffdaeec067d2b3a3d4873..101a0394f87793d223da7a48227c095567919659 100644 (file)
@@ -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;
 drop table some_tab cascade;