@@ -300,9 +300,7 @@ struct DropRelationCallbackState
300
300
#define child_dependency_type (child_is_partition )\
301
301
((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
302
302
303
- static void truncate_check_rel (Oid relid ,Form_pg_class reltuple );
304
- static void truncate_check_perms (Oid relid ,Form_pg_class reltuple );
305
- static void truncate_check_activity (Relation rel );
303
+ static void truncate_check_rel (Relation rel );
306
304
static List * MergeAttributes (List * schema ,List * supers ,char relpersistence ,
307
305
bool is_partition ,List * * supOids ,List * * supconstr ,
308
306
int * supOidCount );
@@ -1383,11 +1381,7 @@ ExecuteTruncate(TruncateStmt *stmt)
1383
1381
heap_close (rel ,lockmode );
1384
1382
continue ;
1385
1383
}
1386
-
1387
- truncate_check_rel (myrelid ,rel -> rd_rel );
1388
- truncate_check_perms (myrelid ,rel -> rd_rel );
1389
- truncate_check_activity (rel );
1390
-
1384
+ truncate_check_rel (rel );
1391
1385
rels = lappend (rels ,rel );
1392
1386
relids = lappend_oid (relids ,myrelid );
1393
1387
/* Log this relation only if needed for logical decoding */
@@ -1426,15 +1420,7 @@ ExecuteTruncate(TruncateStmt *stmt)
1426
1420
continue ;
1427
1421
}
1428
1422
1429
- /*
1430
- * Inherited TRUNCATE commands perform access
1431
- * permission checks on the parent table only.
1432
- * So we skip checking the children's permissions
1433
- * and don't call truncate_check_perms() here.
1434
- */
1435
- truncate_check_rel (RelationGetRelid (rel ),rel -> rd_rel );
1436
- truncate_check_activity (rel );
1437
-
1423
+ truncate_check_rel (rel );
1438
1424
rels = lappend (rels ,rel );
1439
1425
relids = lappend_oid (relids ,childrelid );
1440
1426
/* Log this relation only if needed for logical decoding */
@@ -1517,9 +1503,7 @@ ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged,
1517
1503
ereport (NOTICE ,
1518
1504
(errmsg ("truncate cascades to table \"%s\"" ,
1519
1505
RelationGetRelationName (rel ))));
1520
- truncate_check_rel (relid ,rel -> rd_rel );
1521
- truncate_check_perms (relid ,rel -> rd_rel );
1522
- truncate_check_activity (rel );
1506
+ truncate_check_rel (rel );
1523
1507
rels = lappend (rels ,rel );
1524
1508
relids = lappend_oid (relids ,relid );
1525
1509
/* Log this relation only if needed for logical decoding */
@@ -1775,51 +1759,35 @@ ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged,
1775
1759
* Check that a given rel is safe to truncate. Subroutine for ExecuteTruncate
1776
1760
*/
1777
1761
static void
1778
- truncate_check_rel (Oid relid , Form_pg_class reltuple )
1762
+ truncate_check_rel (Relation rel )
1779
1763
{
1780
- char * relname = NameStr ( reltuple -> relname ) ;
1764
+ AclResult aclresult ;
1781
1765
1782
1766
/*
1783
1767
* Only allow truncate on regular tables and partitioned tables (although,
1784
1768
* the latter are only being included here for the following checks; no
1785
1769
* physical truncation will occur in their case.)
1786
1770
*/
1787
- if (reltuple -> relkind != RELKIND_RELATION &&
1788
- reltuple -> relkind != RELKIND_PARTITIONED_TABLE )
1771
+ if (rel -> rd_rel -> relkind != RELKIND_RELATION &&
1772
+ rel -> rd_rel -> relkind != RELKIND_PARTITIONED_TABLE )
1789
1773
ereport (ERROR ,
1790
1774
(errcode (ERRCODE_WRONG_OBJECT_TYPE ),
1791
- errmsg ("\"%s\" is not a table" ,relname )));
1775
+ errmsg ("\"%s\" is not a table" ,
1776
+ RelationGetRelationName (rel ))));
1777
+
1778
+ /* Permissions checks */
1779
+ aclresult = pg_class_aclcheck (RelationGetRelid (rel ),GetUserId (),
1780
+ ACL_TRUNCATE );
1781
+ if (aclresult != ACLCHECK_OK )
1782
+ aclcheck_error (aclresult ,get_relkind_objtype (rel -> rd_rel -> relkind ),
1783
+ RelationGetRelationName (rel ));
1792
1784
1793
- if (!allowSystemTableMods && IsSystemClass ( relid , reltuple ))
1785
+ if (!allowSystemTableMods && IsSystemRelation ( rel ))
1794
1786
ereport (ERROR ,
1795
1787
(errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
1796
1788
errmsg ("permission denied: \"%s\" is a system catalog" ,
1797
- relname )));
1798
- }
1799
-
1800
- /*
1801
- * Check that current user has the permission to truncate given relation.
1802
- */
1803
- static void
1804
- truncate_check_perms (Oid relid ,Form_pg_class reltuple )
1805
- {
1806
- char * relname = NameStr (reltuple -> relname );
1807
- AclResult aclresult ;
1808
-
1809
- /* Permissions checks */
1810
- aclresult = pg_class_aclcheck (relid ,GetUserId (),ACL_TRUNCATE );
1811
- if (aclresult != ACLCHECK_OK )
1812
- aclcheck_error (aclresult ,get_relkind_objtype (reltuple -> relkind ),
1813
- relname );
1814
- }
1789
+ RelationGetRelationName (rel ))));
1815
1790
1816
- /*
1817
- * Set of extra sanity checks to check if a given relation is safe to
1818
- * truncate.
1819
- */
1820
- static void
1821
- truncate_check_activity (Relation rel )
1822
- {
1823
1791
/*
1824
1792
* Don't allow truncate on temp tables of other backends ... their local
1825
1793
* buffer manager is not going to cope.