On Tue, Mar 4, 2025 at 6:25 AM Jeff Davis <pg...@j-davis.com> wrote: > > On Mon, 2025-03-03 at 22:04 +0530, Ashutosh Bapat wrote: > > But while we have hold of reltuples wasting a chance to > > update it in pg_class does not look right to me. > > To me, autovacuum=off is a pretty clear signal that the user doesn't > want this kind of side-effect to happen. Am I missing something?
Documentation of autovacuum says "Controls whether the server should run the autovacuum launcher daemon." It doesn't talk about updates happening as a side-effect. With autovacuum there is an extra scan and resources are consumed but with index creation all that cost is already paid. I wouldn't compare those two. The case with IsBinaryUpdate is straight, statistics is not updated only when run in binary upgrade mode. If we could devise a way to not update statistics only when the index is created as part of restoring a dump, that will be easily acceptable. But I don't know > > > I think the solution should be on the pg_dump/restore side and not on > > the server side. > > What solution are you suggesting? The only one that comes to mind is > moving everything to SECTION_POST_DATA, which is possible, but it seems > like a big design change to satisfy a small detail. We don't have to do that. We can manage it by making statistics of index dependent upon the indexes on the table. As far as dump is concerned, they are dependent since index creation rewrites the statistics so we would like to add statistics after index creation. For that we will need to track the statistics dumpable object in the TableInfo. When adding indexes to TableInfo in getIndexes, we add dependency between the index and the table statistics. The dependency based sorting will automatically take care ordering statistics objects after all the index objects and thus print it after all CREATE INDEX commands. I have not tried to code this. Do you see any problems with that? -- Best Wishes, Ashutosh Bapat