@@ -161,11 +161,11 @@ typedef struct CopyStateData
161161 ExprState * * defexprs ; /* array of default att expressions */
162162 bool volatile_defexprs ; /* is any of defexprs volatile? */
163163 List * range_table ;
164- PartitionDispatch * partition_dispatch_info ;
165- int num_dispatch ;
166- int num_partitions ;
167- ResultRelInfo * partitions ;
168- TupleConversionMap * * partition_tupconv_maps ;
164+ PartitionDispatch * partition_dispatch_info ;
165+ int num_dispatch ;
166+ int num_partitions ;
167+ ResultRelInfo * partitions ;
168+ TupleConversionMap * * partition_tupconv_maps ;
169169
170170 /*
171171 * These variables are used to reduce overhead in textual COPY FROM.
@@ -1403,31 +1403,28 @@ BeginCopy(ParseState *pstate,
14031403 errmsg ("table \"%s\" does not have OIDs" ,
14041404 RelationGetRelationName (cstate -> rel ))));
14051405
1406- /*
1407- * Initialize state for CopyFrom tuple routing. Watch out for
1408- * any foreign partitions.
1409- */
1406+ /* Initialize state for CopyFrom tuple routing. */
14101407 if (is_from && rel -> rd_rel -> relkind == RELKIND_PARTITIONED_TABLE )
14111408 {
1412- PartitionDispatch * pd ;
1413- List * leaf_parts ;
1414- ListCell * cell ;
1415- int i ,
1416- num_parted ,
1417- num_leaf_parts ;
1418- ResultRelInfo * leaf_part_rri ;
1409+ List * leaf_parts ;
1410+ ListCell * cell ;
1411+ int i ,
1412+ num_parted ;
1413+ ResultRelInfo * leaf_part_rri ;
14191414
14201415 /* Get the tuple-routing information and lock partitions */
1421- pd = RelationGetPartitionDispatchInfo ( rel , RowExclusiveLock ,
1422- & num_parted , & leaf_parts );
1423- num_leaf_parts = list_length ( leaf_parts );
1424- cstate -> partition_dispatch_info = pd ;
1416+ cstate -> partition_dispatch_info =
1417+ RelationGetPartitionDispatchInfo ( rel , RowExclusiveLock ,
1418+ & num_parted ,
1419+ & leaf_parts ) ;
14251420 cstate -> num_dispatch = num_parted ;
1426- cstate -> num_partitions = num_leaf_parts ;
1427- cstate -> partitions = (ResultRelInfo * ) palloc (num_leaf_parts *
1428- sizeof (ResultRelInfo ));
1421+ cstate -> num_partitions = list_length (leaf_parts );
1422+ cstate -> partitions = (ResultRelInfo * )
1423+ palloc (cstate -> num_partitions *
1424+ sizeof (ResultRelInfo ));
14291425 cstate -> partition_tupconv_maps = (TupleConversionMap * * )
1430- palloc0 (num_leaf_parts * sizeof (TupleConversionMap * ));
1426+ palloc0 (cstate -> num_partitions *
1427+ sizeof (TupleConversionMap * ));
14311428
14321429 leaf_part_rri = cstate -> partitions ;
14331430 i = 0 ;
@@ -1438,8 +1435,8 @@ BeginCopy(ParseState *pstate,
14381435 /*
14391436 * We locked all the partitions above including the leaf
14401437 * partitions. Note that each of the relations in
1441- * cstate->partitions will be closed by CopyFrom() after
1442- * it's finished with its processing.
1438+ * cstate->partitions will be closed by CopyFrom() after it's
1439+ * finished with its processing.
14431440 */
14441441 partrel = heap_open (lfirst_oid (cell ), NoLock );
14451442
@@ -1451,18 +1448,19 @@ BeginCopy(ParseState *pstate,
14511448
14521449 InitResultRelInfo (leaf_part_rri ,
14531450 partrel ,
1454- 1 , /* dummy */
1455- false, /* no partition constraint check */
1451+ 1 , /* dummy */
1452+ false, /* no partition constraint
1453+ * check */
14561454 0 );
14571455
14581456 /* Open partition indices */
14591457 ExecOpenIndices (leaf_part_rri , false);
14601458
14611459 if (!equalTupleDescs (tupDesc , RelationGetDescr (partrel )))
14621460 cstate -> partition_tupconv_maps [i ] =
1463- convert_tuples_by_name (tupDesc ,
1464- RelationGetDescr (partrel ),
1465- gettext_noop ("could not convert row type" ));
1461+ convert_tuples_by_name (tupDesc ,
1462+ RelationGetDescr (partrel ),
1463+ gettext_noop ("could not convert row type" ));
14661464 leaf_part_rri ++ ;
14671465 i ++ ;
14681466 }
@@ -2486,8 +2484,8 @@ CopyFrom(CopyState cstate)
24862484 * BEFORE/INSTEAD OF triggers, or we need to evaluate volatile default
24872485 * expressions. Such triggers or expressions might query the table we're
24882486 * inserting to, and act differently if the tuples that have already been
2489- * processed and prepared for insertion are not there. We also can't
2490- * do it if the table is partitioned.
2487+ * processed and prepared for insertion are not there. We also can't do
2488+ * it if the table is partitioned.
24912489 */
24922490 if ((resultRelInfo -> ri_TrigDesc != NULL &&
24932491 (resultRelInfo -> ri_TrigDesc -> trig_insert_before_row ||
@@ -2572,7 +2570,7 @@ CopyFrom(CopyState cstate)
25722570 /* Determine the partition to heap_insert the tuple into */
25732571 if (cstate -> partition_dispatch_info )
25742572 {
2575- int leaf_part_index ;
2573+ int leaf_part_index ;
25762574 TupleConversionMap * map ;
25772575
25782576 /*
@@ -2584,7 +2582,7 @@ CopyFrom(CopyState cstate)
25842582 * partition, respectively.
25852583 */
25862584 leaf_part_index = ExecFindPartition (resultRelInfo ,
2587- cstate -> partition_dispatch_info ,
2585+ cstate -> partition_dispatch_info ,
25882586 slot ,
25892587 estate );
25902588 Assert (leaf_part_index >= 0 &&
@@ -2601,7 +2599,7 @@ CopyFrom(CopyState cstate)
26012599 if (resultRelInfo -> ri_FdwRoutine )
26022600 ereport (ERROR ,
26032601 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
2604- errmsg ("cannot route inserted tuples to a foreign table" )));
2602+ errmsg ("cannot route inserted tuples to a foreign table" )));
26052603
26062604 /*
26072605 * For ExecInsertIndexTuples() to work on the partition's indexes
@@ -2752,7 +2750,7 @@ CopyFrom(CopyState cstate)
27522750 /* Close all the partitioned tables, leaf partitions, and their indices */
27532751 if (cstate -> partition_dispatch_info )
27542752 {
2755- int i ;
2753+ int i ;
27562754
27572755 /*
27582756 * Remember cstate->partition_dispatch_info[0] corresponds to the root
0 commit comments