Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfabde52

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 LEVELSECURITY with an ALTER TABLE command. This makes the code slightlycleaner.Author: Justin PryzbyReviewed-by: Zhihong YuDiscussion:https://postgr.es/m/20210228211854.GC20769@telsasoft.com
1 parentbd1b8d0 commitfabde52

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 5 additions & 29 deletions
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-
Relationpg_class;
14819-
Oidrelid;
14820-
HeapTupletuple;
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
Relationpg_class;
1484214818
Oidrelid;
@@ -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)

[8]ページ先頭

©2009-2025 Movatter.jp