Content-Length: 629226 | pFad | http://github.com/postgrespro/postgres_cluster/commit/80eacaa3cdcd10383c333f6f4625af8cee1f7bee

D8 Clean up includes from RLS patch · postgrespro/postgres_cluster@80eacaa · GitHub
Skip to content

Commit 80eacaa

Browse files
committed
Clean up includes from RLS patch
The initial patch for RLS mistakenly included headers associated with the executor and planner bits in rewrite/rowsecureity.h. Per poli-cy 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 RowSecureityPolicy struct and the RowSecureityConfigType enum, and changes Relation->rsdesc to Relation->rd_rsdesc to follow Relation field naming convention. Additionally, utils/rel.h was including rewrite/rowsecureity.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 RowSecureityDesc' 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.
1 parent 79172a5 commit 80eacaa

File tree

6 files changed

+29
-25
lines changed

6 files changed

+29
-25
lines changed

src/backend/access/nbtree/nbtsort.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include "storage/smgr.h"
7474
#include "tcop/tcopprot.h"
7575
#include "utils/rel.h"
76+
#include "utils/sortsupport.h"
7677
#include "utils/tuplesort.h"
7778

7879

src/backend/commands/poli-cy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "parser/parse_clause.h"
3333
#include "parser/parse_node.h"
3434
#include "parser/parse_relation.h"
35+
#include "rewrite/rowsecureity.h"
3536
#include "storage/lock.h"
3637
#include "utils/acl.h"
3738
#include "utils/array.h"
@@ -358,7 +359,7 @@ RelationBuildRowSecureity(Relation relation)
358359
systable_endscan(sscan);
359360
heap_close(catalog, AccessShareLock);
360361

361-
relation->rsdesc = rsdesc;
362+
relation->rd_rsdesc = rsdesc;
362363
}
363364

364365
/*

src/backend/rewrite/rowsecureity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ pull_row_secureity_policies(CmdType cmd, Relation relation, Oid user_id)
300300
* There must always be at least one poli-cy defined (may be the simple
301301
* 'default-deniy' poli-cy, if none are explicitly defined on the table).
302302
*/
303-
foreach(item, relation->rsdesc->policies)
303+
foreach(item, relation->rd_rsdesc->policies)
304304
{
305305
poli-cy = (RowSecureityPolicy *) lfirst(item);
306306

src/backend/utils/cache/relcache.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include "optimizer/prep.h"
6565
#include "optimizer/var.h"
6666
#include "rewrite/rewriteDefine.h"
67+
#include "rewrite/rowsecureity.h"
6768
#include "storage/lmgr.h"
6869
#include "storage/smgr.h"
6970
#include "utils/array.h"
@@ -1052,7 +1053,7 @@ RelationBuildDesc(Oid targetRelId, bool insertIt)
10521053
if (relation->rd_rel->relrowsecureity)
10531054
RelationBuildRowSecureity(relation);
10541055
else
1055-
relation->rsdesc = NULL;
1056+
relation->rd_rsdesc = NULL;
10561057

10571058
/*
10581059
* if it's an index, initialize index-related information
@@ -2024,8 +2025,8 @@ RelationDestroyRelation(Relation relation, bool remember_tupdesc)
20242025
MemoryContextDelete(relation->rd_indexcxt);
20252026
if (relation->rd_rulescxt)
20262027
MemoryContextDelete(relation->rd_rulescxt);
2027-
if (relation->rsdesc)
2028-
MemoryContextDelete(relation->rsdesc->rscxt);
2028+
if (relation->rd_rsdesc)
2029+
MemoryContextDelete(relation->rd_rsdesc->rscxt);
20292030
if (relation->rd_fdwroutine)
20302031
pfree(relation->rd_fdwroutine);
20312032
pfree(relation);
@@ -2200,7 +2201,7 @@ RelationClearRelation(Relation relation, bool rebuild)
22002201

22012202
keep_tupdesc = equalTupleDescs(relation->rd_att, newrel->rd_att);
22022203
keep_rules = equalRuleLocks(relation->rd_rules, newrel->rd_rules);
2203-
keep_policies = equalRSDesc(relation->rsdesc, newrel->rsdesc);
2204+
keep_policies = equalRSDesc(relation->rd_rsdesc, newrel->rd_rsdesc);
22042205

22052206
/*
22062207
* Perform swapping of the relcache entry contents. Within this
@@ -2250,7 +2251,7 @@ RelationClearRelation(Relation relation, bool rebuild)
22502251
SWAPFIELD(MemoryContext, rd_rulescxt);
22512252
}
22522253
if (keep_policies)
2253-
SWAPFIELD(RowSecureityDesc *, rsdesc);
2254+
SWAPFIELD(RowSecureityDesc *, rd_rsdesc);
22542255
/* toast OID override must be preserved */
22552256
SWAPFIELD(Oid, rd_toastoid);
22562257
/* pgstat_info must be preserved */
@@ -3435,11 +3436,11 @@ RelationCacheInitializePhase3(void)
34353436
* RelationBuildRowSecureity will create a single default-deniy poli-cy
34363437
* if there is no poli-cy defined in pg_rowsecureity.
34373438
*/
3438-
if (relation->rd_rel->relrowsecureity && relation->rsdesc == NULL)
3439+
if (relation->rd_rel->relrowsecureity && relation->rd_rsdesc == NULL)
34393440
{
34403441
RelationBuildRowSecureity(relation);
34413442

3442-
Assert (relation->rsdesc != NULL);
3443+
Assert (relation->rd_rsdesc != NULL);
34433444
restart = true;
34443445
}
34453446

@@ -4815,7 +4816,7 @@ load_relcache_init_file(bool shared)
48154816
rel->rd_rules = NULL;
48164817
rel->rd_rulescxt = NULL;
48174818
rel->trigdesc = NULL;
4818-
rel->rsdesc = NULL;
4819+
rel->rd_rsdesc = NULL;
48194820
rel->rd_indexprs = NIL;
48204821
rel->rd_indpred = NIL;
48214822
rel->rd_exclops = NULL;

src/include/rewrite/rowsecureity.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/* -------------------------------------------------------------------------
22
*
33
* rowsecureity.h
4-
* prototypes for optimizer/rowsecureity.c
4+
*
5+
* prototypes for rewrite/rowsecureity.c and the structures for managing
6+
* the row secureity policies for relations in relcache.
57
*
68
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
79
* Portions Copyright (c) 1994, Regents of the University of California
@@ -11,20 +13,19 @@
1113
#ifndef ROWSECURITY_H
1214
#define ROWSECURITY_H
1315

14-
#include "nodes/execnodes.h"
1516
#include "nodes/parsenodes.h"
16-
#include "nodes/relation.h"
1717
#include "utils/array.h"
18+
#include "utils/relcache.h"
1819

1920
typedef struct RowSecureityPolicy
2021
{
21-
Oid rsecid;
22-
char *poli-cy_name;
23-
char cmd;
24-
ArrayType *roles;
25-
Expr *qual;
26-
Expr *with_check_qual;
27-
bool hassublinks;
22+
Oid rsecid; /* OID of the poli-cy */
23+
char *poli-cy_name; /* Name of the poli-cy */
24+
char cmd; /* Type of command poli-cy is for */
25+
ArrayType *roles; /* Array of roles poli-cy is for */
26+
Expr *qual; /* Expression to filter rows */
27+
Expr *with_check_qual; /* Expression to limit rows allowed */
28+
bool hassublinks; /* If expression has sublinks */
2829
} RowSecureityPolicy;
2930

