postgres.git / summary / log / commit / refs
commit 35def3385998099f3e80e34f9d7bf6444af5bf1c
Author: Michael Paquier <michael@paquier.xyz>
Date: Wed Nov 11 01:38:45 2026 +0000
First released in: 19.0
pg_dump: Fix inherited flag in extended stats from pre-v15 servers
Servers older than v15 have no stxdinherit in pg_statistic_ext_data, so
pg_dump hardcoded it to false. However, these versions build inherited
extended stats on partitioned tables since 20b9fa308eb. Once restored
as non-inherited, the data was ignored by the planner. pg_upgrade from
v10~v14 was impacted by this issue.
For servers in this range, the inherited flag is now guessed from the
relkind of the relation: true for partitioned tables and false
otherwise, matching with what ANALYZE did before 269b532aef5
(introduction of pg_statistic_ext_data.stxdinherit).
Oversight in c32fb29e979d.
Author: Artem Gavrilov <artem.gavrilov@percona.com>
Reviewed-by: Corey Huinker <corey.huinker@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAFPkQKxoB=kBdVsHXHvprV5j2OOBP5x5ea2yL9h0d3HtjuX+Sg@mail.gmail.com
Backpatch-through: 19
src/bin/pg_dump/pg_dump.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 4fc74e6e26e..a3f38f3b886 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -18611,7 +18611,8 @@ dumpStatisticsExtStats(Archive *fout, const StatsExtInfo *statsextinfo)
* catalogs.
* - In v18 and older versions, ndistinct and dependencies have a
* different format that needs translation.
- * - In v14 and older versions, inherited does not exist.
+ * - In v14 and older versions, there is no inherited flag, hence
+ * it is deduced from the relation's relkind.
* - In v11 and older versions, there is no pg_stats_ext, hence
* the logic joins pg_statistic_ext and pg_namespace.
*---------
@@ -18799,10 +18800,21 @@ dumpStatisticsExtStats(Archive *fout, const StatsExtInfo *statsextinfo)
for (int i = 0; i < nstats; i++)
{
TableInfo *tbinfo = statsextinfo->stattable;
+ const char *inherited;
if (PQgetisnull(res, i, i_inherited))
pg_fatal("inherited cannot be NULL");
+ /*
+ * v14 and older have no inherited flag; only partitioned tables
+ * store inherited extended statistics there.
+ */
+ if (fout->remoteVersion >= 150000)
+ inherited = PQgetvalue(res, i, i_inherited);
+ else
+ inherited =
+ (tbinfo->relkind == RELKIND_PARTITIONED_TABLE) ? "t" : "f";
+
appendPQExpBufferStr(out,
"SELECT * FROM pg_catalog.pg_restore_extended_stats(\n");
appendPQExpBuffer(out, "\t'version', '%d'::integer,\n",
@@ -18819,8 +18831,7 @@ dumpStatisticsExtStats(Archive *fout, const StatsExtInfo *statsextinfo)
appendStringLiteralAH(out, statsextinfo->dobj.namespace->dobj.name, fout);
appendPQExpBufferStr(out, ",\n\t'statistics_name', ");
appendStringLiteralAH(out, statsextinfo->dobj.name, fout);
- appendNamedArgument(out, fout, "inherited", "boolean",
- PQgetvalue(res, i, i_inherited));
+ appendNamedArgument(out, fout, "inherited", "boolean", inherited);
if (!PQgetisnull(res, i, i_ndistinct))
appendNamedArgument(out, fout, "n_distinct", "pg_ndistinct",
[parent: 8cdf3c9214fe]