Re: [ADMIN] pg_class reltuples/relpages not updated by autovacuum/vacuum - Mailing list pgsql-hackers
From | Tom Lane |
---|---|
Subject | Re: [ADMIN] pg_class reltuples/relpages not updated by autovacuum/vacuum |
Date | |
Msg-id | 15043.1306423500@sss.pgh.pa.us Whole thread Raw |
In response to | Re: [ADMIN] pg_class reltuples/relpages not updated by autovacuum/vacuum (Greg Stark <gsstark@mit.edu>) |
Responses |
Re: [ADMIN] pg_class reltuples/relpages not updated by autovacuum/vacuum
|
List | pgsql-hackers |
Greg Stark <gsstark@mit.edu> writes: > On Wed, May 25, 2011 at 9:41 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote: >> ... What I'm currently imagining is >> to do a smoothed moving average, where we factor in the new density >> estimate with a weight dependent on the percentage of the table we did >> scan. That is, the calculation goes something like >> >> old_density = old_reltuples / old_relpages >> new_density = counted_tuples / scanned_pages >> reliability = scanned_pages / new_relpages >> updated_density = old_density + (new_density - old_density) * reliability >> new_reltuples = updated_density * new_relpages > This amounts to assuming that the pages observed in the vacuum have > the density observed and the pages that weren't seen have the density > that were previously in the reltuples/relpages stats. That seems like > a pretty solid approach to me. If the numbers were sane before it > follows that they should be sane after the update. Hm, that's an interesting way of looking at it, but I was coming at it from a signal-processing point of view. What Robert is concerned about is that if VACUUM is cleaning a non-representative sample of pages, and repeated VACUUMs examine pretty much the same sample each time, then over repeated applications of the above formula the estimated density will eventually converge to what we are seeing in the sample. The speed of convergence depends on the moving-average multiplier, ie the "reliability" number above, and what I was after was just to slow down convergence for smaller samples. So I wouldn't have any problem with including a fudge factor to make the convergence even slower. But your analogy makes it seem like this particular formulation is actually "right" in some sense. One other point here is that Florian's problem is really only with our failing to update relpages. I don't think there is any part of the system that particularly cares about reltuples for a toast table. So even if the value did converge to some significantly-bad estimate over time, it's not really an issue AFAICS. We do care about having a sane reltuples estimate for regular tables, but for those we should have a mixture of updates from ANALYZE and updates from VACUUM. Also, for both regular and toast tables we will have an occasional vacuum-for-wraparound that is guaranteed to scan all pages and hence do a hard reset of reltuples to the correct value. I'm still of the opinion that an incremental estimation process like the above is a lot saner than what we're doing now, snarky Dilbert references notwithstanding. The only thing that seems worthy of debate from here is whether we should trust ANALYZE's estimates a bit more than VACUUM's estimates, on the grounds that the former are more likely to be from a random subset of pages. We could implement that by applying a fudge factor when folding a VACUUM estimate into the moving average (ie, multiply its reliability by something less than one). I don't have any principled suggestion for just what the fudge factor ought to be, except that I don't think "zero" is the best value, which AFAICT is what Robert is arguing. I think Greg's argument shows that "one" is the right value when dealing with an ANALYZE estimate, if you believe that ANALYZE saw a random set of pages ... but using that for VACUUM does seem overoptimistic. regards, tom lane
pgsql-hackers by date: