27
27
28
28
#include "rum.h" /* RumItem */
29
29
30
- #if PG_VERSION_NUM >= 150000
30
+ #if PG_VERSION_NUM >= 160000
31
+ #include "tuplesort16.c"
32
+ #undef TRACE_SORT
33
+ #elif PG_VERSION_NUM >= 150000
31
34
#include "tuplesort15.c"
32
35
#elif PG_VERSION_NUM >= 140000
33
36
#include "tuplesort14.c"
@@ -53,7 +56,6 @@ typedef struct RumTuplesortstateExt
53
56
FmgrInfo * cmp ;
54
57
} RumTuplesortstateExt ;
55
58
56
- static int compare_rum_itempointer (ItemPointerData p1 , ItemPointerData p2 );
57
59
static int comparetup_rum (const SortTuple * a , const SortTuple * b ,
58
60
RumTuplesortstate * state , bool compareItemPointer );
59
61
static int comparetup_rum_true (const SortTuple * a , const SortTuple * b ,
@@ -69,11 +71,19 @@ static void *rum_tuplesort_getrum_internal(RumTuplesortstate *state,
69
71
bool forward , bool * should_free );
70
72
71
73
#if PG_VERSION_NUM >= 160000
72
- # define TSS_GET (state ) \
73
- TuplesortstateGetPublic((state))
74
+ # define TSS_GET (state ) TuplesortstateGetPublic((state))
75
+ #else
76
+ # define TSS_GET (state ) (state)
77
+ #endif
78
+
79
+ #if PG_VERSION_NUM >= 150000
80
+ #define LT_TYPE LogicalTape *
81
+ #define LT_ARG tape
82
+ #define TAPE (state , LT_ARG ) LT_ARG
74
83
#else
75
- # define TSS_GET (state ) \
76
- (state)
84
+ #define LT_TYPE int
85
+ #define LT_ARG tapenum
86
+ #define TAPE (state , LT_ARG ) state->tapeset, LT_ARG
77
87
#endif
78
88
79
89
static inline int
@@ -152,12 +162,14 @@ comparetup_rumitem(const SortTuple *a, const SortTuple *b,
152
162
{
153
163
RumItem * i1 ,
154
164
* i2 ;
165
+ FmgrInfo * cmp ;
155
166
156
167
/* Extract RumItem from RumScanItem */
157
168
i1 = (RumItem * ) a -> tuple ;
158
169
i2 = (RumItem * ) b -> tuple ;
159
170
160
- if (((RumTuplesortstateExt * ) state )-> cmp )
171
+ cmp = ((RumTuplesortstateExt * ) state )-> cmp ;
172
+ if (cmp != NULL )
161
173
{
162
174
if (i1 -> addInfoIsNull || i2 -> addInfoIsNull )
163
175
{
@@ -169,7 +181,7 @@ comparetup_rumitem(const SortTuple *a, const SortTuple *b,
169
181
{
170
182
int r ;
171
183
172
- r = DatumGetInt32 (FunctionCall2 ((( RumTuplesortstateExt * ) state ) -> cmp ,
184
+ r = DatumGetInt32 (FunctionCall2 (cmp ,
173
185
i1 -> addInfo ,
174
186
i2 -> addInfo ));
175
187
@@ -193,7 +205,7 @@ copytup_rum(RumTuplesortstate *state, SortTuple *stup, void *tup)
193
205
stup -> datum1 = Float8GetDatum (nKeys > 0 ? item -> data [0 ] : 0 );
194
206
stup -> isnull1 = false;
195
207
stup -> tuple = tup ;
196
- // USEMEM(state, GetMemoryChunkSpace(tup));
208
+ USEMEM (state , GetMemoryChunkSpace (tup ));
197
209
}
198
210
199
211
static void
@@ -202,19 +214,9 @@ copytup_rumitem(RumTuplesortstate *state, SortTuple *stup, void *tup)
202
214
stup -> isnull1 = true;
203
215
stup -> tuple = palloc (sizeof (RumScanItem ));
204
216
memcpy (stup -> tuple , tup , sizeof (RumScanItem ));
205
- // USEMEM(state, GetMemoryChunkSpace(stup->tuple));
217
+ USEMEM (state , GetMemoryChunkSpace (stup -> tuple ));
206
218
}
207
219
208
- #if PG_VERSION_NUM >= 150000
209
- #define LT_TYPE LogicalTape *
210
- #define LT_ARG tape
211
- #define TAPE (state , LT_ARG ) LT_ARG
212
- #else
213
- #define LT_TYPE int
214
- #define LT_ARG tapenum
215
- #define TAPE (state , LT_ARG ) state->tapeset, LT_ARG
216
- #endif
217
-
218
220
static void readtup_rum (RumTuplesortstate * state , SortTuple * stup ,
219
221
LT_TYPE LT_ARG , unsigned int len );
220
222
@@ -228,9 +230,9 @@ rum_item_size(RumTuplesortstate *state)
228
230
return RumSortItemSize (TSS_GET (state )-> nKeys );
229
231
else if (TSS_GET (state )-> readtup == readtup_rumitem )
230
232
return sizeof (RumScanItem );
231
- else
232
- elog (FATAL , "Unknown RUM state" );
233
- return 0 ; /* Silence compiler */
233
+
234
+ elog (FATAL , "Unknown RUM state" );
235
+ return 0 ; /* keep compiler quiet */
234
236
}
235
237
236
238
static void
@@ -277,7 +279,7 @@ readtup_rum_internal(RumTuplesortstate *state, SortTuple *stup,
277
279
278
280
Assert (tuplen == size );
279
281
280
- // USEMEM(state, GetMemoryChunkSpace(item));
282
+ USEMEM (state , GetMemoryChunkSpace (item ));
281
283
#if PG_VERSION_NUM >= 150000
282
284
LogicalTapeReadExact (LT_ARG , item , size );
283
285
#else
@@ -420,7 +422,12 @@ rum_tuplesort_putrum(RumTuplesortstate *state, RumSortItem *item)
420
422
421
423
oldcontext = MemoryContextSwitchTo (rum_tuplesort_get_memorycontext (state ));
422
424
copytup_rum (state , & stup , item );
425
+
426
+ #if PG_VERSION_NUM >= 160000
427
+ tuplesort_puttuple_common (state , & stup , false);
428
+ #else
423
429
puttuple_common (state , & stup );
430
+ #endif
424
431
425
432
MemoryContextSwitchTo (oldcontext );
426
433
}
@@ -433,7 +440,12 @@ rum_tuplesort_putrumitem(RumTuplesortstate *state, RumScanItem *item)
433
440
434
441
oldcontext = MemoryContextSwitchTo (rum_tuplesort_get_memorycontext (state ));
435
442
copytup_rumitem (state , & stup , item );
443
+
444
+ #if PG_VERSION_NUM >= 160000
445
+ tuplesort_puttuple_common (state , & stup , false);
446
+ #else
436
447
puttuple_common (state , & stup );
448
+ #endif
437
449
438
450
MemoryContextSwitchTo (oldcontext );
439
451
}
0 commit comments