From e7ae8c8ebaa63446838816a80d63aa2051dc2c6e Mon Sep 17 00:00:00 2001 From: Pavel Borisov Date: Fri, 22 Jul 2022 19:47:50 +0400 Subject: [PATCH v3 7/7] Tuplesort code beautification --- src/backend/utils/sort/tuplesortvariants.c | 440 ++++++++++++--------- 1 file changed, 252 insertions(+), 188 deletions(-) diff --git a/src/backend/utils/sort/tuplesortvariants.c b/src/backend/utils/sort/tuplesortvariants.c index e7bc87c71c..92f3206bf4 100644 --- a/src/backend/utils/sort/tuplesortvariants.c +++ b/src/backend/utils/sort/tuplesortvariants.c @@ -126,18 +126,18 @@ typedef struct } TuplesortDatumArg; Tuplesortstate * -tuplesort_begin_heap(TupleDesc tupDesc, - int nkeys, AttrNumber *attNums, +tuplesort_begin_heap(TupleDesc tupDesc, int nkeys, AttrNumber *attNums, Oid *sortOperators, Oid *sortCollations, bool *nullsFirstFlags, int workMem, SortCoordinate coordinate, int sortopt) { - Tuplesortstate *state = tuplesort_begin_common(workMem, coordinate, - sortopt); - TuplesortPublic *base = TuplesortstateGetPublic(state); - MemoryContext oldcontext; - int i; + Tuplesortstate *state; + TuplesortPublic *base; + MemoryContext oldcontext; + int i; + state = tuplesort_begin_common(workMem, coordinate, sortopt); + base = TuplesortstateGetPublic(state); oldcontext = MemoryContextSwitchTo(base->maincontext); AssertArg(nkeys > 0); @@ -200,19 +200,18 @@ tuplesort_begin_heap(TupleDesc tupDesc, } Tuplesortstate * -tuplesort_begin_cluster(TupleDesc tupDesc, - Relation indexRel, - int workMem, +tuplesort_begin_cluster(TupleDesc tupDesc, Relation indexRel, int workMem, SortCoordinate coordinate, int sortopt) { - Tuplesortstate *state = tuplesort_begin_common(workMem, coordinate, - sortopt); - TuplesortPublic *base = TuplesortstateGetPublic(state); - BTScanInsert indexScanKey; - MemoryContext oldcontext; + Tuplesortstate *state; + TuplesortPublic *base; + BTScanInsert indexScanKey; + MemoryContext oldcontext; TuplesortClusterArg *arg; - int i; + int i; + state = tuplesort_begin_common(workMem, coordinate, sortopt); + base = TuplesortstateGetPublic(state); Assert(indexRel->rd_rel->relam == BTREE_AM_OID); oldcontext = MemoryContextSwitchTo(base->maincontext); @@ -308,22 +307,20 @@ tuplesort_begin_cluster(TupleDesc tupDesc, } Tuplesortstate * -tuplesort_begin_index_btree(Relation heapRel, - Relation indexRel, - bool enforceUnique, - bool uniqueNullsNotDistinct, - int workMem, - SortCoordinate coordinate, +tuplesort_begin_index_btree(Relation heapRel, Relation indexRel, + bool enforceUnique, bool uniqueNullsNotDistinct, + int workMem, SortCoordinate coordinate, int sortopt) { - Tuplesortstate *state = tuplesort_begin_common(workMem, coordinate, - sortopt); - TuplesortPublic *base = TuplesortstateGetPublic(state); - BTScanInsert indexScanKey; + Tuplesortstate *state; + TuplesortPublic *base; + BTScanInsert indexScanKey; TuplesortIndexBTreeArg *arg; - MemoryContext oldcontext; - int i; + MemoryContext oldcontext; + int i; + state = tuplesort_begin_common(workMem, coordinate, sortopt); + base = TuplesortstateGetPublic(state); oldcontext = MemoryContextSwitchTo(base->maincontext); arg = (TuplesortIndexBTreeArg *) palloc(sizeof(TuplesortIndexBTreeArg)); @@ -392,21 +389,18 @@ tuplesort_begin_index_btree(Relation heapRel, } Tuplesortstate * -tuplesort_begin_index_hash(Relation heapRel, - Relation indexRel, - uint32 high_mask, - uint32 low_mask, - uint32 max_buckets, - int workMem, - SortCoordinate coordinate, - int sortopt) +tuplesort_begin_index_hash(Relation heapRel, Relation indexRel, + uint32 high_mask, uint32 low_mask, + uint32 max_buckets, int workMem, + SortCoordinate coordinate, int sortopt) { - Tuplesortstate *state = tuplesort_begin_common(workMem, coordinate, - sortopt); - TuplesortPublic *base = TuplesortstateGetPublic(state); - MemoryContext oldcontext; - TuplesortIndexHashArg *arg; + Tuplesortstate *state; + TuplesortPublic *base; + MemoryContext oldcontext; + TuplesortIndexHashArg *arg; + state = tuplesort_begin_common(workMem, coordinate, sortopt); + base = TuplesortstateGetPublic(state); oldcontext = MemoryContextSwitchTo(base->maincontext); arg = (TuplesortIndexHashArg *) palloc(sizeof(TuplesortIndexHashArg)); @@ -444,19 +438,18 @@ tuplesort_begin_index_hash(Relation heapRel, } Tuplesortstate * -tuplesort_begin_index_gist(Relation heapRel, - Relation indexRel, - int workMem, - SortCoordinate coordinate, +tuplesort_begin_index_gist(Relation heapRel, Relation indexRel, + int workMem, SortCoordinate coordinate, int sortopt) { - Tuplesortstate *state = tuplesort_begin_common(workMem, coordinate, - sortopt); - TuplesortPublic *base = TuplesortstateGetPublic(state); - MemoryContext oldcontext; + Tuplesortstate *state; + TuplesortPublic *base; + MemoryContext oldcontext; TuplesortIndexBTreeArg *arg; - int i; + int i; + state = tuplesort_begin_common(workMem, coordinate, sortopt); + base = TuplesortstateGetPublic(state); oldcontext = MemoryContextSwitchTo(base->maincontext); arg = (TuplesortIndexBTreeArg *) palloc(sizeof(TuplesortIndexBTreeArg)); @@ -512,14 +505,15 @@ tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation, bool nullsFirstFlag, int workMem, SortCoordinate coordinate, int sortopt) { - Tuplesortstate *state = tuplesort_begin_common(workMem, coordinate, - sortopt); - TuplesortPublic *base = TuplesortstateGetPublic(state); - TuplesortDatumArg *arg; - MemoryContext oldcontext; - int16 typlen; - bool typbyval; - + Tuplesortstate *state; + TuplesortPublic *base; + TuplesortDatumArg *arg; + MemoryContext oldcontext; + int16 typlen; + bool typbyval; + + state = tuplesort_begin_common(workMem, coordinate, sortopt); + base = TuplesortstateGetPublic(state); oldcontext = MemoryContextSwitchTo(base->maincontext); arg = (TuplesortDatumArg *) palloc(sizeof(TuplesortDatumArg)); @@ -594,13 +588,16 @@ tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation, void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - MemoryContext oldcontext = MemoryContextSwitchTo(base->tuplecontext); - TupleDesc tupDesc = (TupleDesc) base->arg; - SortTuple stup; - MinimalTuple tuple; - HeapTupleData htup; - + TuplesortPublic *base; + MemoryContext oldcontext; + TupleDesc tupDesc; + SortTuple stup; + MinimalTuple tuple; + HeapTupleData htup; + + base = TuplesortstateGetPublic(state); + tupDesc = (TupleDesc) base->arg; + oldcontext = MemoryContextSwitchTo(base->tuplecontext); /* copy the tuple into sort storage */ tuple = ExecCopySlotMinimalTuple(slot); stup.tuple = (void *) tuple; @@ -627,11 +624,14 @@ tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot) void tuplesort_putheaptuple(Tuplesortstate *state, HeapTuple tup) { - SortTuple stup; - TuplesortPublic *base = TuplesortstateGetPublic(state); - MemoryContext oldcontext = MemoryContextSwitchTo(base->tuplecontext); - TuplesortClusterArg *arg = (TuplesortClusterArg *) base->arg; + SortTuple stup; + TuplesortPublic *base; + MemoryContext oldcontext; + TuplesortClusterArg *arg; + base = TuplesortstateGetPublic(state); + oldcontext = MemoryContextSwitchTo(base->tuplecontext); + arg = (TuplesortClusterArg *) base->arg; /* copy the tuple into sort storage */ tup = heap_copytuple(tup); stup.tuple = (void *) tup; @@ -665,11 +665,13 @@ tuplesort_putindextuplevalues(Tuplesortstate *state, Relation rel, ItemPointer self, Datum *values, bool *isnull) { - SortTuple stup; - IndexTuple tuple; - TuplesortPublic *base = TuplesortstateGetPublic(state); - TuplesortIndexArg *arg = (TuplesortIndexArg *) base->arg; + SortTuple stup; + IndexTuple tuple; + TuplesortPublic *base; + TuplesortIndexArg *arg; + base = TuplesortstateGetPublic(state); + arg = (TuplesortIndexArg *) base->arg; stup.tuple = index_form_tuple_context(RelationGetDescr(rel), values, isnull, base->tuplecontext); tuple = ((IndexTuple) stup.tuple); @@ -694,11 +696,14 @@ tuplesort_putindextuplevalues(Tuplesortstate *state, Relation rel, void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - MemoryContext oldcontext = MemoryContextSwitchTo(base->tuplecontext); - TuplesortDatumArg *arg = (TuplesortDatumArg *) base->arg; - SortTuple stup; + TuplesortPublic *base; + MemoryContext oldcontext; + TuplesortDatumArg *arg; + SortTuple stup; + base = TuplesortstateGetPublic(state); + oldcontext = MemoryContextSwitchTo(base->tuplecontext); + arg = (TuplesortDatumArg *) base->arg; /* * Pass-by-value types or null values are just stored directly in * stup.datum1 (and stup.tuple is not used and set to NULL). @@ -759,9 +764,12 @@ bool tuplesort_gettupleslot(Tuplesortstate *state, bool forward, bool copy, TupleTableSlot *slot, Datum *abbrev) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - MemoryContext oldcontext = MemoryContextSwitchTo(base->sortcontext); - SortTuple stup; + TuplesortPublic *base; + MemoryContext oldcontext; + SortTuple stup; + + base = TuplesortstateGetPublic(state); + oldcontext = MemoryContextSwitchTo(base->sortcontext); if (!tuplesort_gettuple_common(state, forward, &stup)) stup.tuple = NULL; @@ -796,9 +804,12 @@ tuplesort_gettupleslot(Tuplesortstate *state, bool forward, bool copy, HeapTuple tuplesort_getheaptuple(Tuplesortstate *state, bool forward) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - MemoryContext oldcontext = MemoryContextSwitchTo(base->sortcontext); - SortTuple stup; + TuplesortPublic *base; + MemoryContext oldcontext; + SortTuple stup; + + base = TuplesortstateGetPublic(state); + oldcontext = MemoryContextSwitchTo(base->sortcontext); if (!tuplesort_gettuple_common(state, forward, &stup)) stup.tuple = NULL; @@ -817,9 +828,12 @@ tuplesort_getheaptuple(Tuplesortstate *state, bool forward) IndexTuple tuplesort_getindextuple(Tuplesortstate *state, bool forward) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - MemoryContext oldcontext = MemoryContextSwitchTo(base->sortcontext); - SortTuple stup; + TuplesortPublic *base; + MemoryContext oldcontext; + SortTuple stup; + + base = TuplesortstateGetPublic(state); + oldcontext = MemoryContextSwitchTo(base->sortcontext); if (!tuplesort_gettuple_common(state, forward, &stup)) stup.tuple = NULL; @@ -848,10 +862,14 @@ bool tuplesort_getdatum(Tuplesortstate *state, bool forward, Datum *val, bool *isNull, Datum *abbrev) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - MemoryContext oldcontext = MemoryContextSwitchTo(base->sortcontext); - TuplesortDatumArg *arg = (TuplesortDatumArg *) base->arg; - SortTuple stup; + TuplesortPublic *base; + MemoryContext oldcontext; + TuplesortDatumArg *arg; + SortTuple stup; + + base = TuplesortstateGetPublic(state); + oldcontext = MemoryContextSwitchTo(base->sortcontext); + arg = (TuplesortDatumArg *) base->arg; if (!tuplesort_gettuple_common(state, forward, &stup)) { @@ -910,20 +928,21 @@ removeabbrev_heap(Tuplesortstate *state, SortTuple *stups, int count) static int comparetup_heap(const SortTuple *a, const SortTuple *b, Tuplesortstate *state) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - SortSupport sortKey = base->sortKeys; - HeapTupleData ltup; - HeapTupleData rtup; - TupleDesc tupDesc; - int nkey; - int32 compare; - AttrNumber attno; - Datum datum1, - datum2; - bool isnull1, - isnull2; - - + TuplesortPublic *base; + SortSupport sortKey; + HeapTupleData ltup, + rtup; + TupleDesc tupDesc; + int nkey; + int32 compare; + AttrNumber attno; + Datum datum1, + datum2; + bool isnull1, + isnull2; + + base = TuplesortstateGetPublic(state); + sortKey = base->sortKeys; /* Compare the leading sort key */ compare = ApplySortComparator(a->datum1, a->isnull1, b->datum1, b->isnull1, @@ -973,15 +992,17 @@ comparetup_heap(const SortTuple *a, const SortTuple *b, Tuplesortstate *state) static void writetup_heap(Tuplesortstate *state, LogicalTape *tape, SortTuple *stup) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - MinimalTuple tuple = (MinimalTuple) stup->tuple; - - /* the part of the MinimalTuple we'll write: */ - char *tupbody = (char *) tuple + MINIMAL_TUPLE_DATA_OFFSET; - unsigned int tupbodylen = tuple->t_len - MINIMAL_TUPLE_DATA_OFFSET; - - /* total on-disk footprint: */ - unsigned int tuplen = tupbodylen + sizeof(int); + TuplesortPublic *base; + MinimalTuple tuple; + char *tupbody; /* the part of the MinimalTuple we'll write: */ + unsigned int tupbodylen, + tuplen; /* total on-disk footprint: */ + + base = TuplesortstateGetPublic(state); + tuple = (MinimalTuple) stup->tuple; + tupbody = (char *) tuple + MINIMAL_TUPLE_DATA_OFFSET; + tupbodylen = tuple->t_len - MINIMAL_TUPLE_DATA_OFFSET; + tuplen = tupbodylen + sizeof(int); LogicalTapeWrite(tape, (void *) &tuplen, sizeof(tuplen)); LogicalTapeWrite(tape, (void *) tupbody, tupbodylen); @@ -993,13 +1014,18 @@ static void readtup_heap(Tuplesortstate *state, SortTuple *stup, LogicalTape *tape, unsigned int len) { - unsigned int tupbodylen = len - sizeof(int); - unsigned int tuplen = tupbodylen + MINIMAL_TUPLE_DATA_OFFSET; - MinimalTuple tuple = (MinimalTuple) tuplesort_readtup_alloc(state, tuplen); - char *tupbody = (char *) tuple + MINIMAL_TUPLE_DATA_OFFSET; - TuplesortPublic *base = TuplesortstateGetPublic(state); - HeapTupleData htup; - + unsigned int tupbodylen, + tuplen; + MinimalTuple tuple; + char *tupbody; + TuplesortPublic *base; + HeapTupleData htup; + + tupbodylen = len - sizeof(int); + tuplen = tupbodylen + MINIMAL_TUPLE_DATA_OFFSET; + tuple = (MinimalTuple) tuplesort_readtup_alloc(state, tuplen); + tupbody = (char *) tuple + MINIMAL_TUPLE_DATA_OFFSET; + base = TuplesortstateGetPublic(state); /* read in the tuple proper */ tuple->t_len = tuplen; LogicalTapeReadExact(tape, tupbody, tupbodylen); @@ -1023,9 +1049,12 @@ readtup_heap(Tuplesortstate *state, SortTuple *stup, static void removeabbrev_cluster(Tuplesortstate *state, SortTuple *stups, int count) { - int i; - TuplesortPublic *base = TuplesortstateGetPublic(state); - TuplesortClusterArg *arg = (TuplesortClusterArg *) base->arg; + int i; + TuplesortPublic *base; + TuplesortClusterArg *arg; + + base = TuplesortstateGetPublic(state); + arg = (TuplesortClusterArg *) base->arg; for (i = 0; i < count; i++) { @@ -1043,19 +1072,22 @@ static int comparetup_cluster(const SortTuple *a, const SortTuple *b, Tuplesortstate *state) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - TuplesortClusterArg *arg = (TuplesortClusterArg *) base->arg; - SortSupport sortKey = base->sortKeys; - HeapTuple ltup; - HeapTuple rtup; - TupleDesc tupDesc; - int nkey; - int32 compare; - Datum datum1, - datum2; - bool isnull1, - isnull2; - + TuplesortPublic *base; + TuplesortClusterArg *arg; + SortSupport sortKey; + HeapTuple ltup, + rtup; + TupleDesc tupDesc; + int nkey; + int32 compare; + Datum datum1, + datum2; + bool isnull1, + isnull2; + + base = TuplesortstateGetPublic(state); + arg = (TuplesortClusterArg *) base->arg; + sortKey = base->sortKeys; /* Be prepared to compare additional sort keys */ ltup = (HeapTuple) a->tuple; rtup = (HeapTuple) b->tuple; @@ -1156,9 +1188,13 @@ comparetup_cluster(const SortTuple *a, const SortTuple *b, static void writetup_cluster(Tuplesortstate *state, LogicalTape *tape, SortTuple *stup) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - HeapTuple tuple = (HeapTuple) stup->tuple; - unsigned int tuplen = tuple->t_len + sizeof(ItemPointerData) + sizeof(int); + TuplesortPublic *base; + HeapTuple tuple; + unsigned int tuplen; + + base = TuplesortstateGetPublic(state); + tuple = (HeapTuple) stup->tuple; + tuplen = tuple->t_len + sizeof(ItemPointerData) + sizeof(int); /* We need to store t_self, but not other fields of HeapTupleData */ LogicalTapeWrite(tape, &tuplen, sizeof(tuplen)); @@ -1172,11 +1208,15 @@ static void readtup_cluster(Tuplesortstate *state, SortTuple *stup, LogicalTape *tape, unsigned int tuplen) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - TuplesortClusterArg *arg = (TuplesortClusterArg *) base->arg; - unsigned int t_len = tuplen - sizeof(ItemPointerData) - sizeof(int); - HeapTuple tuple = (HeapTuple) tuplesort_readtup_alloc(state, - t_len + HEAPTUPLESIZE); + TuplesortPublic *base; + TuplesortClusterArg *arg; + unsigned int t_len; + HeapTuple tuple; + + base = TuplesortstateGetPublic(state); + arg = (TuplesortClusterArg *) base->arg; + t_len = tuplen - sizeof(ItemPointerData) - sizeof(int); + tuple = (HeapTuple) tuplesort_readtup_alloc(state, t_len + HEAPTUPLESIZE); /* Reconstruct the HeapTupleData header */ tuple->t_data = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE); @@ -1200,8 +1240,11 @@ readtup_cluster(Tuplesortstate *state, SortTuple *stup, static void freestate_cluster(Tuplesortstate *state) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - TuplesortClusterArg *arg = (TuplesortClusterArg *) base->arg; + TuplesortPublic *base; + TuplesortClusterArg *arg; + + base = TuplesortstateGetPublic(state); + arg = (TuplesortClusterArg *) base->arg; /* Free any execution state created for CLUSTER case */ if (arg->estate != NULL) @@ -1224,9 +1267,12 @@ freestate_cluster(Tuplesortstate *state) static void removeabbrev_index(Tuplesortstate *state, SortTuple *stups, int count) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - TuplesortIndexArg *arg = (TuplesortIndexArg *) base->arg; - int i; + TuplesortPublic *base; + TuplesortIndexArg *arg; + int i; + + base = TuplesortstateGetPublic(state); + arg = (TuplesortIndexArg *) base->arg; for (i = 0; i < count; i++) { @@ -1249,22 +1295,24 @@ comparetup_index_btree(const SortTuple *a, const SortTuple *b, * is also special handling for enforcing uniqueness, and special * treatment for equal keys at the end. */ - TuplesortPublic *base = TuplesortstateGetPublic(state); - TuplesortIndexBTreeArg *arg = (TuplesortIndexBTreeArg *) base->arg; - SortSupport sortKey = base->sortKeys; - IndexTuple tuple1; - IndexTuple tuple2; - int keysz; - TupleDesc tupDes; - bool equal_hasnull = false; - int nkey; - int32 compare; - Datum datum1, - datum2; - bool isnull1, - isnull2; - - + TuplesortPublic *base; + TuplesortIndexBTreeArg *arg; + SortSupport sortKey; + IndexTuple tuple1, + tuple2; + int keysz; + TupleDesc tupDes; + bool equal_hasnull = false; + int nkey; + int32 compare; + Datum datum1, + datum2; + bool isnull1, + isnull2; + + base = TuplesortstateGetPublic(state); + arg = (TuplesortIndexBTreeArg *) base->arg; + sortKey = base->sortKeys; /* Compare the leading sort key */ compare = ApplySortComparator(a->datum1, a->isnull1, b->datum1, b->isnull1, @@ -1380,13 +1428,15 @@ static int comparetup_index_hash(const SortTuple *a, const SortTuple *b, Tuplesortstate *state) { - Bucket bucket1; - Bucket bucket2; - IndexTuple tuple1; - IndexTuple tuple2; - TuplesortPublic *base = TuplesortstateGetPublic(state); - TuplesortIndexHashArg *arg = (TuplesortIndexHashArg *) base->arg; - + Bucket bucket1, + bucket2; + IndexTuple tuple1, + tuple2; + TuplesortPublic *base; + TuplesortIndexHashArg *arg; + + base = TuplesortstateGetPublic(state); + arg = (TuplesortIndexHashArg *) base->arg; /* * Fetch hash keys and mask off bits we don't want to sort by. We know * that the first column of the index tuple is the hash key. @@ -1436,10 +1486,12 @@ comparetup_index_hash(const SortTuple *a, const SortTuple *b, static void writetup_index(Tuplesortstate *state, LogicalTape *tape, SortTuple *stup) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - IndexTuple tuple = (IndexTuple) stup->tuple; - unsigned int tuplen; + TuplesortPublic *base; + IndexTuple tuple; + unsigned int tuplen; + base = TuplesortstateGetPublic(state); + tuple = (IndexTuple) stup->tuple; tuplen = IndexTupleSize(tuple) + sizeof(tuplen); LogicalTapeWrite(tape, (void *) &tuplen, sizeof(tuplen)); LogicalTapeWrite(tape, (void *) tuple, IndexTupleSize(tuple)); @@ -1451,10 +1503,15 @@ static void readtup_index(Tuplesortstate *state, SortTuple *stup, LogicalTape *tape, unsigned int len) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - TuplesortIndexArg *arg = (TuplesortIndexArg *) base->arg; - unsigned int tuplen = len - sizeof(unsigned int); - IndexTuple tuple = (IndexTuple) tuplesort_readtup_alloc(state, tuplen); + TuplesortPublic *base; + TuplesortIndexArg *arg; + unsigned int tuplen; + IndexTuple tuple; + + base = TuplesortstateGetPublic(state); + arg = (TuplesortIndexArg *) base->arg; + tuplen = len - sizeof(unsigned int); + tuple = (IndexTuple) tuplesort_readtup_alloc(state, tuplen); LogicalTapeReadExact(tape, tuple, tuplen); if (base->sortopt & TUPLESORT_RANDOMACCESS) /* need trailing length word? */ @@ -1483,9 +1540,10 @@ removeabbrev_datum(Tuplesortstate *state, SortTuple *stups, int count) static int comparetup_datum(const SortTuple *a, const SortTuple *b, Tuplesortstate *state) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - int compare; + TuplesortPublic *base; + int compare; + base = TuplesortstateGetPublic(state); compare = ApplySortComparator(a->datum1, a->isnull1, b->datum1, b->isnull1, base->sortKeys); @@ -1505,11 +1563,14 @@ comparetup_datum(const SortTuple *a, const SortTuple *b, Tuplesortstate *state) static void writetup_datum(Tuplesortstate *state, LogicalTape *tape, SortTuple *stup) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - TuplesortDatumArg *arg = (TuplesortDatumArg *) base->arg; - void *waddr; - unsigned int tuplen; - unsigned int writtenlen; + TuplesortPublic *base; + TuplesortDatumArg *arg; + void *waddr; + unsigned int tuplen, + writtenlen; + + base = TuplesortstateGetPublic(state); + arg = (TuplesortDatumArg *) base->arg; if (stup->isnull1) { @@ -1540,8 +1601,11 @@ static void readtup_datum(Tuplesortstate *state, SortTuple *stup, LogicalTape *tape, unsigned int len) { - TuplesortPublic *base = TuplesortstateGetPublic(state); - unsigned int tuplen = len - sizeof(unsigned int); + TuplesortPublic *base; + unsigned int tuplen; + + base = TuplesortstateGetPublic(state); + tuplen = len - sizeof(unsigned int); if (tuplen == 0) { -- 2.24.3 (Apple Git-128)