Re: Statistics Import and Export - Mailing list pgsql-hackers

From Hari Krishna Sunder
Subject Re: Statistics Import and Export
Date
Msg-id CAAeiqZ0o2p4SX5_xPcuAbbsmXjg6MJLNuPYSLUjC=Wh-VeW64A@mail.gmail.com
Whole thread Raw
In response to Re: Statistics Import and Export  (Nathan Bossart <nathandbossart@gmail.com>)
Responses Re: Statistics Import and Export
List pgsql-hackers
We found a minor issue when testing statistics import with upgrading from versions older than v14. (We have VACUUM and ANALYZE disabled)
3d351d916b20534f973eda760cde17d96545d4c4 changed the default value for reltuples from 0 to -1. So when such tables are imported they get the pg13 default of 0 which in pg18 is treated as "vacuumed and seen to be empty" instead of "never yet vacuumed". The planner then proceeds to pick seq scans even if there are indexes for these tables.
This is a very narrow edge case and the next VACUUM or ANALYZE will fix it but the perf of these tables immediately after the upgrade is considerably affected.

Can we instead use -1 if the version is older than 14, and reltuples is 0?
This will have the unintended consequence of treating a truly empty table as "never yet vacuumed", but that should be fine as empty tables are going to be fast regardless of the plan picked.

PS: This is my first patch, so apologies for any issues with the patch.


On Fri, Apr 4, 2025 at 7:06 PM Nathan Bossart <nathandbossart@gmail.com> wrote:
On Fri, Apr 04, 2025 at 07:32:48PM -0400, Corey Huinker wrote:
> This patch shrinks the array size to 1 for versions < 9.4, which keeps the
> modern code fairly elegant.

Committed.

--
nathan


Attachment

pgsql-hackers by date:

Previous
From: Greg Sabino Mullane
Date:
Subject: Re: Disable parallel query by default
Next
From: Richard Guo
Date:
Subject: Re: Add explicit initialization for all PlannerGlobal fields