=== Applying patches on top of PostgreSQL commit ID 23792d7381583d04c4bbd0a8507566401ec013d3 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sun Nov 16 21:07:23 UTC 2025 On branch cf/6106 nothing to commit, working tree clean === using 'git am' to apply patch ./v5-0001-Restructure-CreateStatsStmt-parse-analysis-processing.patch === Applying: Restructure CreateStatsStmt parse-analysis processing Using index info to reconstruct a base tree... M src/backend/commands/statscmds.c Falling back to patching base and 3-way merge... Auto-merging src/backend/commands/statscmds.c CONFLICT (content): Merge conflict in src/backend/commands/statscmds.c error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Restructure CreateStatsStmt parse-analysis processing When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". Unstaged changes after reset: M src/backend/commands/statscmds.c M src/backend/commands/tablecmds.c M src/backend/parser/gram.y M src/backend/parser/parse_utilcmd.c M src/backend/tcop/utility.c M src/include/commands/defrem.h M src/include/nodes/parsenodes.h M src/include/parser/parse_utilcmd.h === using patch(1) to apply patch ./v5-0001-Restructure-CreateStatsStmt-parse-analysis-processing.patch === patching file src/backend/commands/statscmds.c Hunk #4 FAILED at 97. 1 out of 4 hunks FAILED -- saving rejects to file src/backend/commands/statscmds.c.rej patching file src/backend/commands/tablecmds.c patching file src/backend/parser/gram.y patching file src/backend/parser/parse_utilcmd.c patching file src/backend/tcop/utility.c patching file src/include/commands/defrem.h patching file src/include/nodes/parsenodes.h patching file src/include/parser/parse_utilcmd.h Unstaged changes after reset: M src/backend/commands/statscmds.c M src/backend/commands/tablecmds.c M src/backend/parser/gram.y M src/backend/parser/parse_utilcmd.c M src/backend/tcop/utility.c M src/include/commands/defrem.h M src/include/nodes/parsenodes.h M src/include/parser/parse_utilcmd.h Removing src/backend/commands/statscmds.c.rej === using 'git apply' to apply patch ./v5-0001-Restructure-CreateStatsStmt-parse-analysis-processing.patch === Applied patch to 'src/backend/commands/statscmds.c' with conflicts. Applied patch to 'src/backend/commands/tablecmds.c' cleanly. Applied patch to 'src/backend/parser/gram.y' cleanly. Applied patch to 'src/backend/parser/parse_utilcmd.c' cleanly. Applied patch to 'src/backend/tcop/utility.c' cleanly. Applied patch to 'src/include/commands/defrem.h' cleanly. Applied patch to 'src/include/nodes/parsenodes.h' cleanly. Applied patch to 'src/include/parser/parse_utilcmd.h' cleanly. U src/backend/commands/statscmds.c diff --cc src/backend/commands/statscmds.c index 77b1a6e2dc5,0e08229de53..00000000000 --- a/src/backend/commands/statscmds.c +++ b/src/backend/commands/statscmds.c @@@ -95,64 -97,23 +97,64 @@@ CreateStatistics(CreateStatsStmt *stmt Assert(IsA(stmt, CreateStatsStmt)); + /* Run parse analysis */ + stmt = transformStatsStmt(stmt, queryString); + + /* XXX internal error is better than Assert? error message need polish */ + if (list_length(stmt->rtable) != list_length(stmt->from_clause)) + elog(ERROR, "CreateStatsStmt length of rtable should equal to from_clause"); + /* - * Examine the FROM clause. Currently, we only allow it to be a single - * simple table, but later we'll probably allow multiple tables and JOIN - * syntax. The grammar is already prepared for that, so we have to check - * here that what we got is what we can support. + * Double-check that the range table is of a form we can support. */ - if (list_length(stmt->relations) != 1) + if (list_length(stmt->rtable) != 1) ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("only a single relation is allowed in CREATE STATISTICS"))); - - foreach(cell, stmt->relations) - { - Node *rln = (Node *) lfirst(cell); - - if (!IsA(rln, RangeVar)) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("only a single relation is allowed in CREATE STATISTICS"))); + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("only a single relation is allowed in CREATE STATISTICS")); ++<<<<<<< ours + /* + * CREATE STATISTICS will influence future execution plans but does + * not interfere with currently executing plans. So it should be + * enough to take only ShareUpdateExclusiveLock on relation, + * conflicting with ANALYZE and other DDL that sets statistical + * information, but not with normal queries. + */ + rel = relation_openrv((RangeVar *) rln, ShareUpdateExclusiveLock); + + /* Restrict to allowed relation types */ + if (rel->rd_rel->relkind != RELKIND_RELATION && + rel->rd_rel->relkind != RELKIND_MATVIEW && + rel->rd_rel->relkind != RELKIND_FOREIGN_TABLE && + rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot define statistics for relation \"%s\"", + RelationGetRelationName(rel)), + errdetail_relkind_not_supported(rel->rd_rel->relkind))); + + /* + * 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)); + + /* Creating statistics on system catalogs is not allowed */ + if (!allowSystemTableMods && IsSystemRelation(rel)) + ereport(ERROR, + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + errmsg("permission denied: \"%s\" is a system catalog", + RelationGetRelationName(rel)))); + } ++======= + rte = linitial_node(RangeTblEntry, stmt->rtable); + rel = relation_open(rte->relid, NoLock); ++>>>>>>> theirs Assert(rel); relid = RelationGetRelid(rel);