@@ -72,7 +72,6 @@ static TupleTableSlot *ExecPrepareTupleRouting(ModifyTableState *mtstate,
72
72
ResultRelInfo * targetRelInfo ,
73
73
TupleTableSlot * slot ,
74
74
ResultRelInfo * * partRelInfo );
75
- static ResultRelInfo * getTargetResultRelInfo (ModifyTableState * node );
76
75
static void ExecSetupChildParentMapForSubplan (ModifyTableState * mtstate );
77
76
static TupleConversionMap * tupconv_map_for_subplan (ModifyTableState * node ,
78
77
int whichplan );
@@ -1186,7 +1185,6 @@ ExecCrossPartitionUpdate(ModifyTableState *mtstate,
1186
1185
saved_tcs_map = mtstate -> mt_transition_capture -> tcs_map ;
1187
1186
1188
1187
/* Tuple routing starts from the root table. */
1189
- Assert (mtstate -> rootResultRelInfo != NULL );
1190
1188
* inserted_tuple = ExecInsert (mtstate , mtstate -> rootResultRelInfo , slot ,
1191
1189
planSlot , estate , canSetTag );
1192
1190
@@ -1796,15 +1794,7 @@ static void
1796
1794
fireBSTriggers (ModifyTableState * node )
1797
1795
{
1798
1796
ModifyTable * plan = (ModifyTable * ) node -> ps .plan ;
1799
- ResultRelInfo * resultRelInfo = node -> resultRelInfo ;
1800
-
1801
- /*
1802
- * If the node modifies a partitioned table, we must fire its triggers.
1803
- * Note that in that case, node->resultRelInfo points to the first leaf
1804
- * partition, not the root table.
1805
- */
1806
- if (node -> rootResultRelInfo != NULL )
1807
- resultRelInfo = node -> rootResultRelInfo ;
1797
+ ResultRelInfo * resultRelInfo = node -> rootResultRelInfo ;
1808
1798
1809
1799
switch (node -> operation )
1810
1800
{
@@ -1826,36 +1816,14 @@ fireBSTriggers(ModifyTableState *node)
1826
1816
}
1827
1817
}
1828
1818
1829
- /*
1830
- * Return the target rel ResultRelInfo.
1831
- *
1832
- * This relation is the same as :
1833
- * - the relation for which we will fire AFTER STATEMENT triggers.
1834
- * - the relation into whose tuple format all captured transition tuples must
1835
- * be converted.
1836
- * - the root partitioned table.
1837
- */
1838
- static ResultRelInfo *
1839
- getTargetResultRelInfo (ModifyTableState * node )
1840
- {
1841
- /*
1842
- * Note that if the node modifies a partitioned table, node->resultRelInfo
1843
- * points to the first leaf partition, not the root table.
1844
- */
1845
- if (node -> rootResultRelInfo != NULL )
1846
- return node -> rootResultRelInfo ;
1847
- else
1848
- return node -> resultRelInfo ;
1849
- }
1850
-
1851
1819
/*
1852
1820
* Process AFTER EACH STATEMENT triggers
1853
1821
*/
1854
1822
static void
1855
1823
fireASTriggers (ModifyTableState * node )
1856
1824
{
1857
1825
ModifyTable * plan = (ModifyTable * ) node -> ps .plan ;
1858
- ResultRelInfo * resultRelInfo = getTargetResultRelInfo ( node ) ;
1826
+ ResultRelInfo * resultRelInfo = node -> rootResultRelInfo ;
1859
1827
1860
1828
switch (node -> operation )
1861
1829
{
@@ -1889,7 +1857,7 @@ static void
1889
1857
ExecSetupTransitionCaptureState (ModifyTableState * mtstate , EState * estate )
1890
1858
{
1891
1859
ModifyTable * plan = (ModifyTable * ) mtstate -> ps .plan ;
1892
- ResultRelInfo * targetRelInfo = getTargetResultRelInfo ( mtstate ) ;
1860
+ ResultRelInfo * targetRelInfo = mtstate -> rootResultRelInfo ;
1893
1861
1894
1862
/* Check for transition tables on the directly targeted relation. */
1895
1863
mtstate -> mt_transition_capture =
@@ -2019,7 +1987,7 @@ ExecPrepareTupleRouting(ModifyTableState *mtstate,
2019
1987
static void
2020
1988
ExecSetupChildParentMapForSubplan (ModifyTableState * mtstate )
2021
1989
{
2022
- ResultRelInfo * targetRelInfo = getTargetResultRelInfo ( mtstate ) ;
1990
+ ResultRelInfo * targetRelInfo = mtstate -> rootResultRelInfo ;
2023
1991
ResultRelInfo * resultRelInfos = mtstate -> resultRelInfo ;
2024
1992
TupleDesc outdesc ;
2025
1993
int numResultRelInfos = mtstate -> mt_nplans ;
@@ -2355,13 +2323,31 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
2355
2323
palloc (nplans * sizeof (ResultRelInfo ));
2356
2324
mtstate -> mt_scans = (TupleTableSlot * * ) palloc0 (sizeof (TupleTableSlot * ) * nplans );
2357
2325
2358
- /* If modifying a partitioned table, initialize the root table info */
2326
+ /*----------
2327
+ * Resolve the target relation. This is the same as:
2328
+ *
2329
+ * - the relation for which we will fire FOR STATEMENT triggers,
2330
+ * - the relation into whose tuple format all captured transition tuples
2331
+ * must be converted, and
2332
+ * - the root partitioned table used for tuple routing.
2333
+ *
2334
+ * If it's a partitioned table, the root partition doesn't appear
2335
+ * elsewhere in the plan and its RT index is given explicitly in
2336
+ * node->rootRelation. Otherwise (i.e. table inheritance) the target
2337
+ * relation is the first relation in the node->resultRelations list, and
2338
+ * we will initialize it in the loop below.
2339
+ *----------
2340
+ */
2359
2341
if (node -> rootRelation > 0 )
2360
2342
{
2361
2343
mtstate -> rootResultRelInfo = makeNode (ResultRelInfo );
2362
2344
ExecInitResultRelation (estate , mtstate -> rootResultRelInfo ,
2363
2345
node -> rootRelation );
2364
2346
}
2347
+ else
2348
+ {
2349
+ mtstate -> rootResultRelInfo = mtstate -> resultRelInfo ;
2350
+ }
2365
2351
2366
2352
mtstate -> mt_arowmarks = (List * * ) palloc0 (sizeof (List * ) * nplans );
2367
2353
mtstate -> mt_nplans = nplans ;
@@ -2446,7 +2432,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
2446
2432
}
2447
2433
2448
2434
/* Get the target relation */
2449
- rel = ( getTargetResultRelInfo ( mtstate )) -> ri_RelationDesc ;
2435
+ rel = mtstate -> rootResultRelInfo -> ri_RelationDesc ;
2450
2436
2451
2437
/*
2452
2438
* If it's not a partitioned table after all, UPDATE tuple routing should
0 commit comments