Re: pg_restore handles extended statistics inconsistently with statistics data
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Chao Li <li.evan.chao@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@lists.postgresql.org>, Michael Paquier <michael.paquier@gmail.com>, Jeff Davis <pgsql@j-davis.com>, Corey Huinker <corey.huinker@gmail.com>
Date: 2026-06-15T07:55:48Z
Lists: pgsql-hackers
Attachments
- v3-0001-Fix-pg_restore-with-schema-table-and-statistics-o.patch (text/plain) patch v3-0001
On Mon, Jun 15, 2026 at 11:51:40AM +0800, Chao Li wrote: > If the fix direction is to make pg_restore behave consistently with > pg_dump, then I think Michael's change is correct. I have been checking for a few hours, and well.. There was more. > See the attached v2 for details. That's nice, unfortunately incomplete. I have found a different pattern that behaves incorrectly, reusing your script of upthread: pg_restore --statistics --table t \ -f /tmp/archive-s1-stats.sql /tmp/stats.dump pg_restore --statistics-only --table t \ -f /tmp/archive-s1-stats.sql /tmp/stats.dump With "--statistics --table t", we restore the definition of table "t" and its data (correct), miss the stats (incorrect!). With "--statistics-only --table t", we restore no definition and no data (correct), and still miss the stats (incorrect!). So we still have a borked restore of the stats when selecting an individual table. We don't care about extended stats with this case, as extstats are objects defined at schema level and we cannot filter them, but I think that we definitely care about attribute and relation stats here. This case requires a second change in _tocEntryRequired() even after the first fix so as it is possible to select a STATISTICS DATA that depends on a table part of the authorized list close to the list that includes the "SEQUENCE SET". With all that in mind, I have the attached. I have expanded the tests with the --table case, using dump and restore commands, and that seems to work correctly now with the restores, including the cases with extstats. And I'm planning to apply that down to v18 tomorrow, after a second round of lookups. -- Michael
Commits
-
pg_restore: Use dependency-based matching for STATISTICS DATA
- 477efef089c3 18 (unreleased) landed
- ae39bd23c662 19 (unreleased) landed
-
Fix inconsistencies with pg_restore --statistics[-only]
- 42ffdedcf743 18 (unreleased) landed
- 0dd93de69e80 19 (unreleased) landed