@@ -164,12 +164,12 @@ typedef struct RumMetaPageData
164
164
(RumItemPointerGetOffsetNumber(p) == (OffsetNumber)0xffff && \
165
165
RumItemPointerGetBlockNumber(p) != InvalidBlockNumber)
166
166
167
- typedef struct RumKey
167
+ typedef struct RumItem
168
168
{
169
169
ItemPointerData iptr ;
170
170
bool addInfoIsNull ;
171
171
Datum addInfo ;
172
- }RumKey ;
172
+ }RumItem ;
173
173
174
174
#define RumItemSetMin (item ) \
175
175
do { \
@@ -185,7 +185,7 @@ typedef struct
185
185
{
186
186
/* We use BlockIdData not BlockNumber to avoid padding space wastage */
187
187
BlockIdData child_blkno ;
188
- RumKey key ;
188
+ RumItem item ;
189
189
}PostingItem ;
190
190
191
191
#define PostingItemGetBlockNumber (pointer ) \
@@ -262,21 +262,21 @@ typedef signed char RumNullCategory;
262
262
/*
263
263
* Data (posting tree) pages
264
264
*/
265
- #define RumDataPageGetRightBound (page )((RumKey *) PageGetContents(page))
265
+ #define RumDataPageGetRightBound (page )((RumItem *) PageGetContents(page))
266
266
#define RumDataPageGetData (page )\
267
- (PageGetContents(page) + MAXALIGN(sizeof(RumKey )))
267
+ (PageGetContents(page) + MAXALIGN(sizeof(RumItem )))
268
268
#define RumDataPageGetItem (page ,i )\
269
269
(RumDataPageGetData(page) + ((i)-1) * sizeof(PostingItem))
270
270
271
271
#define RumDataPageGetFreeSpace (page )\
272
272
(BLCKSZ - MAXALIGN(SizeOfPageHeaderData) \
273
- - MAXALIGN(sizeof(RumKey ))/* right bound */ \
273
+ - MAXALIGN(sizeof(RumItem ))/* right bound */ \
274
274
- RumPageGetOpaque (page )-> maxoff * sizeof (PostingItem ) \
275
275
- MAXALIGN (sizeof (RumPageOpaqueData )))
276
276
277
277
#define RumMaxLeafDataItems \
278
278
((BLCKSZ - MAXALIGN(SizeOfPageHeaderData) - \
279
- MAXALIGN(sizeof(RumKey ))/* right bound */ - \
279
+ MAXALIGN(sizeof(RumItem ))/* right bound */ - \
280
280
MAXALIGN (sizeof (RumPageOpaqueData ))) \
281
281
/sizeof (ItemPointerData ))
282
282
@@ -298,7 +298,7 @@ typedef struct
298
298
299
299
#define RumDataPageSize \
300
300
(BLCKSZ - MAXALIGN(SizeOfPageHeaderData) \
301
- - MAXALIGN(sizeof(RumKey ))/* right bound */ \
301
+ - MAXALIGN(sizeof(RumItem ))/* right bound */ \
302
302
- MAXALIGN (sizeof (RumPageOpaqueData )) \
303
303
- MAXALIGN (sizeof (RumDataLeafItemIndex )* RumDataLeafIndexCount ))
304
304
@@ -433,7 +433,7 @@ extern bool ruminsert(Relation index, Datum *values, bool *isnull,
433
433
);
434
434
extern void rumEntryInsert (RumState * rumstate ,
435
435
OffsetNumber attnum ,Datum key ,RumNullCategory category ,
436
- RumKey * items ,uint32 nitem ,GinStatsData * buildStats );
436
+ RumItem * items ,uint32 nitem ,GinStatsData * buildStats );
437
437
438
438
/* rumbtree.c */
439
439
@@ -483,7 +483,7 @@ typedef struct RumBtreeData
483
483
bool isDelete ;
484
484
485
485
/* Data (posting tree) options */
486
- RumKey * items ;
486
+ RumItem * items ;
487
487
488
488
uint32 nitem ;
489
489
uint32 curitem ;
@@ -509,25 +509,25 @@ extern void rumEntryFillRoot(RumBtree btree, Buffer root, Buffer lbuf, Buffer rb
509
509
Page page ,Page lpage ,Page rpage );
510
510
extern IndexTuple rumPageGetLinkItup (RumBtree btree ,Buffer buf ,Page page );
511
511
extern void rumReadTuple (RumState * rumstate ,OffsetNumber attnum ,
512
- IndexTuple itup ,RumKey * items );
512
+ IndexTuple itup ,RumItem * items );
513
513
extern void rumReadTuplePointers (RumState * rumstate ,OffsetNumber attnum ,
514
514
IndexTuple itup ,ItemPointerData * ipd );
515
515
extern void updateItemIndexes (Page page ,OffsetNumber attnum ,RumState * rumstate );
516
516
extern void checkLeafDataPage (RumState * rumstate ,AttrNumber attrnum ,Page page );
517
517
518
518
/* rumdatapage.c */
519
519
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 );
523
523
extern Pointer rumPlaceToDataPageLeaf (Pointer ptr ,OffsetNumber attnum ,
524
- RumKey * item ,ItemPointer prev ,RumState * rumstate );
524
+ RumItem * item ,ItemPointer prev ,RumState * rumstate );
525
525
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 );
531
531
extern void RumDataPageAddItem (Page page ,void * data ,OffsetNumber offset );
532
532
extern void RumPageDeletePostingItem (Page page ,OffsetNumber offset );
533
533
@@ -544,9 +544,9 @@ extern RumPostingTreeScan *rumPrepareScanPostingTree(Relation index,
544
544
extern void rumInsertItemPointers (RumState * rumstate ,
545
545
OffsetNumber attnum ,
546
546
RumPostingTreeScan * gdi ,
547
- RumKey * items ,uint32 nitem ,
547
+ RumItem * items ,uint32 nitem ,
548
548
GinStatsData * buildStats );
549
- extern Buffer rumScanBeginPostingTree (RumPostingTreeScan * gdi ,RumKey * key );
549
+ extern Buffer rumScanBeginPostingTree (RumPostingTreeScan * gdi ,RumItem * item );
550
550
extern void rumDataFillRoot (RumBtree btree ,Buffer root ,Buffer lbuf ,Buffer rbuf ,
551
551
Page page ,Page lpage ,Page rpage );
552
552
extern void rumPrepareDataScan (RumBtree btree ,Relation index ,OffsetNumber attnum ,RumState * rumstate );
@@ -584,8 +584,10 @@ typedef struct RumScanKeyData
584
584
585
585
/* array of check flags, reported to consistentFn */
586
586
bool * entryRes ;
587
+ /* array of additional information, used in consistentFn and orderingFn */
587
588
Datum * addInfo ;
588
589
bool * addInfoIsNull ;
590
+ /* additional information, used in outerOrderingFn */
589
591
bool useAddToColumn ;
590
592
Datum outerAddInfo ;
591
593
bool outerAddInfoIsNull ;
@@ -608,15 +610,16 @@ typedef struct RumScanKeyData
608
610
* isFinished means that all the input entry streams are finished, so this
609
611
* key cannot succeed for any later TIDs.
610
612
*/
611
- RumKey curItem ;
613
+ RumItem curItem ;
612
614
bool curItemMatches ;
613
615
bool recheckCurItem ;
614
616
bool isFinished ;
615
617
bool orderBy ;
616
618
bool willSort ;/* just a copy of RumScanOpaqueData.willSort */
617
619
ScanDirection scanDirection ;
618
620
619
- RumScanKey * addInfoKeys ;
621
+ /* array of keys, used to scan using additional information as keys */
622
+ RumScanKey * addInfoKeys ;
620
623
int addInfoNKeys ;
621
624
}RumScanKeyData ;
622
625
@@ -636,34 +639,38 @@ typedef struct RumScanEntryData
636
639
Buffer buffer ;
637
640
638
641
/* current ItemPointer to heap */
639
- RumKey curRumKey ;
642
+ RumItem curItem ;
640
643
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
+ */
644
648
Tuplesortstate * matchSortstate ;
645
- RumKey collectRumKey ;
649
+ RumItem collectRumItem ;
646
650
647
651
/* for full-scan query with order-by */
648
652
RumBtreeStack * stack ;
649
653
bool scanWithAddInfo ;
650
654
651
655
/* used for Posting list and one page in Posting tree */
652
- RumKey * list ;
653
- MemoryContext context ;
656
+ RumItem * list ;
654
657
int16 nlist ;
655
658
int16 offset ;
656
659
657
- ScanDirection scanDirection ;
660
+ ScanDirection scanDirection ;
658
661
bool isFinished ;
659
662
bool reduceResult ;
660
- bool preValue ;
661
663
uint32 predictNumberResult ;
664
+
665
+ /* used to scan posting tree */
662
666
RumPostingTreeScan * gdi ;
663
667
668
+ /* used in fast scan in addition to preConsistentFn */
669
+ bool preValue ;
670
+
664
671
/* Find by AddInfo */
665
672
bool useMarkAddInfo ;
666
- RumKey markAddInfo ;
673
+ RumItem markAddInfo ;
667
674
}RumScanEntryData ;
668
675
669
676
typedef struct
@@ -682,28 +689,32 @@ typedef enum
682
689
683
690
typedef struct RumScanOpaqueData
684
691
{
692
+ /* tempCtx is used to hold consistent and ordering functions data */
685
693
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 ;
687
696
RumState rumstate ;
688
697
689
- RumScanKey * keys ;/* one per scan qualifier expr */
698
+ RumScanKey * keys ;/* one per scan qualifier expr */
690
699
uint32 nkeys ;
691
- int norderbys ;
692
700
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 */
696
704
uint32 totalentries ;
697
- uint32 allocentries ;/* allocated length of entries[] */
705
+ uint32 allocentries ;/* allocated length of entries[] and
706
+ sortedEntries[] */
698
707
699
708
Tuplesortstate * sortstate ;
709
+ int norderbys ;/* Number of columns in ordering.
710
+ Will be assigned to sortstate->nKeys */
700
711
701
- RumKey key ;
712
+ RumItem item ; /* current item used in index scan */
702
713
bool firstCall ;
714
+
703
715
bool isVoidRes ;/* true if query is unsatisfiable */
704
- bool willSort ;
716
+ bool willSort ;/* is there any columns in ordering */
705
717
RumScanType scanType ;
706
- TIDBitmap * tbm ;
707
718
708
719
ScanDirection naturalOrder ;
709
720
bool secondPass ;
@@ -742,7 +753,7 @@ typedef struct RumEntryAccumulator
742
753
RumNullCategory category ;
743
754
OffsetNumber attnum ;
744
755
bool shouldSort ;
745
- RumKey * list ;
756
+ RumItem * list ;
746
757
uint32 maxcount ;/* allocated size of list[] */
747
758
uint32 count ;/* current number of list[] entries */
748
759
}RumEntryAccumulator ;
@@ -757,7 +768,7 @@ typedef struct
757
768
#if PG_VERSION_NUM >=100000
758
769
RBTreeIterator tree_walk ;
759
770
#endif
760
- RumKey * sortSpace ;
771
+ RumItem * sortSpace ;
761
772
uint32 sortSpaceN ;
762
773
}BuildAccumulator ;
763
774
@@ -767,7 +778,7 @@ extern void rumInsertBAEntries(BuildAccumulator *accum,
767
778
Datum * entries ,Datum * addInfo ,bool * addInfoIsNull ,
768
779
RumNullCategory * categories ,int32 nentries );
769
780
extern void rumBeginBAScan (BuildAccumulator * accum );
770
- extern RumKey * rumGetBAEntry (BuildAccumulator * accum ,
781
+ extern RumItem * rumGetBAEntry (BuildAccumulator * accum ,
771
782
OffsetNumber * attnum ,Datum * key ,RumNullCategory * category ,
772
783
uint32 * n );
773
784
@@ -869,7 +880,7 @@ rumDataPageLeafReadItemPointer(char *ptr, ItemPointer iptr, bool *addInfoIsNull)
869
880
* passed in order to read the first item pointer.
870
881
*/
871
882
static inline Pointer
872
- rumDataPageLeafRead (Pointer ptr ,OffsetNumber attnum ,RumKey * item ,
883
+ rumDataPageLeafRead (Pointer ptr ,OffsetNumber attnum ,RumItem * item ,
873
884
RumState * rumstate )
874
885
{
875
886
Form_pg_attribute attr ;
@@ -950,7 +961,7 @@ rumDataPageLeafRead(Pointer ptr, OffsetNumber attnum, RumKey * item,
950
961
* passed in order to read the first item pointer.
951
962
*/
952
963
static inline Pointer
953
- rumDataPageLeafReadPointer (Pointer ptr ,OffsetNumber attnum ,RumKey * item ,
964
+ rumDataPageLeafReadPointer (Pointer ptr ,OffsetNumber attnum ,RumItem * item ,
954
965
RumState * rumstate )
955
966
{
956
967
Form_pg_attribute attr ;