@@ -303,7 +303,7 @@ ExecInsert(ModifyTableState *mtstate,
303
303
* the selected partition.
304
304
*/
305
305
saved_resultRelInfo = resultRelInfo ;
306
- resultRelInfo = mtstate -> mt_partitions + leaf_part_index ;
306
+ resultRelInfo = mtstate -> mt_partitions [ leaf_part_index ] ;
307
307
308
308
/* We do not yet have a way to insert into a foreign partition */
309
309
if (resultRelInfo -> ri_FdwRoutine )
@@ -1498,25 +1498,11 @@ ExecSetupTransitionCaptureState(ModifyTableState *mtstate, EState *estate)
1498
1498
if (mtstate -> mt_transition_capture != NULL ||
1499
1499
mtstate -> mt_oc_transition_capture != NULL )
1500
1500
{
1501
- ResultRelInfo * resultRelInfos ;
1502
1501
int numResultRelInfos ;
1503
1502
1504
- /* Find the set of partitions so that we can find their TupleDescs. */
1505
- if (mtstate -> mt_partition_dispatch_info != NULL )
1506
- {
1507
- /*
1508
- * For INSERT via partitioned table, so we need TupleDescs based
1509
- * on the partition routing table.
1510
- */
1511
- resultRelInfos = mtstate -> mt_partitions ;
1512
- numResultRelInfos = mtstate -> mt_num_partitions ;
1513
- }
1514
- else
1515
- {
1516
- /* Otherwise we need the ResultRelInfo for each subplan. */
1517
- resultRelInfos = mtstate -> resultRelInfo ;
1518
- numResultRelInfos = mtstate -> mt_nplans ;
1519
- }
1503
+ numResultRelInfos = (mtstate -> mt_partition_tuple_slot != NULL ?
1504
+ mtstate -> mt_num_partitions :
1505
+ mtstate -> mt_nplans );
1520
1506
1521
1507
/*
1522
1508
* Build array of conversion maps from each child's TupleDesc to the
@@ -1526,12 +1512,36 @@ ExecSetupTransitionCaptureState(ModifyTableState *mtstate, EState *estate)
1526
1512
*/
1527
1513
mtstate -> mt_transition_tupconv_maps = (TupleConversionMap * * )
1528
1514
palloc0 (sizeof (TupleConversionMap * ) * numResultRelInfos );
1529
- for (i = 0 ; i < numResultRelInfos ; ++ i )
1515
+
1516
+ /* Choose the right set of partitions */
1517
+ if (mtstate -> mt_partition_dispatch_info != NULL )
1530
1518
{
1531
- mtstate -> mt_transition_tupconv_maps [i ] =
1532
- convert_tuples_by_name (RelationGetDescr (resultRelInfos [i ].ri_RelationDesc ),
1533
- RelationGetDescr (targetRelInfo -> ri_RelationDesc ),
1534
- gettext_noop ("could not convert row type" ));
1519
+ /*
1520
+ * For tuple routing among partitions, we need TupleDescs based
1521
+ * on the partition routing table.
1522
+ */
1523
+ ResultRelInfo * * resultRelInfos = mtstate -> mt_partitions ;
1524
+
1525
+ for (i = 0 ; i < numResultRelInfos ; ++ i )
1526
+ {
1527
+ mtstate -> mt_transition_tupconv_maps [i ] =
1528
+ convert_tuples_by_name (RelationGetDescr (resultRelInfos [i ]-> ri_RelationDesc ),
1529
+ RelationGetDescr (targetRelInfo -> ri_RelationDesc ),
1530
+ gettext_noop ("could not convert row type" ));
1531
+ }
1532
+ }
1533
+ else
1534
+ {
1535
+ /* Otherwise we need the ResultRelInfo for each subplan. */
1536
+ ResultRelInfo * resultRelInfos = mtstate -> resultRelInfo ;
1537
+
1538
+ for (i = 0 ; i < numResultRelInfos ; ++ i )
1539
+ {
1540
+ mtstate -> mt_transition_tupconv_maps [i ] =
1541
+ convert_tuples_by_name (RelationGetDescr (resultRelInfos [i ].ri_RelationDesc ),
1542
+ RelationGetDescr (targetRelInfo -> ri_RelationDesc ),
1543
+ gettext_noop ("could not convert row type" ));
1544
+ }
1535
1545
}
1536
1546
1537
1547
/*
@@ -1935,7 +1945,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
1935
1945
rel -> rd_rel -> relkind == RELKIND_PARTITIONED_TABLE )
1936
1946
{
1937
1947
PartitionDispatch * partition_dispatch_info ;
1938
- ResultRelInfo * partitions ;
1948
+ ResultRelInfo * * partitions ;
1939
1949
TupleConversionMap * * partition_tupconv_maps ;
1940
1950
TupleTableSlot * partition_tuple_slot ;
1941
1951
int num_parted ,
@@ -2014,14 +2024,16 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
2014
2024
mtstate -> mt_nplans == 1 );
2015
2025
wcoList = linitial (node -> withCheckOptionLists );
2016
2026
plan = mtstate -> mt_plans [0 ];
2017
- resultRelInfo = mtstate -> mt_partitions ;
2018
2027
for (i = 0 ; i < mtstate -> mt_num_partitions ; i ++ )
2019
2028
{
2020
- Relation partrel = resultRelInfo -> ri_RelationDesc ;
2029
+ Relation partrel ;
2021
2030
List * mapped_wcoList ;
2022
2031
List * wcoExprs = NIL ;
2023
2032
ListCell * ll ;
2024
2033
2034
+ resultRelInfo = mtstate -> mt_partitions [i ];
2035
+ partrel = resultRelInfo -> ri_RelationDesc ;
2036
+
2025
2037
/* varno = node->nominalRelation */
2026
2038
mapped_wcoList = map_partition_varattnos (wcoList ,
2027
2039
node -> nominalRelation ,
@@ -2037,7 +2049,6 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
2037
2049
2038
2050
resultRelInfo -> ri_WithCheckOptions = mapped_wcoList ;
2039
2051
resultRelInfo -> ri_WithCheckOptionExprs = wcoExprs ;
2040
- resultRelInfo ++ ;
2041
2052
}
2042
2053
}
2043
2054
@@ -2088,21 +2099,22 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
2088
2099
* will suffice. This only occurs for the INSERT case; UPDATE/DELETE
2089
2100
* are handled above.
2090
2101
*/
2091
- resultRelInfo = mtstate -> mt_partitions ;
2092
2102
returningList = linitial (node -> returningLists );
2093
2103
for (i = 0 ; i < mtstate -> mt_num_partitions ; i ++ )
2094
2104
{
2095
- Relation partrel = resultRelInfo -> ri_RelationDesc ;
2105
+ Relation partrel ;
2096
2106
List * rlist ;
2097
2107
2108
+ resultRelInfo = mtstate -> mt_partitions [i ];
2109
+ partrel = resultRelInfo -> ri_RelationDesc ;
2110
+
2098
2111
/* varno = node->nominalRelation */
2099
2112
rlist = map_partition_varattnos (returningList ,
2100
2113
node -> nominalRelation ,
2101
2114
partrel , rel , NULL );
2102
2115
resultRelInfo -> ri_projectReturning =
2103
2116
ExecBuildProjectionInfo (rlist , econtext , slot , & mtstate -> ps ,
2104
2117
resultRelInfo -> ri_RelationDesc -> rd_att );
2105
- resultRelInfo ++ ;
2106
2118
}
2107
2119
}
2108
2120
else
@@ -2376,7 +2388,7 @@ ExecEndModifyTable(ModifyTableState *node)
2376
2388
}
2377
2389
for (i = 0 ; i < node -> mt_num_partitions ; i ++ )
2378
2390
{
2379
- ResultRelInfo * resultRelInfo = node -> mt_partitions + i ;
2391
+ ResultRelInfo * resultRelInfo = node -> mt_partitions [ i ] ;
2380
2392
2381
2393
ExecCloseIndices (resultRelInfo );
2382
2394
heap_close (resultRelInfo -> ri_RelationDesc , NoLock );
0 commit comments