@@ -302,7 +302,6 @@ struct DropRelationCallbackState
302
302
((child_is_partition) ? DEPENDENCY_AUTO : DEPENDENCY_NORMAL)
303
303
304
304
static void truncate_check_rel(Oid relid, Form_pg_class reltuple);
305
- static void truncate_check_perms(Oid relid, Form_pg_class reltuple);
306
305
static void truncate_check_activity(Relation rel);
307
306
static void RangeVarCallbackForTruncate(const RangeVar *relation,
308
307
Oid relId, Oid oldRelId, void *arg);
@@ -1591,12 +1590,6 @@ ExecuteTruncate(TruncateStmt *stmt)
1591
1590
continue;
1592
1591
}
1593
1592
1594
- /*
1595
- * Inherited TRUNCATE commands perform access
1596
- * permission checks on the parent table only.
1597
- * So we skip checking the children's permissions
1598
- * and don't call truncate_check_perms() here.
1599
- */
1600
1593
truncate_check_rel(RelationGetRelid(rel), rel->rd_rel);
1601
1594
truncate_check_activity(rel);
1602
1595
@@ -1683,7 +1676,6 @@ ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged,
1683
1676
(errmsg("truncate cascades to table \"%s\"",
1684
1677
RelationGetRelationName(rel))));
1685
1678
truncate_check_rel(relid, rel->rd_rel);
1686
- truncate_check_perms(relid, rel->rd_rel);
1687
1679
truncate_check_activity(rel);
1688
1680
rels = lappend(rels, rel);
1689
1681
relids = lappend_oid(relids, relid);
@@ -1934,6 +1926,7 @@ ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged,
1934
1926
static void
1935
1927
truncate_check_rel(Oid relid, Form_pg_class reltuple)
1936
1928
{
1929
+ AclResult aclresult;
1937
1930
char *relname = NameStr(reltuple->relname);
1938
1931
1939
1932
/*
@@ -1947,27 +1940,17 @@ truncate_check_rel(Oid relid, Form_pg_class reltuple)
1947
1940
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
1948
1941
errmsg("\"%s\" is not a table", relname)));
1949
1942
1950
- if (!allowSystemTableMods && IsSystemClass(relid, reltuple))
1951
- ereport(ERROR,
1952
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1953
- errmsg("permission denied: \"%s\" is a system catalog",
1954
- relname)));
1955
- }
1956
-
1957
- /*
1958
- * Check that current user has the permission to truncate given relation.
1959
- */
1960
- static void
1961
- truncate_check_perms(Oid relid, Form_pg_class reltuple)
1962
- {
1963
- char *relname = NameStr(reltuple->relname);
1964
- AclResult aclresult;
1965
-
1966
1943
/* Permissions checks */
1967
1944
aclresult = pg_class_aclcheck(relid, GetUserId(), ACL_TRUNCATE);
1968
1945
if (aclresult != ACLCHECK_OK)
1969
1946
aclcheck_error(aclresult, get_relkind_objtype(reltuple->relkind),
1970
1947
relname);
1948
+
1949
+ if (!allowSystemTableMods && IsSystemClass(relid, reltuple))
1950
+ ereport(ERROR,
1951
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1952
+ errmsg("permission denied: \"%s\" is a system catalog",
1953
+ relname)));
1971
1954
}
1972
1955
1973
1956
/*
@@ -14903,7 +14886,6 @@ RangeVarCallbackForTruncate(const RangeVar *relation,
14903
14886
elog(ERROR, "cache lookup failed for relation %u", relId);
14904
14887
14905
14888
truncate_check_rel(relId, (Form_pg_class) GETSTRUCT(tuple));
14906
- truncate_check_perms(relId, (Form_pg_class) GETSTRUCT(tuple));
14907
14889
14908
14890
ReleaseSysCache(tuple);
14909
14891
}
0 commit comments