@@ -300,9 +300,7 @@ struct DropRelationCallbackState
300300#define child_dependency_type (child_is_partition )\
301301((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
302302
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 );
306304static List * MergeAttributes (List * schema ,List * supers ,char relpersistence ,
307305bool is_partition ,List * * supOids ,List * * supconstr ,
308306int * supOidCount );
@@ -1383,11 +1381,7 @@ ExecuteTruncate(TruncateStmt *stmt)
13831381heap_close (rel ,lockmode );
13841382continue ;
13851383}
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 );
13911385rels = lappend (rels ,rel );
13921386relids = lappend_oid (relids ,myrelid );
13931387/* Log this relation only if needed for logical decoding */
@@ -1426,15 +1420,7 @@ ExecuteTruncate(TruncateStmt *stmt)
14261420continue ;
14271421}
14281422
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 );
14381424rels = lappend (rels ,rel );
14391425relids = lappend_oid (relids ,childrelid );
14401426/* Log this relation only if needed for logical decoding */
@@ -1517,9 +1503,7 @@ ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged,
15171503ereport (NOTICE ,
15181504(errmsg ("truncate cascades to table \"%s\"" ,
15191505RelationGetRelationName (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 );
15231507rels = lappend (rels ,rel );
15241508relids = lappend_oid (relids ,relid );
15251509/* Log this relation only if needed for logical decoding */
@@ -1775,51 +1759,35 @@ ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged,
17751759 * Check that a given rel is safe to truncate. Subroutine for ExecuteTruncate
17761760 */
17771761static void
1778- truncate_check_rel (Oid relid , Form_pg_class reltuple )
1762+ truncate_check_rel (Relation rel )
17791763{
1780- char * relname = NameStr ( reltuple -> relname ) ;
1764+ AclResult aclresult ;
17811765
17821766/*
17831767 * Only allow truncate on regular tables and partitioned tables (although,
17841768 * the latter are only being included here for the following checks; no
17851769 * physical truncation will occur in their case.)
17861770 */
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 )
17891773ereport (ERROR ,
17901774(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 ));
17921784
1793- if (!allowSystemTableMods && IsSystemClass ( relid , reltuple ))
1785+ if (!allowSystemTableMods && IsSystemRelation ( rel ))
17941786ereport (ERROR ,
17951787(errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
17961788errmsg ("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 ))));
18151790
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- {
18231791/*
18241792 * Don't allow truncate on temp tables of other backends ... their local
18251793 * buffer manager is not going to cope.