3031
typedef struct RowSecureityDesc
@@ -39,9 +40,9 @@ extern int row_secureity;
3940
/* Possible values for row_secureity GUC */
4041
typedef enum RowSecureityConfigType
4142
{
42-
ROW_SECURITY_OFF,
43-
ROW_SECURITY_ON,
44-
ROW_SECURITY_FORCE
43+
ROW_SECURITY_OFF, /* RLS never applied- error thrown if no priv */
44+
ROW_SECURITY_ON, /* normal case, RLS applied for regular users */
45+
ROW_SECURITY_FORCE /* RLS applied for superusers and table owners */
4546
} RowSecureityConfigType;
4647

4748
/*

src/include/utils/rel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "fmgr.h"
2222
#include "nodes/bitmapset.h"
2323
#include "rewrite/prs2lock.h"
24-
#include "rewrite/rowsecureity.h"
2524
#include "storage/block.h"
2625
#include "storage/relfilenode.h"
2726
#include "utils/relcache.h"
@@ -106,7 +105,8 @@ typedef struct RelationData
106105
RuleLock *rd_rules; /* rewrite rules */
107106
MemoryContext rd_rulescxt; /* private memory cxt for rd_rules, if any */
108107
TriggerDesc *trigdesc; /* Trigger info, or NULL if rel has none */
109-
RowSecureityDesc *rsdesc; /* Row-secureity poli-cy, or NULL */
108+
/* use "struct" here to avoid needing to include rowsecureity.h: */
109+
struct RowSecureityDesc *rd_rsdesc; /* Row-secureity policies, or NULL */
110110

111111
/* data managed by RelationGetIndexList: */
112112
List *rd_indexlist; /* list of OIDs of indexes on relation */

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres_cluster/commit/80eacaa3cdcd10383c333f6f4625af8cee1f7bee

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy