From 80eacaa3cdcd10383c333f6f4625af8cee1f7bee Mon Sep 17 00:00:00 2001 From: Stephen Frost Date: Fri, 14 Nov 2014 16:53:51 -0500 Subject: Clean up includes from RLS patch The initial patch for RLS mistakenly included headers associated with the executor and planner bits in rewrite/rowsecurity.h. Per policy and general good sense, executor headers should not be included in planner headers or vice versa. The include of execnodes.h was a mistaken holdover from previous versions, while the include of relation.h was used for Relation's definition, which should have been coming from utils/relcache.h. This patch cleans these issues up, adds comments to the RowSecurityPolicy struct and the RowSecurityConfigType enum, and changes Relation->rsdesc to Relation->rd_rsdesc to follow Relation field naming convention. Additionally, utils/rel.h was including rewrite/rowsecurity.h, which wasn't a great idea since that was pulling in things not really needed in utils/rel.h (which gets included in quite a few places). Instead, use 'struct RowSecurityDesc' for the rd_rsdesc field and add comments explaining why. Lastly, add an include into access/nbtree/nbtsort.c for utils/sortsupport.h, which was evidently missed due to the above mess. Pointed out by Tom in 16970.1415838651@sss.pgh.pa.us; note that the concerns regarding a similar situation in the custom-path commit still need to be addressed. --- src/backend/utils/cache/relcache.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/backend/utils/cache/relcache.c') diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index e8ed9995ff6..4b4528f7917 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -64,6 +64,7 @@ #include "optimizer/prep.h" #include "optimizer/var.h" #include "rewrite/rewriteDefine.h" +#include "rewrite/rowsecurity.h" #include "storage/lmgr.h" #include "storage/smgr.h" #include "utils/array.h" @@ -1052,7 +1053,7 @@ RelationBuildDesc(Oid targetRelId, bool insertIt) if (relation->rd_rel->relrowsecurity) RelationBuildRowSecurity(relation); else - relation->rsdesc = NULL; + relation->rd_rsdesc = NULL; /* * if it's an index, initialize index-related information @@ -2024,8 +2025,8 @@ RelationDestroyRelation(Relation relation, bool remember_tupdesc) MemoryContextDelete(relation->rd_indexcxt); if (relation->rd_rulescxt) MemoryContextDelete(relation->rd_rulescxt); - if (relation->rsdesc) - MemoryContextDelete(relation->rsdesc->rscxt); + if (relation->rd_rsdesc) + MemoryContextDelete(relation->rd_rsdesc->rscxt); if (relation->rd_fdwroutine) pfree(relation->rd_fdwroutine); pfree(relation); @@ -2200,7 +2201,7 @@ RelationClearRelation(Relation relation, bool rebuild) keep_tupdesc = equalTupleDescs(relation->rd_att, newrel->rd_att); keep_rules = equalRuleLocks(relation->rd_rules, newrel->rd_rules); - keep_policies = equalRSDesc(relation->rsdesc, newrel->rsdesc); + keep_policies = equalRSDesc(relation->rd_rsdesc, newrel->rd_rsdesc); /* * Perform swapping of the relcache entry contents. Within this @@ -2250,7 +2251,7 @@ RelationClearRelation(Relation relation, bool rebuild) SWAPFIELD(MemoryContext, rd_rulescxt); } if (keep_policies) - SWAPFIELD(RowSecurityDesc *, rsdesc); + SWAPFIELD(RowSecurityDesc *, rd_rsdesc); /* toast OID override must be preserved */ SWAPFIELD(Oid, rd_toastoid); /* pgstat_info must be preserved */ @@ -3435,11 +3436,11 @@ RelationCacheInitializePhase3(void) * RelationBuildRowSecurity will create a single default-deny policy * if there is no policy defined in pg_rowsecurity. */ - if (relation->rd_rel->relrowsecurity && relation->rsdesc == NULL) + if (relation->rd_rel->relrowsecurity && relation->rd_rsdesc == NULL) { RelationBuildRowSecurity(relation); - Assert (relation->rsdesc != NULL); + Assert (relation->rd_rsdesc != NULL); restart = true; } @@ -4815,7 +4816,7 @@ load_relcache_init_file(bool shared) rel->rd_rules = NULL; rel->rd_rulescxt = NULL; rel->trigdesc = NULL; - rel->rsdesc = NULL; + rel->rd_rsdesc = NULL; rel->rd_indexprs = NIL; rel->rd_indpred = NIL; rel->rd_exclops = NULL; -- cgit v1.2.3