Commit fabde52f authored by Michael Paquier's avatar Michael Paquier

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
parent bd1b8d0e
...@@ -525,8 +525,7 @@ static ObjectAddress ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKM ...@@ -525,8 +525,7 @@ static ObjectAddress ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKM
static void ATExecDropOf(Relation rel, LOCKMODE lockmode); static void ATExecDropOf(Relation rel, LOCKMODE lockmode);
static void ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode); static void ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode);
static void ATExecGenericOptions(Relation rel, List *options); static void ATExecGenericOptions(Relation rel, List *options);
static void ATExecEnableRowSecurity(Relation rel); static void ATExecSetRowSecurity(Relation rel, bool rls);
static void ATExecDisableRowSecurity(Relation rel);
static void ATExecForceNoForceRowSecurity(Relation rel, bool force_rls); static void ATExecForceNoForceRowSecurity(Relation rel, bool force_rls);
static void index_copy_data(Relation rel, RelFileNode newrnode); static void index_copy_data(Relation rel, RelFileNode newrnode);
...@@ -4823,10 +4822,10 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, ...@@ -4823,10 +4822,10 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
ATExecReplicaIdentity(rel, (ReplicaIdentityStmt *) cmd->def, lockmode); ATExecReplicaIdentity(rel, (ReplicaIdentityStmt *) cmd->def, lockmode);
break; break;
case AT_EnableRowSecurity: case AT_EnableRowSecurity:
ATExecEnableRowSecurity(rel); ATExecSetRowSecurity(rel, true);
break; break;
case AT_DisableRowSecurity: case AT_DisableRowSecurity:
ATExecDisableRowSecurity(rel); ATExecSetRowSecurity(rel, false);
break; break;
case AT_ForceRowSecurity: case AT_ForceRowSecurity:
ATExecForceNoForceRowSecurity(rel, true); ATExecForceNoForceRowSecurity(rel, true);
...@@ -14813,30 +14812,7 @@ ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode ...@@ -14813,30 +14812,7 @@ ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode
* ALTER TABLE ENABLE/DISABLE ROW LEVEL SECURITY * ALTER TABLE ENABLE/DISABLE ROW LEVEL SECURITY
*/ */
static void static void
ATExecEnableRowSecurity(Relation rel) ATExecSetRowSecurity(Relation rel, bool rls)
{
Relation pg_class;
Oid relid;
HeapTuple tuple;
relid = RelationGetRelid(rel);
pg_class = table_open(RelationRelationId, RowExclusiveLock);
tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relid));
if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for relation %u", relid);
((Form_pg_class) GETSTRUCT(tuple))->relrowsecurity = true;
CatalogTupleUpdate(pg_class, &tuple->t_self, tuple);
table_close(pg_class, RowExclusiveLock);
heap_freetuple(tuple);
}
static void
ATExecDisableRowSecurity(Relation rel)
{ {
Relation pg_class; Relation pg_class;
Oid relid; Oid relid;
...@@ -14852,7 +14828,7 @@ ATExecDisableRowSecurity(Relation rel) ...@@ -14852,7 +14828,7 @@ ATExecDisableRowSecurity(Relation rel)
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "cache lookup failed for relation %u", relid); elog(ERROR, "cache lookup failed for relation %u", relid);
((Form_pg_class) GETSTRUCT(tuple))->relrowsecurity = false; ((Form_pg_class) GETSTRUCT(tuple))->relrowsecurity = rls;
CatalogTupleUpdate(pg_class, &tuple->t_self, tuple); CatalogTupleUpdate(pg_class, &tuple->t_self, tuple);
table_close(pg_class, RowExclusiveLock); table_close(pg_class, RowExclusiveLock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment