pgsql: Fix nbtree array unsatisfied inequality check. - Mailing list pgsql-committers

From Peter Geoghegan
Subject pgsql: Fix nbtree array unsatisfied inequality check.
Date
Msg-id E1sMTuS-0036ja-QL@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix nbtree array unsatisfied inequality check.

_bt_advance_array_keys didn't take sufficient care at the point where it
decides whether to start a new primitive index scan based on a call to
_bt_check_compare against finaltup (a call with the scan direction
flipped around).  The final decision was conditioned on rules about how
the scan key offset sktrig that initially triggered array advancement
(passed to _bt_advance_array_keys from its _bt_checkkeys caller)
compared to the offset set by its own _bt_check_compare finaltup call.
This approach was faulty, in that it allowed _bt_advance_array_keys to
incorrectly start a new primitive index scan, that landed on the same
leaf page (on assert-enabled builds it led to an assertion failure).

In general, scans with array keys are expected to never have to read the
same leaf page more than once (barring cases involving cursors, and
cases where the scan restores a marked position for the inner side of a
merge join).  This principle was established by commit 5bf748b8.

To fix, make the final decision based on whether the scan key offset set
by the _bt_check_compare finaltup call is an offset to an inequality
strategy scan key.  An unsatisfied required inequality strategy scan key
indicates that all of the scan's required equality strategy scan keys
must also be satisfied by finaltup (not just by caller's tuple), and
that there is a decent chance that _bt_first will be able to reposition
the scan to a position many leaf pages ahead of the current leaf page.

Oversight in commit 5bf748b8.

Discussion: https://postgr.es/m/CAH2-Wz=DyHbcg7o6zXqzyiin8WE8vzk4tvU8Lrnh-a=EAvO0TQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/486c2ea25c5e7e248c31b2dbb5db8ebcd3c7d813

Modified Files
--------------
src/backend/access/nbtree/nbtutils.c | 30 ++++++++++--------------------
1 file changed, 10 insertions(+), 20 deletions(-)


pgsql-committers by date:

Previous
From: Alvaro Herrera
Date:
Subject: pgsql: Fix partition pruning setup during DETACH CONCURRENTLY
Next
From: Nathan Bossart
Date:
Subject: pgsql: Use PqMsg_* macros in fe-auth.c.