pgsql: nbtree: tighten up array recheck rules. - Mailing list pgsql-committers

From Peter Geoghegan
Subject pgsql: nbtree: tighten up array recheck rules.
Date
Msg-id E1uCkHT-000eps-05@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
nbtree: tighten up array recheck rules.

Be more conservative when performing a scheduled recheck of an nbtree
scan's array keys once on the next page, having set so->scanBehind: back
out of reading the page (perform another primitive scan instead) when
the next page's high key/finaltup has an untruncated prefix of matching
values and truncated suffix attributes associated with lower-order keys.
In other words, stop assuming that the lower-order keys have been
satisfied by the truncated suffix attributes in this context (only do so
when considering scheduling a recheck within _bt_advance_array_keys).

The new behavior is more logical: if the next page read after setting
so->scanBehind can only contain tuples that are themselves "behind the
scan", that's reason enough to cut our losses.  In general, when we set
so->scanBehind, we only expect to perform one recheck on the next page
to make a final decision about whether or not to continue the current
primitive index scan.  It seems unprincipled for the recheck to allow a
_bt_readpage to continue unless the scan's arrays will advance/unless
the page might actually contain relevant tuples.

In practice it is highly unlikely that things will line up like this
(the untruncated prefix of attribute values from the next page's high
key is seldom an exact match for their corresponding array's current
element following array advancement on the original/previous page).
That gives us all the more reason to keep things simple and consistent.

This was arguably an oversight in commit 9a2e2a285a, which improved
nbtree array primitive scan scheduling.

Author: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-WzkXzJajgyW-pCQ7vaDPhaT3huU+Zw_j448rpCBEsu2YOQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7e25c9363a82b6974c1ca2303ae8ded98af3bb24

Modified Files
--------------
src/backend/access/nbtree/nbtutils.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)


pgsql-committers by date:

Previous
From: Aleksander Alekseev
Date:
Subject: Re: pgsql: Refactor ChangeVarNodesExtended() using the custom callback
Next
From: Peter Geoghegan
Date:
Subject: pgsql: Prevent premature nbtree array advancement.