Subject: Re: Statistics Import and Export: difference in statistics dumped

From: Tom Lane <[email-masked]>
Date: Fri, 07 Mar 2025 14:14:08 -0500

Jeff Davis <[email-masked]> writes:
> Sounds good. I will commit something like the v2 patch then soon, and
> if we need a different condition we can change it later.

Sadly, this made things worse not better: crake is failing
cross-version-upgrade tests again [1], with dump diffs like

@@ -270836,8 +270836,8 @@
 --
 SELECT * FROM pg_catalog.pg_restore_relation_stats(	'version', '000000'::integer,
 	'relation', 'public.hash_f8_index'::regclass,
-	'relpages', '66'::integer,
-	'reltuples', '10000'::real,
+	'relpages', '0'::integer,
+	'reltuples', '-1'::real,
 	'relallvisible', '0'::integer
 );

I think what is happening is that the patch shut off CREATE
INDEX's update of not only the table's stats but also the
index's stats.  This seems unhelpful: the index's empty
stats can never be what's wanted.

We could band-aid over this by making AdjustUpgrade.pm
lobotomize the comparisons of all three stats fields,
but I think it's just wrong as-is.  Perhaps fix by
checking the relation's relkind before applying the
autovacuum heuristic?

			regards, tom lane

[1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=crake&dt=2025-03-07%2018%3A19%3A14

---

From: Tom Lane <[email-masked]>
Date: Mon, 10 Mar 2025 17:53:26 -0400

> stats can never be what's wanted.

I looked at this more closely and realized that it's a simple matter
of having made the tests in the wrong order.  The whole stanza
should only apply when dealing with the table, not the index.

I verified that this change fixes the cross-version-upgrade
failure in local testing, and pushed it.

			regards, tom lane

---

From: Jeff Davis <[email-masked]>
Date: Mon, 10 Mar 2025 16:53:50 -0700

> failure in local testing, and pushed it.

Ah, thank you.

Regards,
	Jeff Davis

---

From: Ashutosh Bapat <[email-masked]>
Date: Tue, 11 Mar 2025 15:50:02 +0530

> > failure in local testing, and pushed it.

Thanks. I verified that it has been fixed now. But there's something
wrong with materialized view statistics. I am starting a new thread
for the same.

-- 
Best Wishes,
Ashutosh Bapat