]> granicus.if.org Git - postgresql/blobdiff - src/backend/executor/nodeModifyTable.c
Phase 2 of pgindent updates.
[postgresql] / src / backend / executor / nodeModifyTable.c
index bf26488c5103358b785d55445dc8596fc40d955f..11594b58b57e32d2dfd00a0fb6ed5493d57e8b9d 100644 (file)
@@ -421,8 +421,8 @@ ExecInsert(ModifyTableState *mtstate,
                 * trigger might modify the tuple such that the partition constraint
                 * is no longer satisfied, so we need to check in that case.
                 */
-               bool    check_partition_constr =
-                                                               (resultRelInfo->ri_PartitionCheck != NIL);
+               bool            check_partition_constr =
+               (resultRelInfo->ri_PartitionCheck != NIL);
 
                /*
                 * Constraints might reference the tableoid column, so initialize
@@ -1561,8 +1561,7 @@ ExecModifyTable(ModifyTableState *node)
                                                elog(ERROR, "ctid is NULL");
 
                                        tupleid = (ItemPointer) DatumGetPointer(datum);
-                                       tuple_ctid = *tupleid;          /* be sure we don't free
-                                                                                                * ctid!! */
+                                       tuple_ctid = *tupleid;  /* be sure we don't free ctid!! */
                                        tupleid = &tuple_ctid;
                                }
 
@@ -1775,7 +1774,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
 
                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 */
+               rel = heap_open(root_oid, NoLock);      /* locked by InitPlan */
        }
        else
                rel = mtstate->resultRelInfo->ri_RelationDesc;
@@ -1841,10 +1840,21 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
        if (node->withCheckOptionLists != NIL && mtstate->mt_num_partitions > 0)
        {
                List       *wcoList;
+               PlanState  *plan;
 
-               Assert(operation == CMD_INSERT);
-               resultRelInfo = mtstate->mt_partitions;
+               /*
+                * In case of INSERT on partitioned tables, there is only one plan.
+                * Likewise, there is only one WITH CHECK OPTIONS list, not one per
+                * partition.  We make a copy of the WCO qual for each partition; note
+                * that, if there are SubPlans in there, they all end up attached to
+                * the one parent Plan node.
+                */
+               Assert(operation == CMD_INSERT &&
+                          list_length(node->withCheckOptionLists) == 1 &&
+                          mtstate->mt_nplans == 1);
                wcoList = linitial(node->withCheckOptionLists);
+               plan = mtstate->mt_plans[0];
+               resultRelInfo = mtstate->mt_partitions;
                for (i = 0; i < mtstate->mt_num_partitions; i++)
                {
                        Relation        partrel = resultRelInfo->ri_RelationDesc;
@@ -1858,9 +1868,9 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
                                                                                                         partrel, rel);
                        foreach(ll, mapped_wcoList)
                        {
-                               WithCheckOption *wco = (WithCheckOption *) lfirst(ll);
-                               ExprState  *wcoExpr = ExecInitQual((List *) wco->qual,
-                                                                                                  mtstate->mt_plans[i]);
+                               WithCheckOption *wco = castNode(WithCheckOption, lfirst(ll));
+                               ExprState  *wcoExpr = ExecInitQual(castNode(List, wco->qual),
+                                                                                                  plan);
 
                                wcoExprs = lappend(wcoExprs, wcoExpr);
                        }