]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add note about CreateStatistics()'s selective use of check_rights.
authorNathan Bossart <nathan@postgresql.org>
Fri, 14 Nov 2025 19:20:09 +0000 (13:20 -0600)
committerNathan Bossart <nathan@postgresql.org>
Fri, 14 Nov 2025 19:20:09 +0000 (13:20 -0600)
Commit 5e4fcbe531 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

src/backend/commands/statscmds.c

index b06758f5e857e4b75d6f9d342ed17c599270cd6d..38c76feb5c77baea9f4b3b4b4a0958bcec841967 100644 (file)
@@ -139,7 +139,13 @@ CreateStatistics(CreateStatsStmt *stmt, bool check_rights)
                                         errmsg("relation \"%s\" is not a table, foreign table, or materialized view",
                                                        RelationGetRelationName(rel))));
 
-               /* You must own the relation to create stats on it */
+               /*
+                * You must own the relation to create stats on it.
+                *
+                * NB: Concurrent changes could cause this function's lookup to find a
+                * different relation than a previous lookup by the caller, so we must
+                * perform this check even when check_rights == false.
+                */
                if (!pg_class_ownercheck(RelationGetRelid(rel), stxowner))
                        aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(rel->rd_rel->relkind),
                                                   RelationGetRelationName(rel));