]> git.ipfire.org Git - thirdparty/postgresql.git/commit
YA attempt at taming worst-case behavior of get_actual_variable_range.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 Nov 2022 19:40:20 +0000 (14:40 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 Nov 2022 19:40:45 +0000 (14:40 -0500)
commitbd06fe4dee6321a3eabc1832f1faa736350d5d2c
treee624311ddd78f0f883753f5b487b1ae25d402fd6
parent870d6218e6d73dca8ec37b4d7f5076b74eeaeffe
YA attempt at taming worst-case behavior of get_actual_variable_range.

We've made multiple attempts at preventing get_actual_variable_range
from taking an unreasonable amount of time (3ca930fc3fccebe421).
But there's still an issue for the very first planning attempt after
deletion of a large number of extremal-valued tuples.  While that
planning attempt will set "killed" bits on the tuples it visits and
thereby reduce effort for next time, there's still a lot of work it
has to do to visit the heap and then set those bits.  It's (usually?)
not worth it to do that much work at plan time to have a slightly
better estimate, especially in a context like this where the table
contents are known to be mutating rapidly.

Therefore, let's bound the amount of work to be done by giving up
after we've visited 100 heap pages.  Giving up just means we'll
fall back on the extremal value recorded in pg_statistic, so it
shouldn't mean that planner estimates suddenly become worthless.

Note that this means we'll still gradually whittle down the problem
by setting a few more index "killed" bits in each planning attempt;
so eventually we'll reach a good state (barring further deletions),
even in the absence of VACUUM.

Simon Riggs, per a complaint from Jakub Wartak (with cosmetic
adjustments by me).  Back-patch to all supported branches.

Discussion: https://postgr.es/m/CAKZiRmznOwi0oaV=4PHOCM4ygcH4MgSvt8=5cu_vNCfc8FSUug@mail.gmail.com
src/backend/utils/adt/selfuncs.c