postgres.git / summary / log / commit / refs

commit    414e1ece9d71cece76fcab0abca6816605cb7db5
Author:   Nathan Bossart <nathan@postgresql.org>
Date:     Fri Nov 14 19:20:09 2025 +0000
First released in: 14.21, 15.16, 16.12, 17.8, 18.2

    Add note about CreateStatistics()'s selective use of check_rights.
    
    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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c index f2546c9bf08..78b000a24d3 100644 --- a/src/backend/commands/statscmds.c +++ b/src/backend/commands/statscmds.c @@ -137,7 +137,13 @@ CreateStatistics(CreateStatsStmt *stmt, bool check_rights) RelationGetRelationName(rel)), errdetail_relkind_not_supported(rel->rd_rel->relkind))); - /* 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 (!object_ownercheck(RelationRelationId, RelationGetRelid(rel), stxowner)) aclcheck_error(ACLCHECK_NOT_OWNER, get_relkind_objtype(rel->rd_rel->relkind), RelationGetRelationName(rel)); [parent: 8d43607cd422]