diff --git a/src/common/backend/utils/cache/knl_globaltabdefcache.cpp b/src/common/backend/utils/cache/knl_globaltabdefcache.cpp index 16996d647..15e8d20d8 100644 --- a/src/common/backend/utils/cache/knl_globaltabdefcache.cpp +++ b/src/common/backend/utils/cache/knl_globaltabdefcache.cpp @@ -433,7 +433,8 @@ Relation CopyRelationData(Relation newrel, Relation rel, MemoryContext rules_cxt * otherwise, do the copy work here * if the variable changed, there is no lock and no rel inval msg, * set it zero and reinit it when copy into local */ - Assert(sizeof(RelationData) == 544); +#define RD_SIZE 552 + Assert(sizeof(RelationData) == RD_SIZE); /* all copied exclude pointer */ *newrel = *rel; Assert(rel->rd_createSubid == InvalidSubTransactionId); @@ -493,6 +494,7 @@ Relation CopyRelationData(Relation newrel, Relation rel, MemoryContext rules_cxt newrel->entry = NULL; newrel->rd_ind_partition_all_usable = rel->rd_ind_partition_all_usable; + newrel->rd_optionsValid = rel->rd_optionsValid; return newrel; } diff --git a/src/common/backend/utils/cache/relcache.cpp b/src/common/backend/utils/cache/relcache.cpp index 6c5563955..d9f3fa6a4 100755 --- a/src/common/backend/utils/cache/relcache.cpp +++ b/src/common/backend/utils/cache/relcache.cpp @@ -3834,6 +3834,7 @@ void RelationClearRelation(Relation relation, bool rebuild) relation->rd_indexlist = NIL; relation->rd_oidindex = InvalidOid; relation->rd_indexvalid = 0; + relation->rd_optionsValid = false; return; } @@ -7874,6 +7875,7 @@ static bool load_relcache_init_file(bool shared) rel->rd_amcache = NULL; rel->rd_rootcache = InvalidBuffer; rel->pgstat_info = NULL; + rel->rd_optionsValid = true; /* * Recompute lock and physical addressing info. This is needed in @@ -8961,3 +8963,20 @@ bool IsRelationReplidentKey(Relation r, int attno) RelationClose(idx_rel); return false; } + +void RelationReloadRdOption(Relation relation) +{ + HeapTuple htup = SearchSysCache1(RELOID, ObjectIdGetDatum(RelationGetRelid(relation))); + Assert(HeapTupleIsValid(htup)); + + pfree_ext(relation->rd_options); + RelationParseRelOptions(relation, htup); + + ReleaseSysCache(htup); + + if (RelationEnableRowSecurity(relation)) { + RelationDestroyRls(relation); + RelationBuildRlsPolicies(relation); + } + relation->rd_optionsValid = true; +} diff --git a/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp b/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp index 41f684cc2..35b0f5b5b 100644 --- a/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp +++ b/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp @@ -2391,6 +2391,11 @@ static Query* fireRIRrules(Query* parsetree, List* activeRIRs, bool forUpdatePus } Relation targetTable = relation_open(rte->relid, NoLock); + + if (!targetTable->rd_optionsValid) { + RelationReloadRdOption(targetTable); + } + /* Fetch all R.L.S security quals that must be applied to this RTE */ GetRlsPolicies(parsetree, rte, targetTable, &securityQuals, rt_index, hasRowSecurity, hasSubLink); if (securityQuals != NIL) { diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f6b2988e6..b24f80ba6 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -303,6 +303,7 @@ typedef struct RelationData { /* used only for datavec pq */ char *pqTable; float *pqDistanceTable; + bool rd_optionsValid; } RelationData; /* diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h index 847348ac3..cf39c5750 100644 --- a/src/include/utils/relcache.h +++ b/src/include/utils/relcache.h @@ -170,4 +170,5 @@ extern HeapTuple ScanPgRelation(Oid targetRelId, bool indexOK, bool force_non_hi */ extern Relation tuple_get_rel(HeapTuple pg_class_tuple, LOCKMODE lockmode, TupleDesc tuple_desc, HeapTuple pg_indextuple = NULL); extern THR_LOCAL bool needNewLocalCacheFile; +extern void RelationReloadRdOption(Relation relation); #endif /* RELCACHE_H */