Re: Returning nbtree posting list TIDs in DESC order during backwards scans - Mailing list pgsql-hackers

From Victor Yegorov
Subject Re: Returning nbtree posting list TIDs in DESC order during backwards scans
Date
Msg-id CAGnEboirgArezZDNeFrR8FOGvKF-Xok333s2iVwWi65gZf8MEA@mail.gmail.com
Whole thread Raw
In response to Re: Returning nbtree posting list TIDs in DESC order during backwards scans  (Peter Geoghegan <pg@bowt.ie>)
Responses Re: Returning nbtree posting list TIDs in DESC order during backwards scans
List pgsql-hackers
ср, 10 дек. 2025 г. в 21:40, Peter Geoghegan <pg@bowt.ie>:
Attached v5 avoids the regression by tweaking _bt_readpage. I will
commit this version soon (I really mean it this time!).



I also gave up on the idea of using a bitmapset for v5 -- the issue
with regressing _bt_readpage discouraged me from adding code that
allocates memory (more than once per scan) within btgettuple, which is
a performance-critical path. We can simply sort and unique-ify the
killedItems array from within _bt_killitems instead -- which is
largely the same way that my original v1 did it. That way it won't
matter what order we append to killItems in, relative to the scan
direction. (The downside of sticking with an array for killedItems is
that we can still run out of array space in extreme cases involving
scrollable cursors that return many killable tuples, and repeatedly
append the same TID to killedItems[], but that doesn't seem like much
of a loss to me -- that almost never happens in practice.)

Compiled and tested without issues.

Small note: as you're removing “We rely on the convention that heap TIDs in the scanpos
items array are stored in ascending heap TID order…” part of the comment, perhaps it'd be
good to add smth similar to that to the “Sort and uniqueify so->killedItems[] to deal with all this.”
piece? Smth like:

+ * Sort and uniqueify so->killedItems[] to deal with all this,
+ * as TIDs are processed in ascending order.

I feel the need for such a comment from my POV as a code reader. 


--
Victor Yegorov

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Solaris versus our NLS files
Next
From: Jacob Champion
Date:
Subject: Re: Periodic authorization expiration checks using GoAway message