2727
2828#include "rum.h" /* RumItem */
2929
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
3134#include "tuplesort15.c"
3235#elif PG_VERSION_NUM >= 140000
3336#include "tuplesort14.c"
@@ -53,7 +56,6 @@ typedef struct RumTuplesortstateExt
5356 FmgrInfo * cmp ;
5457} RumTuplesortstateExt ;
5558
56- static int compare_rum_itempointer (ItemPointerData p1 , ItemPointerData p2 );
5759static int comparetup_rum (const SortTuple * a , const SortTuple * b ,
5860 RumTuplesortstate * state , bool compareItemPointer );
5961static int comparetup_rum_true (const SortTuple * a , const SortTuple * b ,
@@ -69,11 +71,19 @@ static void *rum_tuplesort_getrum_internal(RumTuplesortstate *state,
6971 bool forward , bool * should_free );
7072
7173#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
7483#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
7787#endif
7888
7989static inline int
@@ -152,12 +162,14 @@ comparetup_rumitem(const SortTuple *a, const SortTuple *b,
152162{
153163 RumItem * i1 ,
154164 * i2 ;
165+ FmgrInfo * cmp ;
155166
156167 /* Extract RumItem from RumScanItem */
157168 i1 = (RumItem * ) a -> tuple ;
158169 i2 = (RumItem * ) b -> tuple ;
159170
160- if (((RumTuplesortstateExt * ) state )-> cmp )
171+ cmp = ((RumTuplesortstateExt * ) state )-> cmp ;
172+ if (cmp != NULL )
161173 {
162174 if (i1 -> addInfoIsNull || i2 -> addInfoIsNull )
163175 {
@@ -169,7 +181,7 @@ comparetup_rumitem(const SortTuple *a, const SortTuple *b,
169181 {
170182 int r ;
171183
172- r = DatumGetInt32 (FunctionCall2 ((( RumTuplesortstateExt * ) state ) -> cmp ,
184+ r = DatumGetInt32 (FunctionCall2 (cmp ,
173185 i1 -> addInfo ,
174186 i2 -> addInfo ));
175187
@@ -193,7 +205,7 @@ copytup_rum(RumTuplesortstate *state, SortTuple *stup, void *tup)
193205 stup -> datum1 = Float8GetDatum (nKeys > 0 ? item -> data [0 ] : 0 );
194206 stup -> isnull1 = false;
195207 stup -> tuple = tup ;
196- // USEMEM(state, GetMemoryChunkSpace(tup));
208+ USEMEM (state , GetMemoryChunkSpace (tup ));
197209}
198210
199211static void
@@ -202,19 +214,9 @@ copytup_rumitem(RumTuplesortstate *state, SortTuple *stup, void *tup)
202214 stup -> isnull1 = true;
203215 stup -> tuple = palloc (sizeof (RumScanItem ));
204216 memcpy (stup -> tuple , tup , sizeof (RumScanItem ));
205- // USEMEM(state, GetMemoryChunkSpace(stup->tuple));
217+ USEMEM (state , GetMemoryChunkSpace (stup -> tuple ));
206218}
207219
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-
218220static void readtup_rum (RumTuplesortstate * state , SortTuple * stup ,
219221 LT_TYPE LT_ARG , unsigned int len );
220222
@@ -228,9 +230,9 @@ rum_item_size(RumTuplesortstate *state)
228230 return RumSortItemSize (TSS_GET (state )-> nKeys );
229231 else if (TSS_GET (state )-> readtup == readtup_rumitem )
230232 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 */
234236}
235237
236238static void
@@ -277,7 +279,7 @@ readtup_rum_internal(RumTuplesortstate *state, SortTuple *stup,
277279
278280 Assert (tuplen == size );
279281
280- // USEMEM(state, GetMemoryChunkSpace(item));
282+ USEMEM (state , GetMemoryChunkSpace (item ));
281283#if PG_VERSION_NUM >= 150000
282284 LogicalTapeReadExact (LT_ARG , item , size );
283285#else
@@ -420,7 +422,12 @@ rum_tuplesort_putrum(RumTuplesortstate *state, RumSortItem *item)
420422
421423 oldcontext = MemoryContextSwitchTo (rum_tuplesort_get_memorycontext (state ));
422424 copytup_rum (state , & stup , item );
425+
426+ #if PG_VERSION_NUM >= 160000
427+ tuplesort_puttuple_common (state , & stup , false);
428+ #else
423429 puttuple_common (state , & stup );
430+ #endif
424431
425432 MemoryContextSwitchTo (oldcontext );
426433}
@@ -433,7 +440,12 @@ rum_tuplesort_putrumitem(RumTuplesortstate *state, RumScanItem *item)
433440
434441 oldcontext = MemoryContextSwitchTo (rum_tuplesort_get_memorycontext (state ));
435442 copytup_rumitem (state , & stup , item );
443+
444+ #if PG_VERSION_NUM >= 160000
445+ tuplesort_puttuple_common (state , & stup , false);
446+ #else
436447 puttuple_common (state , & stup );
448+ #endif
437449
438450 MemoryContextSwitchTo (oldcontext );
439451}
0 commit comments