On Mon, Feb 9, 2026 at 7:39 PM Tom Lane <[email protected]> wrote:
> > 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.

It's true that I have only begun to examine how much of a risk this
is. It is still a WIP patch.

> Maybe it would work to express the limit as number of dead index
> entries we will skip past before failing?

Something like that makes sense.

Perhaps the limit should be expressed in terms of both index tuples
and index pages. We allow the scan to visit additional leaf pages, if
and only if it is necessary for the scan to do so in order for it to
examine the required number of index tuples. But we also apply a hard
cap on the total number of index pages read, enforced regardless of
how many index tuples we have read.  We should have some concern about
sparse deletion patterns and the like, where each leaf page has only 1
or 2 index tuples (there might be no LP_DEAD-marked index tuples that
count towards this index tuple limit within such an index).

Obviously, the number of index tuples isn't necessarily the same thing
as the number of TIDs contained within those index tuples. With nbtree
deduplication, a single leaf page can contain as many as ~1350
distinct TIDs. I wonder if that difference needs to be taken into
account...

> 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.

Ideally we could keep the mechanism confined to nbtree (or other index
AMs that implement the functionality that selfuncs.c will rely on).
I'd like to avoid inventing a new heapam-specific mechanism that has
to somehow coordinate with the nbtree mechanism that I have in mind
for this.

-- 
Peter Geoghegan


Reply via email to