=== Applying patches on top of PostgreSQL commit ID 901ed9b352b41f034e17bc540725082a488fce31 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sat May 9 14:27:23 UTC 2026 On branch cf/6516 nothing to commit, working tree clean === using 'git am' to apply patch ./v6-0001-ANALYZE-add-MISSING_STATS_ONLY-option.patch === Applying: ANALYZE: add MISSING_STATS_ONLY option Using index info to reconstruct a base tree... M src/backend/commands/analyze.c M src/backend/commands/vacuum.c M src/include/commands/vacuum.h M src/test/regress/parallel_schedule Falling back to patching base and 3-way merge... Auto-merging src/test/regress/parallel_schedule Auto-merging src/include/commands/vacuum.h Auto-merging src/backend/commands/vacuum.c Auto-merging src/backend/commands/analyze.c CONFLICT (content): Merge conflict in src/backend/commands/analyze.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 ANALYZE: add MISSING_STATS_ONLY option 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". === using patch(1) to apply patch ./v6-0001-ANALYZE-add-MISSING_STATS_ONLY-option.patch === patching file src/backend/commands/analyze.c Hunk #2 succeeded at 49 (offset 1 line). Hunk #3 succeeded at 88 with fuzz 2 (offset 2 lines). Hunk #4 succeeded at 101 (offset 2 lines). Hunk #5 FAILED at 450. Hunk #6 succeeded at 470 (offset 6 lines). Hunk #7 succeeded at 539 (offset 6 lines). Hunk #8 succeeded at 549 (offset 6 lines). Hunk #9 succeeded at 1164 (offset 40 lines). Hunk #10 succeeded at 1179 with fuzz 1 (offset 18 lines). 1 out of 10 hunks FAILED -- saving rejects to file src/backend/commands/analyze.c.rej patching file src/backend/commands/vacuum.c Hunk #1 succeeded at 166 (offset 1 line). Hunk #2 succeeded at 231 (offset 1 line). Hunk #3 succeeded at 309 (offset 1 line). Hunk #4 succeeded at 320 (offset 1 line). patching file src/include/commands/vacuum.h Hunk #1 succeeded at 187 (offset -1 lines). patching file src/test/regress/expected/analyze_missing_stats_only.out patching file src/test/regress/parallel_schedule patching file src/test/regress/sql/analyze_missing_stats_only.sql Unstaged changes after reset: M src/backend/commands/analyze.c M src/backend/commands/vacuum.c M src/include/commands/vacuum.h M src/test/regress/parallel_schedule Removing src/backend/commands/analyze.c.rej Removing src/test/regress/expected/analyze_missing_stats_only.out Removing src/test/regress/sql/analyze_missing_stats_only.sql === using 'git apply' to apply patch ./v6-0001-ANALYZE-add-MISSING_STATS_ONLY-option.patch === Applied patch to 'src/backend/commands/analyze.c' with conflicts. Applied patch to 'src/backend/commands/vacuum.c' cleanly. Applied patch to 'src/include/commands/vacuum.h' cleanly. Falling back to direct application... Applied patch to 'src/test/regress/parallel_schedule' cleanly. Falling back to direct application... U src/backend/commands/analyze.c diff --cc src/backend/commands/analyze.c index 020a5919b84,928ede4f7b8..00000000000 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@@ -83,9 -85,8 +86,9 @@@ static void compute_index_stats(Relatio AnlIndexData *indexdata, int nindexes, HeapTuple *rows, int numrows, MemoryContext col_context); +static void validate_va_cols_list(Relation onerel, List *va_cols); static VacAttrStats *examine_attribute(Relation onerel, int attnum, - Node *index_expr); + Node *index_expr,bool missing_stats_only); static int acquire_sample_rows(Relation onerel, int elevel, HeapTuple *rows, int targrows, double *totalrows, double *totaldeadrows); @@@ -404,8 -438,19 +455,24 @@@ do_analyze_rel(Relation onerel, const V char *col = strVal(lfirst(le)); i = attnameAttNum(onerel, col, false); ++<<<<<<< ours + Assert(i != InvalidAttrNumber); + vacattrstats[tcnt] = examine_attribute(onerel, i, NULL); ++======= + if (i == InvalidAttrNumber) + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_COLUMN), + errmsg("column \"%s\" of relation \"%s\" does not exist", + col, RelationGetRelationName(onerel)))); + if (bms_is_member(i, unique_cols)) + ereport(ERROR, + (errcode(ERRCODE_DUPLICATE_COLUMN), + errmsg("column \"%s\" of relation \"%s\" appears more than once", + col, RelationGetRelationName(onerel)))); + unique_cols = bms_add_member(unique_cols, i); + + vacattrstats[tcnt] = examine_attribute(onerel, i, NULL,(params.options & VACOPT_MISSING_STATS_ONLY)); ++>>>>>>> theirs if (vacattrstats[tcnt] != NULL) tcnt++; } @@@ -1088,12 -1136,70 +1189,51 @@@ examine_attribute(Relation onerel, int int i; bool ok; - /* Never analyze dropped columns */ - if (attr->attisdropped) - return NULL; - - /* Don't analyze virtual generated columns */ - if (attr->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL) - return NULL; - /* - * Get attstattarget value. Set to -1 if null. (Analyze functions expect - * -1 to mean use default_statistics_target; see for example - * std_typanalyze.) + * Check if the column is analyzable. */ - atttuple = SearchSysCache2(ATTNUM, ObjectIdGetDatum(RelationGetRelid(onerel)), Int16GetDatum(attnum)); - if (!HeapTupleIsValid(atttuple)) - elog(ERROR, "cache lookup failed for attribute %d of relation %u", - attnum, RelationGetRelid(onerel)); - dat = SysCacheGetAttr(ATTNUM, atttuple, Anum_pg_attribute_attstattarget, &isnull); - attstattarget = isnull ? -1 : DatumGetInt16(dat); - ReleaseSysCache(atttuple); - - /* Don't analyze column if user has specified not to */ - if (attstattarget == 0) + if (!attribute_is_analyzable(onerel, attnum, attr, &attstattarget)) return NULL; + /* + * If ANALYZE (MISSING_STATS_ONLY), + * skip attributes that already have stats. + */ + if (missing_stats_only) + { + HeapTuple statstup; + bool has_stats = false; + + /* Try stainherit = false */ + statstup = SearchSysCache3(STATRELATTINH, + ObjectIdGetDatum(RelationGetRelid(onerel)), + Int16GetDatum(attnum), + BoolGetDatum(false)); + + if (HeapTupleIsValid(statstup)) + { + has_stats = true; + ReleaseSysCache(statstup); + } + else + { + /* Try stainherit = true (partition parents) */ + statstup = SearchSysCache3(STATRELATTINH, + ObjectIdGetDatum(RelationGetRelid(onerel)), + Int16GetDatum(attnum), + BoolGetDatum(true)); + + if (HeapTupleIsValid(statstup)) + { + has_stats = true; + ReleaseSysCache(statstup); + } + } + if (has_stats) + return NULL; /* skip attribute */ + + } + /* * Create the VacAttrStats struct. */