修复rowlevelsecurity用例不稳定问题

This commit is contained in:
chenxiaobin19
2025-03-19 16:44:23 +08:00
parent cdd8cdeae2
commit b032bd3ce3
5 changed files with 29 additions and 1 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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) {

View File

@ -303,6 +303,7 @@ typedef struct RelationData {
/* used only for datavec pq */
char *pqTable;
float *pqDistanceTable;
bool rd_optionsValid;
} RelationData;
/*

View File

@ -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 */