From 49baf8d642382fa073a887050e409c9e2b3e55f8 Mon Sep 17 00:00:00 2001 From: chenxiaobin19 <1025221611@qq.com> Date: Wed, 19 Mar 2025 16:44:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drowlevelsecurity=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E4=B8=8D=E7=A8=B3=E5=AE=9A=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/cache/knl_globaltabdefcache.cpp | 4 +++- src/common/backend/utils/cache/relcache.cpp | 19 +++++++++++++++++++ .../optimizer/rewrite/rewriteHandler.cpp | 5 +++++ src/include/utils/rel.h | 1 + src/include/utils/relcache.h | 1 + src/test/regress/parallel_schedule0B | 2 +- 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/common/backend/utils/cache/knl_globaltabdefcache.cpp b/src/common/backend/utils/cache/knl_globaltabdefcache.cpp index 16996d6475..15e8d20d8c 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 a82d4f9c88..e0adb3db98 100755 --- a/src/common/backend/utils/cache/relcache.cpp +++ b/src/common/backend/utils/cache/relcache.cpp @@ -3896,6 +3896,7 @@ void RelationClearRelation(Relation relation, bool rebuild) relation->rd_indexlist = NIL; relation->rd_oidindex = InvalidOid; relation->rd_indexvalid = 0; + relation->rd_optionsValid = false; return; } @@ -7934,6 +7935,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 @@ -9026,3 +9028,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 fe0afede70..ea511cff23 100644 --- a/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp +++ b/src/gausskernel/optimizer/rewrite/rewriteHandler.cpp @@ -2412,6 +2412,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 6c4b26a90c..c6429eb68a 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -304,6 +304,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 847348ac36..cf39c57505 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 */ diff --git a/src/test/regress/parallel_schedule0B b/src/test/regress/parallel_schedule0B index aa049008eb..6bbd9ea9df 100644 --- a/src/test/regress/parallel_schedule0B +++ b/src/test/regress/parallel_schedule0B @@ -5,7 +5,7 @@ # usecases for improving coverage # -------------------------- test: vec_hashjoin1 single_node_rangetypes db4ai_explain_model test_ustore_toast ustore_ddl ts_utf8 test_ustore_update test_ustore_index -test: sqlldr/gs_loader_basic psql parse_xlog cgin_test create_index_gist hw_user query_self_tuning hw_partition_llt +test: sqlldr/gs_loader_basic psql parse_xlog cgin_test create_index_gist hw_user rowlevelsecurity query_self_tuning hw_partition_llt test: physical_slot -- Gitee