Peter Geoghegan <[email protected]> writes:
> VISITED_PAGES_LIMIT counts heap page visits. But when there are many
> index tuples marked LP_DEAD, btgettuple will traverse
> indefinitely-many *index* pages before returning even a single tuple
> to the selfuncs.c caller.

Yup, that's a problem.

> Proposed solution
> =================

> Rather than counting heap page visits, I propose limiting the scan to
> the extremal leaf page only. If the extremal index leaf page yields no
> visible tuples, we give up immediately. The latest version of the
> index prefetching patch [2] adds a WIP patch that does just that.

I think that's throwing the baby out with the bathwater.  In exchange
for a tight limit on planner time expended, you have an enormously
increased chance of getting no useful data at all.  For one thing,
it is likely that the extremal page is only partly filled, so that
there may be only a very small number of index entries that this
strategy would consider at all.

Maybe it would work to express the limit as number of dead index
entries we will skip past before failing?  I'd want a threshold of
maybe a thousand, but that would still work to bound the index AM's
work as well as the heap AM's.

> Testing of the patch posted to that other thead today shows that this
> is much more effective.

What definition of "effective" are you using?  It sounds like you are
putting zero weight on successfully obtaining an estimate, and I find
that approach quite unacceptable.

                        regards, tom lane


Reply via email to