Skip to content

Commit 440165f

Browse files
committed
Merge commit '10e2ea6720a55713e8fbd9ae31753863b741c763' into PGPROEE9_6
Updates RUM to actualk version Conflicts: contrib/rum/Makefile contrib/rum/src/rum.h contrib/rum/src/rumdatapage.c contrib/rum/src/rumget.c contrib/rum/tests/pglist_tests.py
2 parents 66579d7 + 10e2ea6 commit 440165f

File tree

15 files changed

+372
-358
lines changed

15 files changed

+372
-358
lines changed

contrib/rum/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ endif
3535
wal-check: temp-install
3636
$(prove_check)
3737

38+
all: rum--1.1.sql
39+
40+
#9.6 requires 1.1 file but 10.0 could live with 1.0 + 1.0-1.1 files
41+
rum--1.1.sql: rum--1.0.sql rum--1.0--1.1.sql
42+
cat rum--1.0.sql rum--1.0--1.1.sql > rum--1.1.sql
43+
44+
rum--1.0--1.1.sql: Makefile gen_rum_sql--1.0--1.1.pl
45+
perl gen_rum_sql--1.0--1.1.pl > rum--1.0--1.1.sql
46+
3847
install: installincludes
3948

4049
installincludes:

contrib/rum/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,21 @@ SELECT t, a <=> to_tsquery('english', 'beautiful | place') AS rank
106106
FROM test_rum
107107
WHERE a @@ to_tsquery('english', 'beautiful | place')
108108
ORDER BY a <=> to_tsquery('english', 'beautiful | place');
109-
t | rank
110-
---------------------------------+-----------
111-
The situation is most beautiful | 0.0303964
112-
It is a beautiful | 0.0303964
113-
It looks like a beautiful place | 0.0607927
109+
t | rank
110+
---------------------------------+---------
111+
It looks like a beautiful place | 8.22467
112+
The situation is most beautiful | 16.4493
113+
It is a beautiful | 16.4493
114114
(3 rows)
115115

