@@ -262,9 +262,7 @@ struct DropRelationCallbackState
262
262
#define ATT_COMPOSITE_TYPE 0x0010
263
263
#define ATT_FOREIGN_TABLE 0x0020
264
264
265
- static void truncate_check_rel (Oid relid , Form_pg_class reltuple );
266
- static void truncate_check_perms (Oid relid , Form_pg_class reltuple );
267
- static void truncate_check_activity (Relation rel );
265
+ static void truncate_check_rel (Relation rel );
268
266
static List * MergeAttributes (List * schema , List * supers , char relpersistence ,
269
267
List * * supOids , List * * supconstr , int * supOidCount );
270
268
static bool MergeCheckConstraint (List * constraints , char * name , Node * expr );
@@ -1020,11 +1018,7 @@ ExecuteTruncate(TruncateStmt *stmt)
1020
1018
heap_close (rel , lockmode );
1021
1019
continue ;
1022
1020
}
1023
-
1024
- truncate_check_rel (myrelid , rel -> rd_rel );
1025
- truncate_check_perms (myrelid , rel -> rd_rel );
1026
- truncate_check_activity (rel );
1027
-
1021
+ truncate_check_rel (rel );
1028
1022
rels = lappend (rels , rel );
1029
1023
relids = lappend_oid (relids , myrelid );
1030
1024
@@ -1060,15 +1054,7 @@ ExecuteTruncate(TruncateStmt *stmt)
1060
1054
continue ;
1061
1055
}
1062
1056
1063
- /*
1064
- * Inherited TRUNCATE commands perform access
1065
- * permission checks on the parent table only.
1066
- * So we skip checking the children's permissions
1067
- * and don't call truncate_check_perms() here.
1068
- */
1069
- truncate_check_rel (RelationGetRelid (rel ), rel -> rd_rel );
1070
- truncate_check_activity (rel );
1071
-
1057
+ truncate_check_rel (rel );
1072
1058
rels = lappend (rels , rel );
1073
1059
relids = lappend_oid (relids , childrelid );
1074
1060
}
@@ -1102,9 +1088,7 @@ ExecuteTruncate(TruncateStmt *stmt)
1102
1088
ereport (NOTICE ,
1103
1089
(errmsg ("truncate cascades to table \"%s\"" ,
1104
1090
RelationGetRelationName (rel ))));
1105
- truncate_check_rel (relid , rel -> rd_rel );
1106
- truncate_check_perms (relid , rel -> rd_rel );
1107
- truncate_check_activity (rel );
1091
+ truncate_check_rel (rel );
1108
1092
rels = lappend (rels , rel );
1109
1093
relids = lappend_oid (relids , relid );
1110
1094
}
@@ -1305,45 +1289,30 @@ ExecuteTruncate(TruncateStmt *stmt)
1305
1289
* Check that a given rel is safe to truncate. Subroutine for ExecuteTruncate
1306
1290
*/
1307
1291
static void
1308
- truncate_check_rel (Oid relid , Form_pg_class reltuple )
1292
+ truncate_check_rel (Relation rel )
1309
1293
{
1310
- char * relname = NameStr ( reltuple -> relname ) ;
1294
+ AclResult aclresult ;
1311
1295
1312
1296
/* Only allow truncate on regular tables */
1313
- if (reltuple -> relkind != RELKIND_RELATION )
1297
+ if (rel -> rd_rel -> relkind != RELKIND_RELATION )
1314
1298
ereport (ERROR ,
1315
1299
(errcode (ERRCODE_WRONG_OBJECT_TYPE ),
1316
- errmsg ("\"%s\" is not a table" , relname )));
1300
+ errmsg ("\"%s\" is not a table" ,
1301
+ RelationGetRelationName (rel ))));
1317
1302
1318
- if (!allowSystemTableMods && IsSystemClass (relid , reltuple ))
1303
+ /* Permissions checks */
1304
+ aclresult = pg_class_aclcheck (RelationGetRelid (rel ), GetUserId (),
1305
+ ACL_TRUNCATE );
1306
+ if (aclresult != ACLCHECK_OK )
1307
+ aclcheck_error (aclresult , ACL_KIND_CLASS ,
1308
+ RelationGetRelationName (rel ));
1309
+
1310
+ if (!allowSystemTableMods && IsSystemRelation (rel ))
1319
1311
ereport (ERROR ,
1320
1312
(errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
1321
1313
errmsg ("permission denied: \"%s\" is a system catalog" ,
1322
- relname )));
1323
- }
1324
-
1325
- /*
1326
- * Check that current user has the permission to truncate given relation.
1327
- */
1328
- static void
1329
- truncate_check_perms (Oid relid , Form_pg_class reltuple )
1330
- {
1331
- char * relname = NameStr (reltuple -> relname );
1332
- AclResult aclresult ;
1333
-
1334
- /* Permissions checks */
1335
- aclresult = pg_class_aclcheck (relid , GetUserId (), ACL_TRUNCATE );
1336
- if (aclresult != ACLCHECK_OK )
1337
- aclcheck_error (aclresult , ACL_KIND_CLASS , relname );
1338
- }
1314
+ RelationGetRelationName (rel ))));
1339
1315
1340
- /*
1341
- * Set of extra sanity checks to check if a given relation is safe to
1342
- * truncate.
1343
- */
1344
- static void
1345
- truncate_check_activity (Relation rel )
1346
- {
1347
1316
/*
1348
1317
* Don't allow truncate on temp tables of other backends ... their local
1349
1318
* buffer manager is not going to cope.
0 commit comments