8000 [PGPRO-13804] Save original RTEPermissionInfo array before adding a n… · postgrespro/pg_pathman@a0fd611 · GitHub
[go: up one dir, main page]

Skip to content

Commit a0fd611

Browse files
committed
[PGPRO-13804] Save original RTEPermissionInfo array before adding a new element
1 parent 73aafcf commit a0fd611

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/partition_filter.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ typedef struct
5151
{
5252
int estate_alloc_result_rels; /* number of allocated result rels */
5353
bool estate_not_modified; /* did we modify EState somehow? */
54+
#if PG_VERSION_NUM >= 160000
55+
bool perminfo_not_modified; /* did we change the estate->es_rteperminfos field? */
56+
#endif
5457
} estate_mod_data;
5558

5659
/*
@@ -95,6 +98,9 @@ static Node *fix_returning_list_mutator(Node *node, void *state);
9598

9699
static Index append_rte_to_estate(EState *estate, RangeTblEntry *rte, Relation child_rel);
97100
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
98104

99105
static void pf_memcxt_callback(void *arg);
100106
static estate_mod_data * fetch_estate_mod_data(EState *estate);
@@ -337,6 +343,7 @@ scan_result_parts_storage(EState *estate, ResultPartsStorage *parts_storage,
337343
parent_perminfo = getRTEPermissionInfo(estate->es_rteperminfos, init_rte);
338344

339345
child_rte->perminfoindex = 0; /* expected by addRTEPermissionInfo() */
346+
prepare_estate_for_append_perminfo(estate);
340347
child_perminfo = addRTEPermissionInfo(&estate->es_rteperminfos, child_rte);
341348
child_perminfo->requiredPerms = parent_perminfo->requiredPerms;
342349
child_perminfo->checkAsUser = parent_perminfo->checkAsUser;
@@ -1449,6 +1456,22 @@ fix_returning_list_mutator(Node *node, void *state)
14491456
* -------------------------------------
14501457
*/
14511458

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+
14521475
/* Append RangeTblEntry 'rte' to estate->es_range_table */
14531476
static Index
14541477
append_rte_to_estate(EState *estate, RangeTblEntry *rte, Relation child_rel)
@@ -1594,6 +1617,9 @@ fetch_estate_mod_data(EState *estate)
15941617
/* Have to create a new one */
15951618
emd_struct = MemoryContextAlloc(estate_mcxt, sizeof(estate_mod_data));
15961619
emd_struct->estate_not_modified = true;
1620+
#if PG_VERSION_NUM >= 160000
1621+
emd_struct->perminfo_not_modified = true;
1622+
#endif
15971623
#if PG_VERSION_NUM >= 140000
15981624
/*
15991625
* Reworked in commit a04daa97a433: field "es_num_result_relations"

0 commit comments

Comments
 (0)
0