=== Applying patches on top of PostgreSQL commit ID a14041d437ff9e74d3596aea31bd202662e28800 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Tue Oct 6 17:00:33 UTC 2026 On branch cf/7170 nothing to commit, working tree clean === using 'git am' to apply patch ./0001-Add-safer-initializers-for-relation-and-attribute-st.patch === Applying: Add safer initializers for relation and attribute stats Using index info to reconstruct a base tree... M contrib/postgres_fdw/postgres_fdw.c M src/backend/statistics/attribute_stats.c M src/backend/statistics/relation_stats.c M src/include/statistics/statistics.h Falling back to patching base and 3-way merge... Auto-merging src/include/statistics/statistics.h CONFLICT (content): Merge conflict in src/include/statistics/statistics.h Auto-merging src/backend/statistics/relation_stats.c CONFLICT (content): Merge conflict in src/backend/statistics/relation_stats.c Auto-merging src/backend/statistics/attribute_stats.c CONFLICT (content): Merge conflict in src/backend/statistics/attribute_stats.c Auto-merging contrib/postgres_fdw/postgres_fdw.c CONFLICT (content): Merge conflict in contrib/postgres_fdw/postgres_fdw.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 Add safer initializers for relation and attribute stats 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 ./0001-Add-safer-initializers-for-relation-and-attribute-st.patch === patching file src/include/statistics/statistics.h Hunk #1 FAILED at 132. Hunk #2 FAILED at 146. Hunk #3 succeeded at 128 with fuzz 2 (offset -45 lines). 2 out of 3 hunks FAILED -- saving rejects to file src/include/statistics/statistics.h.rej patching file src/backend/statistics/attribute_stats.c Hunk #1 FAILED at 140. Hunk #2 FAILED at 206. 2 out of 2 hunks FAILED -- saving rejects to file src/backend/statistics/attribute_stats.c.rej patching file src/backend/statistics/relation_stats.c Hunk #1 FAILED at 73. Hunk #2 FAILED at 92. 2 out of 2 hunks FAILED -- saving rejects to file src/backend/statistics/relation_stats.c.rej patching file contrib/postgres_fdw/postgres_fdw.c Hunk #1 FAILED at 6254. Hunk #2 FAILED at 6275. Hunk #3 FAILED at 6345. 3 out of 3 hunks FAILED -- saving rejects to file contrib/postgres_fdw/postgres_fdw.c.rej Unstaged changes after reset: M src/include/statistics/statistics.h Removing contrib/postgres_fdw/postgres_fdw.c.rej Removing src/backend/statistics/attribute_stats.c.rej Removing src/backend/statistics/relation_stats.c.rej Removing src/include/statistics/statistics.h.rej === using 'git apply' to apply patch ./0001-Add-safer-initializers-for-relation-and-attribute-st.patch === Applied patch to 'src/include/statistics/statistics.h' with conflicts. Applied patch to 'src/backend/statistics/attribute_stats.c' with conflicts. Applied patch to 'src/backend/statistics/relation_stats.c' with conflicts. Applied patch to 'contrib/postgres_fdw/postgres_fdw.c' with conflicts. U contrib/postgres_fdw/postgres_fdw.c U src/backend/statistics/attribute_stats.c U src/backend/statistics/relation_stats.c U src/include/statistics/statistics.h diff --cc contrib/postgres_fdw/postgres_fdw.c index 4ca061c9e0b,97f45062e56..00000000000 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@@ -6314,11 -6252,13 +6314,17 @@@ import_fetched_statistics(Relation rela const RemoteAttributeMapping *remattrmap, int attrcnt) { ++<<<<<<< ours + NullableDatum args[ATTSTATS_NUM_FIELDS]; ++======= + PGresult *res; + NullableDatum version; + RelationStatsValues relvalues = RELATION_STATS_VALUES_NULL; ++>>>>>>> theirs - /* Set the 'version' value, which is common to both statistics. */ - version.value = Int32GetDatum(remstats->version); - version.isnull = false; + /* Set the 'version' parameter, which is common to both statistics. */ + args[0].value = Int32GetDatum(remstats->version); + args[0].isnull = false; /* * We import attribute statistics first, if any, because those are more @@@ -6336,6 -6275,7 +6342,10 @@@ { int row = remattrmap[mapidx].res_index; AttrNumber attnum = remattrmap[mapidx].local_attnum; ++<<<<<<< ours ++======= + AttributeStatsValues attvalues = ATTRIBUTE_STATS_VALUES_NULL; ++>>>>>>> theirs /* All mappings should have been assigned a result set row. */ Assert(row >= 0); @@@ -6394,21 -6331,23 +6404,24 @@@ /* * Import relation statistics. */ - res = remstats->rel; - Assert(res != NULL); - Assert(PQnfields(res) == RELSTATS_NUM_FIELDS); - Assert(PQntuples(res) == 1); - - /* Set the remaining values. */ - relvalues.version = version; - set_int32_arg(&relvalues.relpages, - get_opt_value(res, 0, RELSTATS_RELPAGES)); - Assert(!relvalues.relpages.isnull); - set_float_arg(&relvalues.reltuples, - get_opt_value(res, 0, RELSTATS_RELTUPLES)); - Assert(!relvalues.reltuples.isnull); + + /* Set the remaining parameters. */ + args[1].value = Int32GetDatum(remstats->relpages); + args[1].isnull = false; + args[2].value = Float4GetDatum(remstats->reltuples); + args[2].isnull = false; /* We don't import relallvisible/relallfrozen. */ ++<<<<<<< ours + args[3].value = (Datum) 0; + args[3].isnull = true; + args[4].value = (Datum) 0; + args[4].isnull = true; ++======= ++>>>>>>> theirs /* Try to import the statistics. */ - if (!import_relation_statistics(relation, &relvalues)) + if (!import_relation_statistics(relation, &args[0], &args[1], + &args[2], &args[3], &args[4])) { ereport(WARNING, errmsg("could not import statistics for foreign table \"%s.%s\" --- relation statistics import failed for this foreign table", diff --cc src/backend/statistics/attribute_stats.c index 25d8a73e573,cd9794c952e..00000000000 --- a/src/backend/statistics/attribute_stats.c +++ b/src/backend/statistics/attribute_stats.c @@@ -140,12 -140,13 +140,16 @@@ attribute_statistics_update(FunctionCal AttrNumber attnum; bool inherited; Oid locked_table = InvalidOid; ++<<<<<<< ours ++======= + AttributeStatsValues values = ATTRIBUTE_STATS_VALUES_NULL; ++>>>>>>> theirs - stats_check_required_arg(args, attarginfo, ATTRELSCHEMA_ARG); - stats_check_required_arg(args, attarginfo, ATTRELNAME_ARG); + stats_check_required_arg(fcinfo, attarginfo, ATTRELSCHEMA_ARG); + stats_check_required_arg(fcinfo, attarginfo, ATTRELNAME_ARG); - nspname = TextDatumGetCString(args[ATTRELSCHEMA_ARG].value); - relname = TextDatumGetCString(args[ATTRELNAME_ARG].value); + nspname = TextDatumGetCString(PG_GETARG_DATUM(ATTRELSCHEMA_ARG)); + relname = TextDatumGetCString(PG_GETARG_DATUM(ATTRELNAME_ARG)); if (RecoveryInProgress()) ereport(ERROR, @@@ -201,11 -202,26 +205,31 @@@ errmsg("cannot modify statistics on system column \"%s\"", attname))); ++<<<<<<< ours + stats_check_required_arg(fcinfo, attarginfo, INHERITED_ARG); + inherited = PG_GETARG_BOOL(INHERITED_ARG); ++======= + stats_check_required_arg(args, attarginfo, INHERITED_ARG); + inherited = DatumGetBool(args[INHERITED_ARG].value); + + /* Collect the values to apply */ + values.null_frac = args[NULL_FRAC_ARG]; + values.avg_width = args[AVG_WIDTH_ARG]; + values.n_distinct = args[N_DISTINCT_ARG]; + values.most_common_vals = args[MOST_COMMON_VALS_ARG]; + values.most_common_freqs = args[MOST_COMMON_FREQS_ARG]; + values.histogram_bounds = args[HISTOGRAM_BOUNDS_ARG]; + values.correlation = args[CORRELATION_ARG]; + values.most_common_elems = args[MOST_COMMON_ELEMS_ARG]; + values.most_common_elem_freqs = args[MOST_COMMON_ELEM_FREQS_ARG]; + values.elem_count_histogram = args[ELEM_COUNT_HISTOGRAM_ARG]; + values.range_length_histogram = args[RANGE_LENGTH_HISTOGRAM_ARG]; + values.range_empty_frac = args[RANGE_EMPTY_FRAC_ARG]; + values.range_bounds_histogram = args[RANGE_BOUNDS_HISTOGRAM_ARG]; ++>>>>>>> theirs return attribute_statistics_update_internal(reloid, attname, attnum, - inherited, &values); + inherited, fcinfo); } /* diff --cc src/backend/statistics/relation_stats.c index f2743c00c58,6e073c9cc0a..00000000000 --- a/src/backend/statistics/relation_stats.c +++ b/src/backend/statistics/relation_stats.c @@@ -73,12 -73,13 +73,16 @@@ relation_statistics_update(FunctionCall char *relname; Oid reloid; Oid locked_table = InvalidOid; ++<<<<<<< ours ++======= + RelationStatsValues values = RELATION_STATS_VALUES_NULL; ++>>>>>>> theirs - stats_check_required_arg(args, relarginfo, RELSCHEMA_ARG); - stats_check_required_arg(args, relarginfo, RELNAME_ARG); + stats_check_required_arg(fcinfo, relarginfo, RELSCHEMA_ARG); + stats_check_required_arg(fcinfo, relarginfo, RELNAME_ARG); - nspname = TextDatumGetCString(args[RELSCHEMA_ARG].value); - relname = TextDatumGetCString(args[RELNAME_ARG].value); + nspname = TextDatumGetCString(PG_GETARG_DATUM(RELSCHEMA_ARG)); + relname = TextDatumGetCString(PG_GETARG_DATUM(RELNAME_ARG)); if (RecoveryInProgress()) ereport(ERROR, @@@ -90,7 -91,13 +94,17 @@@ ShareUpdateExclusiveLock, 0, RangeVarCallbackForStats, &locked_table); ++<<<<<<< ours + return relation_statistics_update_internal(reloid, fcinfo); ++======= + /* Collect the values to apply. */ + values.relpages = args[RELPAGES_ARG]; + values.reltuples = args[RELTUPLES_ARG]; + values.relallvisible = args[RELALLVISIBLE_ARG]; + values.relallfrozen = args[RELALLFROZEN_ARG]; + + return relation_statistics_update_internal(reloid, &values); ++>>>>>>> theirs } /* diff --cc src/include/statistics/statistics.h index 0b163103a72,71ebca40438..00000000000 --- a/src/include/statistics/statistics.h +++ b/src/include/statistics/statistics.h @@@ -128,28 -128,91 +128,111 @@@ extern StatisticExtInfo *choose_best_st int nclauses); extern HeapTuple statext_expressions_load(Oid stxoid, bool inh, int idx); ++<<<<<<< ours ++======= + /* + * Statistics values applied to pg_class during stats import or restore + * + * A field with isnull set to true leaves the corresponding pg_class column + * untouched. The caller must initialize every field; see also + * RELATION_STATS_VALUES_NULL. + * + * The "version" field is currently ignored. In the future it can be used to + * interpret the format of older statistics. + */ + typedef struct RelationStatsValues + { + NullableDatum version; + NullableDatum relpages; + NullableDatum reltuples; + NullableDatum relallvisible; + NullableDatum relallfrozen; + } RelationStatsValues; + + /* + * Initializer for a RelationStatsValues. + */ + #define RELATION_STATS_VALUES_NULL \ + { \ + .version = {.value = (Datum) 0, .isnull = true}, \ + .relpages = {.value = (Datum) 0, .isnull = true}, \ + .reltuples = {.value = (Datum) 0, .isnull = true}, \ + .relallvisible = {.value = (Datum) 0, .isnull = true}, \ + .relallfrozen = {.value = (Datum) 0, .isnull = true}, \ + } + + /* + * Statistics values applied to pg_statistic during stats import or restore. + * + * A field with isnull set to true leaves the corresponding statistics kind + * unset. The caller must initialize every field; see also + * ATTRIBUTE_STATS_VALUES_NULL. + * + * The "version" field is currently ignored. In the future, it can be used to + * interpret the format of older statistics. + */ + typedef struct AttributeStatsValues + { + NullableDatum version; + NullableDatum null_frac; + NullableDatum avg_width; + NullableDatum n_distinct; + NullableDatum most_common_vals; + NullableDatum most_common_freqs; + NullableDatum histogram_bounds; + NullableDatum correlation; + NullableDatum most_common_elems; + NullableDatum most_common_elem_freqs; + NullableDatum elem_count_histogram; + NullableDatum range_length_histogram; + NullableDatum range_empty_frac; + NullableDatum range_bounds_histogram; + } AttributeStatsValues; + + /* + * Initializer for an AttributeStatsValues. + */ + #define ATTRIBUTE_STATS_VALUES_NULL \ + { \ + .version = {.value = (Datum) 0, .isnull = true}, \ + .null_frac = {.value = (Datum) 0, .isnull = true}, \ + .avg_width = {.value = (Datum) 0, .isnull = true}, \ + .n_distinct = {.value = (Datum) 0, .isnull = true}, \ + .most_common_vals = {.value = (Datum) 0, .isnull = true}, \ + .most_common_freqs = {.value = (Datum) 0, .isnull = true}, \ + .histogram_bounds = {.value = (Datum) 0, .isnull = true}, \ + .correlation = {.value = (Datum) 0, .isnull = true}, \ + .most_common_elems = {.value = (Datum) 0, .isnull = true}, \ + .most_common_elem_freqs = {.value = (Datum) 0, .isnull = true}, \ + .elem_count_histogram = {.value = (Datum) 0, .isnull = true}, \ + .range_length_histogram = {.value = (Datum) 0, .isnull = true}, \ + .range_empty_frac = {.value = (Datum) 0, .isnull = true}, \ + .range_bounds_histogram = {.value = (Datum) 0, .isnull = true}, \ + } + ++>>>>>>> theirs extern bool import_relation_statistics(Relation rel, - const RelationStatsValues *statvalues); + const NullableDatum *version, + const NullableDatum *relpages, + const NullableDatum *reltuples, + const NullableDatum *relallvisible, + const NullableDatum *relallfrozen); extern bool import_attribute_statistics(Relation rel, AttrNumber attnum, bool inherited, - const AttributeStatsValues *statvalues); + const NullableDatum *version, + const NullableDatum *null_frac, + const NullableDatum *avg_width, + const NullableDatum *n_distinct, + const NullableDatum *most_common_vals, + const NullableDatum *most_common_freqs, + const NullableDatum *histogram_bounds, + const NullableDatum *correlation, + const NullableDatum *most_common_elems, + const NullableDatum *most_common_elem_freqs, + const NullableDatum *elem_count_histogram, + const NullableDatum *range_length_histogram, + const NullableDatum *range_empty_frac, + const NullableDatum *range_bounds_histogram); extern bool delete_attribute_statistics(Relation rel, AttrNumber attnum, bool inherited);