Skip to content

Commit 1a4070e

Browse files
committed
Add second pass (reversed) from gettuple if we did not found enough tuples
1 parent f48c31f commit 1a4070e

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

rum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ typedef struct RumScanOpaqueData
695695
TIDBitmap *tbm;
696696

697697
ScanDirection naturalOrder;
698+
bool secondPass;
698699
} RumScanOpaqueData;
699700

700701
typedef RumScanOpaqueData *RumScanOpaque;
@@ -706,6 +707,7 @@ extern void rumrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
706707
extern Datum rummarkpos(PG_FUNCTION_ARGS);
707708
extern Datum rumrestrpos(PG_FUNCTION_ARGS);
708709
extern void rumNewScanKey(IndexScanDesc scan);
710+
extern void freeScanKeys(RumScanOpaque so);
709711

710712
/* rumget.c */
711713
extern int64 rumgetbitmap(IndexScanDesc scan, TIDBitmap *tbm);

rumget.c

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@
2525
/* GUC parameter */
2626
int RumFuzzySearchLimit = 0;
2727

28-
typedef struct pendingPosition
29-
{
30-
Buffer pendingBuffer;
31-
OffsetNumber firstOffset;
32-
OffsetNumber lastOffset;
33-
ItemPointerData item;
34-
bool *hasMatchKey;
35-
} pendingPosition;
36-
3728
static bool scanPage(RumState * rumstate, RumScanEntry entry, RumKey *item,
3829
Page page, bool equalOk);
3930
static void insertScanItem(RumScanOpaque so, bool recheck);
@@ -2331,6 +2322,34 @@ insertScanItem(RumScanOpaque so, bool recheck)
23312322
rum_tuplesort_putrum(so->sortstate, item);
23322323
}
23332324

2325+
static void
2326+
reverseScan(IndexScanDesc scan)
2327+
{
2328+
RumScanOpaque so = (RumScanOpaque) scan->opaque;
2329+
int i, j;
2330+
2331+
freeScanKeys(so);
2332+
rumNewScanKey(scan);
2333+
2334+
for(i=0; i<so->nkeys; i++)
2335+
{
2336+
RumScanKey key = so->keys[i];
2337+
2338+
key->isFinished = false;
2339+
key->scanDirection = - key->scanDirection;
2340+
2341+
for(j=0; j<key->nentries; j++)
2342+
{
2343+
RumScanEntry entry = key->scanEntry[j];
2344+
2345+
entry->isFinished = false;
2346+
entry->scanDirection = - entry->scanDirection;
2347+
}
2348+
}
2349+
2350+
startScan(scan);
2351+
}
2352+
23342353
bool
23352354
rumgettuple(IndexScanDesc scan, ScanDirection direction)
23362355
{
@@ -2341,8 +2360,6 @@ rumgettuple(IndexScanDesc scan, ScanDirection direction)
23412360

23422361
if (so->firstCall)
23432362
{
2344-
so->norderbys = scan->numberOfOrderBys;
2345-
23462363
/*
23472364
* Set up the scan keys, and check for unsatisfiable query.
23482365
*/
@@ -2352,10 +2369,6 @@ rumgettuple(IndexScanDesc scan, ScanDirection direction)
23522369
if (RumIsVoidRes(scan))
23532370
PG_RETURN_INT64(0);
23542371

2355-
so->tbm = NULL;
2356-
so->entriesIncrIndex = -1;
2357-
so->firstCall = false;
2358-
23592372
startScan(scan);
23602373
if (so->naturalOrder == NoMovementScanDirection)
23612374
{
@@ -2384,6 +2397,12 @@ rumgettuple(IndexScanDesc scan, ScanDirection direction)
23842397

23852398
return true;
23862399
}
2400+
else if (so->secondPass == false)
2401+
{
2402+
reverseScan(scan);
2403+
so->secondPass = true;
2404+
return rumgettuple(scan, direction);
2405+
}
23872406

23882407
return false;
23892408
}

rumscan.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ freeScanEntries(RumScanEntry *entries, uint32 nentries)
285285
}
286286
}
287287

288-
static void
288+
void
289289
freeScanKeys(RumScanOpaque so)
290290
{
291291
freeScanEntries(so->entries, so->totalentries);
@@ -513,6 +513,11 @@ rumNewScanKey(IndexScanDesc scan)
513513
} hasAddOnFilter = haofNone;
514514

515515
so->naturalOrder = NoMovementScanDirection;
516+
so->secondPass = false;
517+
so->tbm = NULL;
518+
so->entriesIncrIndex = -1;
519+
so->firstCall = false;
520+
so->norderbys = scan->numberOfOrderBys;
516521

517522
/*
518523
* Allocate all the scan key information in the key context. (If

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy