@@ -31,6 +31,34 @@ static void insertScanItem(RumScanOpaque so, bool recheck);
31
31
static int scan_entry_cmp (const void * p1 , const void * p2 , void * arg );
32
32
static void entryGetItem (RumState * rumstate , RumScanEntry entry , bool * nextEntryList );
33
33
34
+ /*
35
+ * Extract key value for ordering.
36
+ *
37
+ * XXX FIXME only pass-by-value!!! Value should be copied to
38
+ * long-lived memory context and, somehow, freeed. Seems, the
39
+ * last is real problem.
40
+ */
41
+ #define SCAN_ENTRY_GET_KEY (entry , rumstate , itup ) \
42
+ do { \
43
+ if ((entry)->useCurKey) \
44
+ (entry)->curKey = rumtuple_get_key(rumstate, itup, &(entry)->curKeyCategory); \
45
+ } while(0)
46
+
47
+ /*
48
+ * Assign key value for ordering.
49
+ *
50
+ * XXX FIXME only pass-by-value!!! Value should be copied to
51
+ * long-lived memory context and, somehow, freeed. Seems, the
52
+ * last is real problem.
53
+ */
54
+ #define SCAN_ITEM_PUT_KEY (entry , item , key , category ) \
55
+ do { \
56
+ if ((entry)->useCurKey) \
57
+ { \
58
+ (item).keyValue = key; \
59
+ (item).keyCategory = category; \
60
+ } \
61
+ } while(0)
34
62
35
63
static bool
36
64
callAddInfoConsistentFn (RumState * rumstate , RumScanKey key )
@@ -151,23 +179,6 @@ callConsistentFn(RumState * rumstate, RumScanKey key)
151
179
return res && callAddInfoConsistentFn (rumstate , key );
152
180
}
153
181
154
- /*
155
- * Extract key value for ordering
156
- */
157
- static void
158
- scanEntryGetKey (RumScanEntry entry , RumState * rumstate , IndexTuple itup )
159
- {
160
- if (entry -> useCurKey == false)
161
- return ;
162
-
163
- /*
164
- * XXX FIXME only pass-by-value!!! Value should be copied to
165
- * long-lived memory context and, somehow, freeed. Seems, the
166
- * last is real problem.
167
- */
168
- entry -> curKey = rumtuple_get_key (rumstate , itup , & entry -> curKeyCategory );
169
- }
170
-
171
182
/*
172
183
* Goes to the next page if current offset is outside of bounds
173
184
*/
@@ -199,7 +210,8 @@ moveRightIfItNeeded(RumBtreeData * btree, RumBtreeStack * stack)
199
210
*/
200
211
static void
201
212
scanPostingTree (Relation index , RumScanEntry scanEntry ,
202
- BlockNumber rootPostingTree , OffsetNumber attnum , RumState * rumstate )
213
+ BlockNumber rootPostingTree , OffsetNumber attnum ,
214
+ RumState * rumstate , Datum idatum , RumNullCategory icategory )
203
215
{
204
216
RumPostingTreeScan * gdi ;
205
217
Buffer buffer ;
@@ -230,15 +242,16 @@ scanPostingTree(Relation index, RumScanEntry scanEntry,
230
242
if ((RumPageGetOpaque (page )-> flags & RUM_DELETED ) == 0 &&
231
243
maxoff >= FirstOffsetNumber )
232
244
{
233
- RumItem item ;
245
+ RumScanItem item ;
234
246
Pointer ptr ;
235
247
236
- ItemPointerSetMin (& item .iptr );
248
+ ItemPointerSetMin (& item .item . iptr );
237
249
238
250
ptr = RumDataPageGetData (page );
239
251
for (i = FirstOffsetNumber ; i <= maxoff ; i ++ )
240
252
{
241
- ptr = rumDataPageLeafRead (ptr , attnum , & item , rumstate );
253
+ ptr = rumDataPageLeafRead (ptr , attnum , & item .item , rumstate );
254
+ SCAN_ITEM_PUT_KEY (scanEntry , item , idatum , icategory );
242
255
rum_tuplesort_putrumitem (scanEntry -> matchSortstate , & item );
243
256
}
244
257
@@ -387,7 +400,8 @@ collectMatchBitmap(RumBtreeData * btree, RumBtreeStack * stack,
387
400
LockBuffer (stack -> buffer , RUM_UNLOCK );
388
401
389
402
/* Collect all the TIDs in this entry's posting tree */
390
- scanPostingTree (btree -> index , scanEntry , rootPostingTree , attnum , rumstate );
403
+ scanPostingTree (btree -> index , scanEntry , rootPostingTree , attnum ,
404
+ rumstate , idatum , icategory );
391
405
392
406
/*
393
407
* We lock again the entry page and while it was unlocked insert
@@ -437,13 +451,14 @@ collectMatchBitmap(RumBtreeData * btree, RumBtreeStack * stack,
437
451
{
438
452
int i ;
439
453
char * ptr = RumGetPosting (itup );
440
- RumItem item ;
454
+ RumScanItem item ;
441
455
442
- ItemPointerSetMin (& item .iptr );
456
+ ItemPointerSetMin (& item .item . iptr );
443
457
for (i = 0 ; i < RumGetNPosting (itup ); i ++ )
444
458
{
445
- ptr = rumDataPageLeafRead (ptr , scanEntry -> attnum , & item ,
459
+ ptr = rumDataPageLeafRead (ptr , scanEntry -> attnum , & item . item ,
446
460
rumstate );
461
+ SCAN_ITEM_PUT_KEY (scanEntry , item , idatum , icategory );
447
462
rum_tuplesort_putrumitem (scanEntry -> matchSortstate , & item );
448
463
}
449
464
@@ -576,7 +591,7 @@ startScanEntry(RumState * rumstate, RumScanEntry entry)
576
591
if (entry -> matchSortstate )
577
592
{
578
593
rum_tuplesort_performsort (entry -> matchSortstate );
579
- ItemPointerSetMin (& entry -> collectRumItem .iptr );
594
+ ItemPointerSetMin (& entry -> collectRumItem .item . iptr );
580
595
entry -> isFinished = FALSE;
581
596
}
582
597
}
@@ -659,7 +674,7 @@ startScanEntry(RumState * rumstate, RumScanEntry entry)
659
674
entry -> scanWithAddInfo )
660
675
entry -> stack = stackEntry ;
661
676
662
- scanEntryGetKey (entry , rumstate , itup );
677
+ SCAN_ENTRY_GET_KEY (entry , rumstate , itup );
663
678
}
664
679
665
680
if (needUnlock )
@@ -1066,7 +1081,7 @@ entryGetNextItemList(RumState * rumstate, RumScanEntry entry)
1066
1081
entry -> curItem = entry -> list [entry -> offset ];
1067
1082
entry -> offset += entry -> scanDirection ;
1068
1083
1069
- scanEntryGetKey (entry , rumstate , itup );
1084
+ SCAN_ENTRY_GET_KEY (entry , rumstate , itup );
1070
1085
1071
1086
/*
1072
1087
* Done with this entry, go to the next for the future.
@@ -1102,11 +1117,11 @@ entryGetItem(RumState * rumstate, RumScanEntry entry, bool *nextEntryList)
1102
1117
1103
1118
do
1104
1119
{
1105
- RumItem collected ;
1106
- RumItem * current_collected ;
1120
+ RumScanItem collected ;
1121
+ RumScanItem * current_collected ;
1107
1122
1108
1123
/* We are finished, but should return last result */
1109
- if (ItemPointerIsMax (& entry -> collectRumItem .iptr ))
1124
+ if (ItemPointerIsMax (& entry -> collectRumItem .item . iptr ))
1110
1125
{
1111
1126
entry -> isFinished = TRUE;
1112
1127
rum_tuplesort_end (entry -> matchSortstate );
@@ -1115,10 +1130,10 @@ entryGetItem(RumState * rumstate, RumScanEntry entry, bool *nextEntryList)
1115
1130
}
1116
1131
1117
1132
/* collectRumItem could store the begining of current result */
1118
- if (!ItemPointerIsMin (& entry -> collectRumItem .iptr ))
1133
+ if (!ItemPointerIsMin (& entry -> collectRumItem .item . iptr ))
1119
1134
collected = entry -> collectRumItem ;
1120
1135
else
1121
- ItemPointerSetMin (& collected .iptr );
1136
+ ItemPointerSetMin (& collected .item . iptr );
1122
1137
1123
1138
ItemPointerSetMin (& entry -> curItem .iptr );
1124
1139
@@ -1133,60 +1148,76 @@ entryGetItem(RumState * rumstate, RumScanEntry entry, bool *nextEntryList)
1133
1148
1134
1149
if (current_collected == NULL )
1135
1150
{
1136
- entry -> curItem = collected ;
1151
+ entry -> curItem = collected .item ;
1152
+ if (entry -> useCurKey )
1153
+ {
1154
+ entry -> curKey = collected .keyValue ;
1155
+ entry -> curKeyCategory = collected .keyCategory ;
1156
+ }
1137
1157
break ;
1138
1158
}
1139
1159
1140
- if (ItemPointerIsMin (& collected .iptr ) ||
1141
- rumCompareItemPointers (& collected .iptr ,
1142
- & current_collected -> iptr ) == 0 )
1160
+ if (ItemPointerIsMin (& collected .item . iptr ) ||
1161
+ rumCompareItemPointers (& collected .item . iptr ,
1162
+ & current_collected -> item . iptr ) == 0 )
1143
1163
{
1144
1164
Datum joinedAddInfo = (Datum )0 ;
1145
1165
bool joinedAddInfoIsNull ;
1146
1166
1147
- if (ItemPointerIsMin (& collected .iptr ))
1167
+ if (ItemPointerIsMin (& collected .item . iptr ))
1148
1168
{
1149
1169
joinedAddInfoIsNull = true; /* will change later */
1150
- collected .addInfoIsNull = true;
1170
+ collected .item . addInfoIsNull = true;
1151
1171
}
1152
1172
else
1153
- joinedAddInfoIsNull = collected .addInfoIsNull ||
1154
- current_collected -> addInfoIsNull ;
1173
+ joinedAddInfoIsNull = collected .item . addInfoIsNull ||
1174
+ current_collected -> item . addInfoIsNull ;
1155
1175
1156
1176
if (joinedAddInfoIsNull )
1157
1177
{
1158
1178
joinedAddInfoIsNull =
1159
- (collected .addInfoIsNull && current_collected -> addInfoIsNull );
1179
+ (collected .item .addInfoIsNull &&
1180
+ current_collected -> item .addInfoIsNull );
1160
1181
1161
- if (collected .addInfoIsNull == false)
1162
- joinedAddInfo = collected .addInfo ;
1163
- else if (current_collected -> addInfoIsNull == false)
1164
- joinedAddInfo = current_collected -> addInfo ;
1182
+ if (collected .item . addInfoIsNull == false)
1183
+ joinedAddInfo = collected .item . addInfo ;
1184
+ else if (current_collected -> item . addInfoIsNull == false)
1185
+ joinedAddInfo = current_collected -> item . addInfo ;
1165
1186
}
1166
1187
else if (rumstate -> canJoinAddInfo [entry -> attnumOrig - 1 ])
1167
1188
{
1168
1189
joinedAddInfo =
1169
1190
FunctionCall2 (
1170
1191
& rumstate -> joinAddInfoFn [entry -> attnumOrig - 1 ],
1171
- collected .addInfo ,
1172
- current_collected -> addInfo );
1192
+ collected .item . addInfo ,
1193
+ current_collected -> item . addInfo );
1173
1194
}
1174
1195
else
1175
1196
{
1176
- joinedAddInfo = current_collected -> addInfo ;
1197
+ joinedAddInfo = current_collected -> item . addInfo ;
1177
1198
}
1178
1199
1179
- collected .iptr = current_collected -> iptr ;
1180
- collected .addInfoIsNull = joinedAddInfoIsNull ;
1181
- collected .addInfo = joinedAddInfo ;
1200
+ collected .item .iptr = current_collected -> item .iptr ;
1201
+ collected .item .addInfoIsNull = joinedAddInfoIsNull ;
1202
+ collected .item .addInfo = joinedAddInfo ;
1203
+ if (entry -> useCurKey )
1204
+ {
1205
+ collected .keyValue = current_collected -> keyValue ;
1206
+ collected .keyCategory = current_collected -> keyCategory ;
1207
+ }
1182
1208
1183
1209
if (should_free )
1184
1210
pfree (current_collected );
1185
1211
}
1186
1212
else
1187
1213
{
1188
- entry -> curItem = collected ;
1214
+ entry -> curItem = collected . item ;
1189
1215
entry -> collectRumItem = * current_collected ;
1216
+ if (entry -> useCurKey )
1217
+ {
1218
+ entry -> curKey = collected .keyValue ;
1219
+ entry -> curKeyCategory = collected .keyCategory ;
1220
+ }
1190
1221
if (should_free )
1191
1222
pfree (current_collected );
1192
1223
break ;
@@ -1196,7 +1227,7 @@ entryGetItem(RumState * rumstate, RumScanEntry entry, bool *nextEntryList)
1196
1227
if (current_collected == NULL )
1197
1228
{
1198
1229
/* mark next call as last */
1199
- ItemPointerSetMax (& entry -> collectRumItem .iptr );
1230
+ ItemPointerSetMax (& entry -> collectRumItem .item . iptr );
1200
1231
1201
1232
/* even current call is last */
1202
1233
if (ItemPointerIsMin (& entry -> curItem .iptr ))
0 commit comments