@@ -51,6 +51,9 @@ typedef struct
51
51
{
52
52
int estate_alloc_result_rels ;/* number of allocated result rels */
53
53
bool estate_not_modified ;/* did we modify EState somehow? */
54
+ #if PG_VERSION_NUM >=160000
55
+ bool perminfo_not_modified ;/* did we modify EState somehow? */
56
+ #endif
54
57
}estate_mod_data ;
55
58
56
59
/*
@@ -95,6 +98,9 @@ static Node *fix_returning_list_mutator(Node *node, void *state);
95
98
96
99
static Index append_rte_to_estate (EState * estate ,RangeTblEntry * rte ,Relation child_rel );
97
100
static int append_rri_to_estate (EState * estate ,ResultRelInfo * rri );
101
+ #if PG_VERSION_NUM >=160000
102
+ static void prepare_estate_for_append_perminfo (EState * estate );
103
+ #endif
98
104
99
105
static void pf_memcxt_callback (void * arg );
100
106
static estate_mod_data * fetch_estate_mod_data (EState * estate );
@@ -337,6 +343,7 @@ scan_result_parts_storage(EState *estate, ResultPartsStorage *parts_storage,
337
343
parent_perminfo = getRTEPermissionInfo (estate -> es_rteperminfos ,init_rte );
338
344
339
345
child_rte -> perminfoindex = 0 ;/* expected by addRTEPermissionInfo() */
346
+ prepare_estate_for_append_perminfo (estate );
340
347
child_perminfo = addRTEPermissionInfo (& estate -> es_rteperminfos ,child_rte );
341
348
child_perminfo -> requiredPerms = parent_perminfo -> requiredPerms ;
342
349
child_perminfo -> checkAsUser = parent_perminfo -> checkAsUser ;
@@ -1449,6 +1456,22 @@ fix_returning_list_mutator(Node *node, void *state)
1449
1456
* -------------------------------------
1450
1457
*/
1451
1458
1459
+ #if PG_VERSION_NUM >=160000
1460
+ /* Prepare estate->es_rteperminfos for append RTEPermissionInfo */
1461
+ static void
1462
+ prepare_estate_for_append_perminfo (EState * estate )
1463
+ {
1464
+ estate_mod_data * emd_struct = fetch_estate_mod_data (estate );
1465
+
1466
+ /* Copy estate->es_rteperminfos if it's first time expansion. */
1467
+ if (emd_struct -> perminfo_not_modified )
1468
+ estate -> es_rteperminfos = list_copy (estate -> es_rteperminfos );
1469
+
1470
+ /* Update estate_mod_data. */
1471
+ emd_struct -> perminfo_not_modified = false;
1472
+ }
1473
+ #endif
1474
+
1452
1475
/* Append RangeTblEntry 'rte' to estate->es_range_table */
1453
1476
static Index
1454
1477
append_rte_to_estate (EState * estate ,RangeTblEntry * rte ,Relation child_rel )
@@ -1594,6 +1617,9 @@ fetch_estate_mod_data(EState *estate)
1594
1617
/* Have to create a new one */
1595
1618
emd_struct = MemoryContextAlloc (estate_mcxt ,sizeof (estate_mod_data ));
1596
1619
emd_struct -> estate_not_modified = true;
1620
+ #if PG_VERSION_NUM >=160000
1621
+ emd_struct -> perminfo_not_modified = true;
1622
+ #endif
1597
1623
#if PG_VERSION_NUM >=140000
1598
1624
/*
1599
1625
* Reworked in commit a04daa97a433: field "es_num_result_relations"