You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Redefine pg_class.reltuples to be -1 before the first VACUUM or ANALYZE.
Historically, we've considered the state with relpages and reltuplesboth zero as indicating that we do not know the table's tuple density.This is problematic because it's impossible to distinguish "never yetvacuumed" from "vacuumed and seen to be empty". In particular, a usercannot use VACUUM or ANALYZE to override the planner's normal heuristicthat an empty table should not be believed to be empty because it isprobably about to get populated. That heuristic is a good safetymeasure, so I don't care to abandon it, but there should be a way tooverride it if the table is indeed intended to stay empty.Hence, represent the initial state of ignorance by setting reltuplesto -1 (relpages is still set to zero), and apply the minimum-ten-pagesheuristic only when reltuples is still -1. If the table is empty,VACUUM or ANALYZE (but not CREATE INDEX) will override that toreltuples = relpages = 0, and then we'll plan on that basis.This requires a bunch of fiddly little changes, but we can get rid ofsome ugly kluges that were formerly needed to maintain the old definition.One notable point is that FDWs' GetForeignRelSize methods will seebaserel->tuples = -1 when no ANALYZE has been done on the foreign table.That seems like a net improvement, since those methods were formerlyalso in the dark about what baserel->tuples = 0 really meant. Still,it is an API change.I bumped catversion because code predating this change would get confusedby seeing reltuples = -1.Discussion:https://postgr.es/m/F02298E0-6EF4-49A1-BCB6-C484794D9ACC@thebuild.com