0001-Stats-import-Fix-default-reltuples-on-versions-older.patch
application/octet-stream
Filename: 0001-Stats-import-Fix-default-reltuples-on-versions-older.patch
Type: application/octet-stream
Part: 0
Message:
Re: Statistics Import and Export
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch 0001
Subject: Stats import: Fix default reltuples on versions older than 14
| File | + | − |
|---|---|---|
| src/bin/pg_dump/pg_dump.c | 11 | 1 |
From f3024a4b50af63f61fb91a82e7b91c98f9bf882d Mon Sep 17 00:00:00 2001
From: Hari Krishna Sunder <hari90@users.noreply.github.com>
Date: Tue, 13 May 2025 23:26:32 +0000
Subject: [PATCH] Stats import: Fix default reltuples on versions older than 14
---
src/bin/pg_dump/pg_dump.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index e2e7975b34e..45548004240 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -10924,7 +10924,17 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te)
appendStringLiteralAH(out, rsinfo->dobj.name, fout);
appendPQExpBufferStr(out, ",\n");
appendPQExpBuffer(out, "\t'relpages', '%d'::integer,\n", rsinfo->relpages);
- appendPQExpBuffer(out, "\t'reltuples', '%s'::real,\n", rsinfo->reltuples);
+
+ /*
+ * Before version 14, the default value for reltuples of tables that had not yet been ANALYZED
+ * was 0. In version 14, the default value was changed to -1. Even if the table is empty, let's
+ * just assume it has not yet been ANALYZED and set to -1.
+ */
+ if (fout->remoteVersion < 140000 && strcmp("0", rsinfo->reltuples) == 0)
+ appendPQExpBufferStr(out, "\t'reltuples', '-1'::real,\n");
+ else
+ appendPQExpBuffer(out, "\t'reltuples', '%s'::real,\n", rsinfo->reltuples);
+
appendPQExpBuffer(out, "\t'relallvisible', '%d'::integer",
rsinfo->relallvisible);
--
2.26.0