116116
SELECT t, a <=> to_tsquery('english', 'place | situation') AS rank
117117
FROM test_rum
118118
WHERE a @@ to_tsquery('english', 'place | situation')
119119
ORDER BY a <=> to_tsquery('english', 'place | situation');
120-
t | rank
121-
---------------------------------+-----------
122-
The situation is most beautiful | 0.0303964
123-
It looks like a beautiful place | 0.0303964
120+
t | rank
121+
---------------------------------+---------
122+
The situation is most beautiful | 16.4493
123+
It looks like a beautiful place | 16.4493
124124
(2 rows)
125125
```
126126

contrib/rum/src/rum.h

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ typedef struct RumMetaPageData
164164
(RumItemPointerGetOffsetNumber(p) == (OffsetNumber)0xffff && \
165165
RumItemPointerGetBlockNumber(p) != InvalidBlockNumber)
166166

167-
typedef struct RumKey
167+
typedef struct RumItem
168168
{
169169
ItemPointerData iptr;
170170
bool addInfoIsNull;
171171
Datum addInfo;
172-
} RumKey;
172+
} RumItem;
173173

174174
#define RumItemSetMin(item) \
175175
do { \
@@ -185,7 +185,7 @@ typedef struct
185185
{
186186
/* We use BlockIdData not BlockNumber to avoid padding space wastage */
187187
BlockIdData child_blkno;
188-
RumKey key;
188+
RumItem item;
189189
} PostingItem;
190190

191191
#define PostingItemGetBlockNumber(pointer) \
@@ -262,21 +262,21 @@ typedef signed char RumNullCategory;
262262
/*
263263
* Data (posting tree) pages
264264
*/
265-
#define RumDataPageGetRightBound(page) ((RumKey*) PageGetContents(page))
265+
#define RumDataPageGetRightBound(page) ((RumItem*) PageGetContents(page))
266266
#define RumDataPageGetData(page) \
267-
(PageGetContents(page) + MAXALIGN(sizeof(RumKey)))
267+
(PageGetContents(page) + MAXALIGN(sizeof(RumItem)))
268268
#define RumDataPageGetItem(page,i) \
269269
(RumDataPageGetData(page) + ((i)-1) * sizeof(PostingItem))
270270

271271
#define RumDataPageGetFreeSpace(page) \
272272
(BLCKSZ - MAXALIGN(SizeOfPageHeaderData) \
273-
- MAXALIGN(sizeof(RumKey)) /* right bound */ \
273+
- MAXALIGN(sizeof(RumItem)) /* right bound */ \
274274
- RumPageGetOpaque(page)->maxoff * sizeof(PostingItem) \
275275
- MAXALIGN(sizeof(RumPageOpaqueData)))
276276

277277
#define RumMaxLeafDataItems \
278278
((BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - \
279-
MAXALIGN(sizeof(RumKey)) /* right bound */ - \
279+
MAXALIGN(sizeof(RumItem)) /* right bound */ - \
280280
MAXALIGN(sizeof(RumPageOpaqueData))) \
281281
/ sizeof(ItemPointerData))
282282

@@ -298,7 +298,7 @@ typedef struct
298298

299299
#define RumDataPageSize \
300300
(BLCKSZ - MAXALIGN(SizeOfPageHeaderData) \
301-
- MAXALIGN(sizeof(RumKey)) /* right bound */ \
301+
- MAXALIGN(sizeof(RumItem)) /* right bound */ \
302302
- MAXALIGN(sizeof(RumPageOpaqueData)) \
303303
- MAXALIGN(sizeof(RumDataLeafItemIndex) * RumDataLeafIndexCount))
304304

@@ -433,7 +433,7 @@ extern bool ruminsert(Relation index, Datum *values, bool *isnull,
433433
);
434434
extern void rumEntryInsert(RumState * rumstate,
435435
OffsetNumber attnum, Datum key, RumNullCategory category,
436-
RumKey * items, uint32 nitem, GinStatsData *buildStats);
436+
RumItem * items, uint32 nitem, GinStatsData *buildStats);
437437

438438
/* rumbtree.c */
439439

@@ -483,7 +483,7 @@ typedef struct RumBtreeData
483483
bool isDelete;
484484

485485
/* Data (posting tree) options */
486-
RumKey *items;
486+
RumItem *items;
487487

488488
uint32 nitem;
489489
uint32 curitem;
@@ -509,25 +509,25 @@ extern void rumEntryFillRoot(RumBtree btree, Buffer root, Buffer lbuf, Buffer rb
509509
Page page, Page lpage, Page rpage);
510510
extern IndexTuple rumPageGetLinkItup(RumBtree btree, Buffer buf, Page page);
511511
extern void rumReadTuple(RumState * rumstate, OffsetNumber attnum,
512-
IndexTuple itup, RumKey * items);
512+
IndexTuple itup, RumItem * items);
513513
extern void rumReadTuplePointers(RumState * rumstate, OffsetNumber attnum,
514514
IndexTuple itup, ItemPointerData *ipd);
515515
extern void updateItemIndexes(Page page, OffsetNumber attnum, RumState * rumstate);
516516
extern void checkLeafDataPage(RumState * rumstate, AttrNumber attrnum, Page page);
517517

518518
/* rumdatapage.c */
519519
extern int rumCompareItemPointers(const ItemPointerData *a, const ItemPointerData *b);
520-
extern int compareRumKey(RumState * state, const AttrNumber attno,
521-
const RumKey * a, const RumKey * b);
522-
extern void convertIndexToKey(RumDataLeafItemIndex *src, RumKey *dst);
520+
extern int compareRumItem(RumState * state, const AttrNumber attno,
521+
const RumItem * a, const RumItem * b);
522+
extern void convertIndexToKey(RumDataLeafItemIndex *src, RumItem *dst);
523523
extern Pointer rumPlaceToDataPageLeaf(Pointer ptr, OffsetNumber attnum,
524-
RumKey * item, ItemPointer prev, RumState * rumstate);
524+
RumItem * item, ItemPointer prev, RumState * rumstate);
525525
extern Size rumCheckPlaceToDataPageLeaf(OffsetNumber attnum,
526-
RumKey * item, ItemPointer prev, RumState * rumstate, Size size);
527-
extern uint32 rumMergeItemPointers(RumState * rumstate, AttrNumber attno,
528-
RumKey * dst,
529-
RumKey * a, uint32 na,
530-
RumKey * b, uint32 nb);
526+
RumItem * item, ItemPointer prev, RumState * rumstate, Size size);
527+
extern uint32 rumMergeRumItems(RumState * rumstate, AttrNumber attno,
528+
RumItem * dst,
529+
RumItem * a, uint32 na,
530+
RumItem * b, uint32 nb);
531531
extern void RumDataPageAddItem(Page page, void *data, OffsetNumber offset);
532532
extern void RumPageDeletePostingItem(Page page, OffsetNumber offset);
533533

@@ -544,9 +544,9 @@ extern RumPostingTreeScan *rumPrepareScanPostingTree(Relation index,
544544
extern void rumInsertItemPointers(RumState * rumstate,
545545
OffsetNumber attnum,
546546
RumPostingTreeScan * gdi,
547-
RumKey * items, uint32 nitem,
547+
RumItem * items, uint32 nitem,
548548
GinStatsData *buildStats);
549-
extern Buffer rumScanBeginPostingTree(RumPostingTreeScan * gdi, RumKey *key);
549+
extern Buffer rumScanBeginPostingTree(RumPostingTreeScan * gdi, RumItem *item);
550550
extern void rumDataFillRoot(RumBtree btree, Buffer root, Buffer lbuf, Buffer rbuf,
551551
Page page, Page lpage, Page rpage);
552552
extern void rumPrepareDataScan(RumBtree btree, Relation index, OffsetNumber attnum, RumState * rumstate);
@@ -584,8 +584,10 @@ typedef struct RumScanKeyData
584584

585585
/* array of check flags, reported to consistentFn */
586586
bool *entryRes;
587+
/* array of additional information, used in consistentFn and orderingFn */
587588
Datum *addInfo;
588589
bool *addInfoIsNull;
590+
/* additional information, used in outerOrderingFn */
589591
bool useAddToColumn;
590592
Datum outerAddInfo;
591593
bool outerAddInfoIsNull;
@@ -608,15 +610,16 @@ typedef struct RumScanKeyData
608610
* isFinished means that all the input entry streams are finished, so this
609611
* key cannot succeed for any later TIDs.
610612
*/
611-
RumKey curItem;
613+
RumItem curItem;
612614
bool curItemMatches;
613615
bool recheckCurItem;
614616
bool isFinished;
615617
bool orderBy;
616618
bool willSort; /* just a copy of RumScanOpaqueData.willSort */
617619
ScanDirection scanDirection;
618620

619-
RumScanKey *addInfoKeys;
621+
/* array of keys, used to scan using additional information as keys */
622+
RumScanKey *addInfoKeys;
620623
int addInfoNKeys;
621624
} RumScanKeyData;
622625

@@ -636,34 +639,38 @@ typedef struct RumScanEntryData
636639
Buffer buffer;
637640

638641
/* current ItemPointer to heap */
639-
RumKey curRumKey;
642+
RumItem curItem;
640643

641-
/* for a partial-match or full-scan query, we accumulate all TIDs here */
642-
bool forceUseBitmap;
643-
/* or here if we need to store addinfo */
644+
/*
645+
* For a partial-match or full-scan query, we accumulate all TIDs and
646+
* and additional information here
647+
*/
644648
Tuplesortstate *matchSortstate;
645-
RumKey collectRumKey;
649+
RumItem collectRumItem;
646650

647651
/* for full-scan query with order-by */
648652
RumBtreeStack *stack;
649653
bool scanWithAddInfo;
650654

651655
/* used for Posting list and one page in Posting tree */
652-
RumKey *list;
653-
MemoryContext context;
656+
RumItem *list;
654657
int16 nlist;
655658
int16 offset;
656659

657-
ScanDirection scanDirection;
660+
ScanDirection scanDirection;
658661
bool isFinished;
659662
bool reduceResult;
660-
bool preValue;
661663
uint32 predictNumberResult;
664+
665+
/* used to scan posting tree */
662666
RumPostingTreeScan *gdi;
663667

668+
/* used in fast scan in addition to preConsistentFn */
669+
bool preValue;
670+
664671
/* Find by AddInfo */
665672
bool useMarkAddInfo;
666-
RumKey markAddInfo;
673+
RumItem markAddInfo;
667674
} RumScanEntryData;
668675

669676
typedef struct
@@ -682,28 +689,32 @@ typedef enum
682689

683690
typedef struct RumScanOpaqueData
684691
{
692+
/* tempCtx is used to hold consistent and ordering functions data */
685693
MemoryContext tempCtx;
686-
MemoryContext keyCtx; /* used to hold key and entry data */
694+
/* keyCtx is used to hold key and entry data */
695+
MemoryContext keyCtx;
687696
RumState rumstate;
688697

689-
RumScanKey *keys; /* one per scan qualifier expr */
698+
RumScanKey *keys; /* one per scan qualifier expr */
690699
uint32 nkeys;
691-
int norderbys;
692700

693-
RumScanEntry *entries; /* one per index search condition */
694-
RumScanEntry *sortedEntries; /* one per index search condition */
695-
int entriesIncrIndex;
701+
RumScanEntry *entries; /* one per index search condition */
702+
RumScanEntry *sortedEntries; /* Sorted entries. Used in fast scan */
703+
int entriesIncrIndex; /* used in fast scan */
696704
uint32 totalentries;
697-
uint32 allocentries; /* allocated length of entries[] */
705+
uint32 allocentries; /* allocated length of entries[] and
706+
sortedEntries[] */
698707

699708
Tuplesortstate *sortstate;
709+
int norderbys; /* Number of columns in ordering.
710+
Will be assigned to sortstate->nKeys */
700711

701-
RumKey key;
712+
RumItem item; /* current item used in index scan */
702713
bool firstCall;
714+
703715
bool isVoidRes; /* true if query is unsatisfiable */
704-
bool willSort;
716+
bool willSort; /* is there any columns in ordering */
705717
RumScanType scanType;
706-
TIDBitmap *tbm;
707718

708719
ScanDirection naturalOrder;
709720
bool secondPass;
@@ -742,7 +753,7 @@ typedef struct RumEntryAccumulator
742753
RumNullCategory category;
743754
OffsetNumber attnum;
744755
bool shouldSort;
745-
RumKey *list;
756+
RumItem *list;
746757
uint32 maxcount; /* allocated size of list[] */
747758
uint32 count; /* current number of list[] entries */
748759
} RumEntryAccumulator;
@@ -757,7 +768,7 @@ typedef struct
757768
#if PG_VERSION_NUM >= 100000
758769
RBTreeIterator tree_walk;
759770
#endif
760-
RumKey *sortSpace;
771+
RumItem *sortSpace;
761772
uint32 sortSpaceN;
762773
} BuildAccumulator;
763774

@@ -767,7 +778,7 @@ extern void rumInsertBAEntries(BuildAccumulator *accum,
767778
Datum *entries, Datum *addInfo, bool *addInfoIsNull,
768779
RumNullCategory * categories, int32 nentries);
769780
extern void rumBeginBAScan(BuildAccumulator *accum);
770-
extern RumKey *rumGetBAEntry(BuildAccumulator *accum,
781+
extern RumItem *rumGetBAEntry(BuildAccumulator *accum,
771782
OffsetNumber *attnum, Datum *key, RumNullCategory * category,
772783
uint32 *n);
773784

@@ -869,7 +880,7 @@ rumDataPageLeafReadItemPointer(char *ptr, ItemPointer iptr, bool *addInfoIsNull)
869880
* passed in order to read the first item pointer.
870881
*/
871882
static inline Pointer
872-
rumDataPageLeafRead(Pointer ptr, OffsetNumber attnum, RumKey * item,
883+
rumDataPageLeafRead(Pointer ptr, OffsetNumber attnum, RumItem * item,
873884
RumState * rumstate)
874885
{
875886
Form_pg_attribute attr;
@@ -950,7 +961,7 @@ rumDataPageLeafRead(Pointer ptr, OffsetNumber attnum, RumKey * item,
950961
* passed in order to read the first item pointer.
951962
*/
952963
static inline Pointer
953-
rumDataPageLeafReadPointer(Pointer ptr, OffsetNumber attnum, RumKey * item,
964+
rumDataPageLeafReadPointer(Pointer ptr, OffsetNumber attnum, RumItem * item,
954965
RumState * rumstate)
955966
{
956967
Form_pg_attribute attr;

contrib/rum/src/rumbtree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ rumReFindLeafPage(RumBtree btree, RumBtreeStack * stack)
100100
* that requested leaf page is in this subtree only when requested
101101
* item pointer is less than item pointer previous to rightmost.
102102
*/
103-
if (compareRumKey(btree->rumstate, btree->entryAttnum,
104-
&(((PostingItem *) RumDataPageGetItem(page, maxoff - 1))->key),
103+
if (compareRumItem(btree->rumstate, btree->entryAttnum,
104+
&(((PostingItem *) RumDataPageGetItem(page, maxoff - 1))->item),
105105
&btree->items[btree->curitem]) >= 0)
106106
{
107107
break;

0 commit comments

Comments
 (0)