v1-0002-Pass-scan-direction-down-through-pstate.patch
application/octet-stream
Filename: v1-0002-Pass-scan-direction-down-through-pstate.patch
Type: application/octet-stream
Part: 1
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v1-0002
Subject: Pass scan direction down through pstate.
| File | + | − |
|---|---|---|
| src/backend/access/nbtree/nbtreadpage.c | 7 | 6 |
From a5b634ce85b82aed4cfe80e3d5f96b657b785383 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <pg@bowt.ie>
Date: Fri, 5 Dec 2025 16:53:44 -0500
Subject: [PATCH v1 2/2] Pass scan direction down through pstate.
---
src/backend/access/nbtree/nbtreadpage.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/access/nbtree/nbtreadpage.c b/src/backend/access/nbtree/nbtreadpage.c
index 06040d283..540d172cc 100644
--- a/src/backend/access/nbtree/nbtreadpage.c
+++ b/src/backend/access/nbtree/nbtreadpage.c
@@ -31,6 +31,7 @@
typedef struct BTReadPageState
{
/* Input parameters, set by _bt_readpage for _bt_checkkeys */
+ ScanDirection dir; /* current scan direction */
OffsetNumber minoff; /* Lowest non-pivot tuple's offset */
OffsetNumber maxoff; /* Highest non-pivot tuple's offset */
IndexTuple finaltup; /* Needed by scans with array keys */
@@ -181,6 +182,7 @@ _bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum,
maxoff = PageGetMaxOffsetNumber(page);
/* initialize page-level state that we'll pass to _bt_checkkeys */
+ pstate.dir = dir;
pstate.minoff = minoff;
pstate.maxoff = maxoff;
pstate.finaltup = NULL;
@@ -1152,13 +1154,13 @@ _bt_savepostingitem(BTScanOpaque so, int itemIndex, OffsetNumber offnum,
* tuple: index tuple to test
* tupnatts: number of attributes in tupnatts (high key may be truncated)
*/
-bool
+static bool
_bt_checkkeys(IndexScanDesc scan, BTReadPageState *pstate, bool arrayKeys,
IndexTuple tuple, int tupnatts)
{
TupleDesc tupdesc = RelationGetDescr(scan->indexRelation);
- BTScanOpaque so = (BTScanOpaque) scan->opaque;
- ScanDirection dir = so->currPos.dir;
+ BTScanOpaque so PG_USED_FOR_ASSERTS_ONLY = (BTScanOpaque) scan->opaque;
+ ScanDirection dir = pstate->dir;
int ikey = pstate->startikey;
bool res;
@@ -2059,8 +2061,7 @@ static void
_bt_checkkeys_look_ahead(IndexScanDesc scan, BTReadPageState *pstate,
int tupnatts, TupleDesc tupdesc)
{
- BTScanOpaque so = (BTScanOpaque) scan->opaque;
- ScanDirection dir = so->currPos.dir;
+ ScanDirection dir = pstate->dir;
OffsetNumber aheadoffnum;
IndexTuple ahead;
@@ -2193,7 +2194,7 @@ _bt_advance_array_keys(IndexScanDesc scan, BTReadPageState *pstate,
{
BTScanOpaque so = (BTScanOpaque) scan->opaque;
Relation rel = scan->indexRelation;
- ScanDirection dir = so->currPos.dir;
+ ScanDirection dir = pstate ? pstate->dir : ForwardScanDirection;
int arrayidx = 0;
bool beyond_end_advance = false,
skip_array_advanced = false,
--
2.51.0