@@ -281,7 +281,7 @@ rumCheckPlaceToDataPageLeaf(OffsetNumber attnum,
281
281
}
282
282
283
283
int
284
- rumCompareItemPointers (ItemPointer a ,ItemPointer b )
284
+ rumCompareItemPointers (const ItemPointerData * a ,const ItemPointerData * b )
285
285
{
286
286
BlockNumber ba = RumItemPointerGetBlockNumber (a );
287
287
BlockNumber bb = RumItemPointerGetBlockNumber (b );
@@ -300,39 +300,36 @@ rumCompareItemPointers(ItemPointer a, ItemPointer b)
300
300
}
301
301
302
302
int
303
- compareRumKey (RumState * state ,RumKey * a ,RumKey * b )
303
+ compareRumKey (RumState * state ,const RumKey * a ,const RumKey * b )
304
304
{
305
305
306
306
/* assume NULL is greate than any real value */
307
- if (state -> useAlternativeOrder )
307
+ if (a -> addInfoIsNull == false && b -> addInfoIsNull == false )
308
308
{
309
- if (a -> isNull == false&& b -> isNull == false)
310
- {
311
- int res ;
312
- AttrNumber attnum = state -> attrnOrderByColumn ;
313
-
314
- res = DatumGetInt32 (FunctionCall2Coll (
315
- & state -> compareFn [attnum - 1 ],
316
- state -> supportCollation [attnum - 1 ],
317
- a -> addToCompare ,b -> addToCompare ));
318
- if (res != 0 )
319
- return res ;
320
- /* fallback to ItemPointerCompare */
321
- }
322
- else if (a -> isNull == true)
323
- {
324
- if (b -> isNull == false)
325
- return 1 ;
326
- /* fallback to ItemPointerCompare */
327
- }
328
- else
329
- {
330
- Assert (b -> isNull == true);
331
- return -1 ;
332
- }
309
+ int res ;
310
+ AttrNumber attnum = state -> attrnOrderByColumn ;
311
+
312
+ res = DatumGetInt32 (FunctionCall2Coll (
313
+ & state -> compareFn [attnum - 1 ],
314
+ state -> supportCollation [attnum - 1 ],
315
+ a -> addInfo ,b -> addInfo ));
316
+ if (res != 0 )
317
+ return res ;
318
+ /* fallback to ItemPointerCompare */
319
+ }
320
+ else if (a -> addInfoIsNull == true)
321
+ {
322
+ if (b -> addInfoIsNull == false)
323
+ return 1 ;
324
+ /* fallback to ItemPointerCompare */
325
+ }
326
+ else
327
+ {
328
+ Assert (b -> addInfoIsNull == true);
329
+ return -1 ;
333
330
}
334
331
335
- return rumCompareItemPointers (& a -> ipd ,& b -> ipd );
332
+ return rumCompareItemPointers (& a -> iptr ,& b -> iptr );
336
333
}
337
334
338
335
/*
@@ -341,7 +338,8 @@ compareRumKey(RumState *state, RumKey *a, RumKey *b)
341
338
* Caller is responsible that there is enough space at *dst.
342
339
*/
343
340
uint32
344
- rumMergeItemPointers (ItemPointerData * dst ,Datum * dstAddInfo ,bool * dstAddInfoIsNull ,
341
+ rumMergeItemPointers (RumState * rumstate ,
342
+ ItemPointerData * dst ,Datum * dstAddInfo ,bool * dstAddInfoIsNull ,
345
343
ItemPointerData * a ,Datum * aAddInfo ,bool * aAddInfoIsNull ,uint32 na ,
346
344
ItemPointerData * b ,Datum * bAddInfo ,bool * bAddInfoIsNull ,uint32 nb )
347
345
{
@@ -351,7 +349,25 @@ rumMergeItemPointers(ItemPointerData *dst, Datum *dstAddInfo, bool *dstAddInfoIs
351
349
352
350
while (aptr - a < na && bptr - b < nb )
353
351
{
354
- int cmp = rumCompareItemPointers (aptr ,bptr );
352
+ int cmp ;
353
+
354
+ if (rumstate -> useAlternativeOrder )
355
+ {
356
+ RumKey a ,b ;
357
+
358
+ a .iptr = * aptr ;
359
+ a .addInfoIsNull = * aAddInfoIsNull ;
360
+ a .addInfo = * aAddInfo ;
361
+ b .iptr = * bptr ;
362
+ b .addInfoIsNull = * bAddInfoIsNull ;
363
+ b .addInfo = * bAddInfo ;
364
+
365
+ cmp = compareRumKey (rumstate ,& a ,& b );
366
+ }
367
+ else
368
+ {
369
+ cmp = rumCompareItemPointers (aptr ,bptr );
370
+ }
355
371
356
372
if (cmp > 0 )
357
373
{