Skip to content

Commit 414e1ec

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 8d43607 commit 414e1ec

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
@@ -137,7 +137,13 @@ CreateStatistics(CreateStatsStmt *stmt, bool check_rights)
137137
RelationGetRelationName(rel)),
138138
errdetail_relkind_not_supported(rel->rd_rel->relkind)));
139139

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

0 commit comments

Comments
 (0)