Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fabde52

Browse files
committed
Simplify code to switch pg_class.relrowsecurity in tablecmds.c
The same code pattern was repeated twice to enable or disable ROW LEVEL SECURITY with an ALTER TABLE command. This makes the code slightly cleaner. Author: Justin Pryzby Reviewed-by: Zhihong Yu Discussion: https://postgr.es/m/20210228211854.GC20769@telsasoft.com
1 parent bd1b8d0 commit fabde52

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

src/backend/commands/tablecmds.c

+5-29
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,7 @@ static ObjectAddress ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKM
525525
static void ATExecDropOf(Relation rel, LOCKMODE lockmode);
526526
static void ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode);
527527
static void ATExecGenericOptions(Relation rel, List *options);
528-
static void ATExecEnableRowSecurity(Relation rel);
529-
static void ATExecDisableRowSecurity(Relation rel);
528+
static void ATExecSetRowSecurity(Relation rel, bool rls);
530529
static void ATExecForceNoForceRowSecurity(Relation rel, bool force_rls);
531530

532531
static void index_copy_data(Relation rel, RelFileNode newrnode);
@@ -4823,10 +4822,10 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
48234822
ATExecReplicaIdentity(rel, (ReplicaIdentityStmt *) cmd->def, lockmode);
48244823
break;
48254824
case AT_EnableRowSecurity:
4826-
ATExecEnableRowSecurity(rel);
4825+
ATExecSetRowSecurity(rel, true);
48274826
break;
48284827
case AT_DisableRowSecurity:
4829-
ATExecDisableRowSecurity(rel);
4828+
ATExecSetRowSecurity(rel, false);
48304829
break;
48314830
case AT_ForceRowSecurity:
48324831
ATExecForceNoForceRowSecurity(rel, true);
@@ -14813,30 +14812,7 @@ ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode
1481314812
* ALTER TABLE ENABLE/DISABLE ROW LEVEL SECURITY
1481414813
*/
1481514814
static void
14816-
ATExecEnableRowSecurity(Relation rel)
14817-
{
14818-
Relation pg_class;
14819-
Oid relid;
14820-
HeapTuple tuple;
14821-
14822-
relid = RelationGetRelid(rel);
14823-
14824-
pg_class = table_open(RelationRelationId, RowExclusiveLock);
14825-
14826-
tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relid));
14827-
14828-
if (!HeapTupleIsValid(tuple))
14829-
elog(ERROR, "cache lookup failed for relation %u", relid);
14830-
14831-
((Form_pg_class) GETSTRUCT(tuple))->relrowsecurity = true;
14832-
CatalogTupleUpdate(pg_class, &tuple->t_self, tuple);
14833-
14834-
table_close(pg_class, RowExclusiveLock);
14835-
heap_freetuple(tuple);
14836-
}
14837-
14838-
static void
14839-
ATExecDisableRowSecurity(Relation rel)
14815+
ATExecSetRowSecurity(Relation rel, bool rls)
1484014816
{
1484114817
Relation pg_class;
1484214818
Oid relid;
@@ -14852,7 +14828,7 @@ ATExecDisableRowSecurity(Relation rel)
1485214828
if (!HeapTupleIsValid(tuple))
1485314829
elog(ERROR, "cache lookup failed for relation %u", relid);
1485414830

14855-
((Form_pg_class) GETSTRUCT(tuple))->relrowsecurity = false;
14831+
((Form_pg_class) GETSTRUCT(tuple))->relrowsecurity = rls;
1485614832
CatalogTupleUpdate(pg_class, &tuple->t_self, tuple);
1485714833

1485814834
table_close(pg_class, RowExclusiveLock);

0 commit comments

Comments
 (0)