Skip to content

Commit 4c179cc

Browse files
Add note about CreateStatistics()'s selective use of check_rights.
Commit 5e4fcbe added a check_rights parameter to this function for use by ALTER TABLE commands that re-create statistics objects. However, we intentionally ignore check_rights when verifying relation ownership because this function's lookup could return a different answer than the caller's. This commit adds a note to this effect so that we remember it down the road. Reviewed-by: Noah Misch <noah@leadboat.com> Backpatch-through: 14
1 parent 7aa83ea commit 4c179cc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/backend/commands/statscmds.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ CreateStatistics(CreateStatsStmt *stmt, bool check_rights)
139139
errmsg("relation \"%s\" is not a table, foreign table, or materialized view",
140140
RelationGetRelationName(rel))));
141141

142-
/* You must own the relation to create stats on it */
142+
/*
143+
* You must own the relation to create stats on it.
144+
*
145+
* NB: Concurrent changes could cause this function's lookup to find a
146+
* different relation than a previous lookup by the caller, so we must
147+
* perform this check even when check_rights == false.
148+
*/
143149
if (!pg_class_ownercheck(RelationGetRelid(rel), stxowner))
144150
aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(rel->rd_rel->relkind),
145151
RelationGetRelationName(rel));

0 commit comments

Comments
 (0)