*/
SortTupleComparator comparetup;
+ /*
+ * Alter datum1 representation in the SortTuple's array back from the
+ * abbreviated key to the first column value.
+ */
+ void (*removeabbrev) (Tuplesortstate *state, SortTuple *stups,
+ int count);
+
/*
* Function to write a stored tuple onto tape. The representation of the
* tuple on tape need not be the same as it is in memory; requirements on
pfree(buf); \
} while(0)
+#define REMOVEABBREV(state,stup,count) ((*(state)->removeabbrev) (state, stup, count))
#define COMPARETUP(state,a,b) ((*(state)->comparetup) (a, b, state))
#define WRITETUP(state,tape,stup) ((*(state)->writetup) (state, tape, stup))
#define READTUP(state,stup,tape,len) ((*(state)->readtup) (state, stup, tape, len))
static unsigned int getlen(LogicalTape *tape, bool eofOK);
static void markrunend(LogicalTape *tape);
static void *readtup_alloc(Tuplesortstate *state, Size tuplen);
+static void removeabbrev_heap(Tuplesortstate *state, SortTuple *stups,
+ int count);
+static void removeabbrev_cluster(Tuplesortstate *state, SortTuple *stups,
+ int count);
+static void removeabbrev_index(Tuplesortstate *state, SortTuple *stups,
+ int count);
+static void removeabbrev_datum(Tuplesortstate *state, SortTuple *stups,
+ int count);
static int comparetup_heap(const SortTuple *a, const SortTuple *b,
Tuplesortstate *state);
static void writetup_heap(Tuplesortstate *state, LogicalTape *tape,
sortopt & TUPLESORT_RANDOMACCESS,
PARALLEL_SORT(state));
+ state->removeabbrev = removeabbrev_heap;
state->comparetup = comparetup_heap;
state->writetup = writetup_heap;
state->readtup = readtup_heap;
sortopt & TUPLESORT_RANDOMACCESS,
PARALLEL_SORT(state));
+ state->removeabbrev = removeabbrev_cluster;
state->comparetup = comparetup_cluster;
state->writetup = writetup_cluster;
state->readtup = readtup_cluster;
sortopt & TUPLESORT_RANDOMACCESS,
PARALLEL_SORT(state));
+ state->removeabbrev = removeabbrev_index;
state->comparetup = comparetup_index_btree;
state->writetup = writetup_index;
state->readtup = readtup_index;
state->nKeys = 1; /* Only one sort column, the hash code */
+ state->removeabbrev = removeabbrev_index;
state->comparetup = comparetup_index_hash;
state->writetup = writetup_index;
state->readtup = readtup_index;
state->nKeys = IndexRelationGetNumberOfKeyAttributes(indexRel);
+ state->removeabbrev = removeabbrev_index;
state->comparetup = comparetup_index_btree;
state->writetup = writetup_index;
state->readtup = readtup_index;
sortopt & TUPLESORT_RANDOMACCESS,
PARALLEL_SORT(state));
+ state->removeabbrev = removeabbrev_datum;
state->comparetup = comparetup_datum;
state->writetup = writetup_datum;
state->readtup = readtup_datum;
else
{
/* Abort abbreviation */
- int i;
-
stup.datum1 = original;
/*
* sorted on tape, since serialized tuples lack abbreviated keys
* (TSS_BUILDRUNS state prevents control reaching here in any case).
*/
- for (i = 0; i < state->memtupcount; i++)
- {
- SortTuple *mtup = &state->memtuples[i];
-
- htup.t_len = ((MinimalTuple) mtup->tuple)->t_len +
- MINIMAL_TUPLE_OFFSET;
- htup.t_data = (HeapTupleHeader) ((char *) mtup->tuple -
- MINIMAL_TUPLE_OFFSET);
-
- mtup->datum1 = heap_getattr(&htup,
- state->sortKeys[0].ssup_attno,
- state->tupDesc,
- &mtup->isnull1);
- }
+ REMOVEABBREV(state, state->memtuples, state->memtupcount);
}
puttuple_common(state, &stup);
else
{
/* Abort abbreviation */
- int i;
-
stup.datum1 = original;
/*
* (TSS_BUILDRUNS state prevents control reaching here in any
* case).
*/
- for (i = 0; i < state->memtupcount; i++)
- {
- SortTuple *mtup = &state->memtuples[i];
-
- tup = (HeapTuple) mtup->tuple;
- mtup->datum1 = heap_getattr(tup,
- state->indexInfo->ii_IndexAttrNumbers[0],
- state->tupDesc,
- &mtup->isnull1);
- }
+ REMOVEABBREV(state, state->memtuples, state->memtupcount);
}
}
else
{
/* Abort abbreviation */
- int i;
-
stup.datum1 = original;
/*
* sorted on tape, since serialized tuples lack abbreviated keys
* (TSS_BUILDRUNS state prevents control reaching here in any case).
*/
- for (i = 0; i < state->memtupcount; i++)
- {
- SortTuple *mtup = &state->memtuples[i];
-
- tuple = mtup->tuple;
- mtup->datum1 = index_getattr(tuple,
- 1,
- RelationGetDescr(state->indexRel),
- &mtup->isnull1);
- }
+ REMOVEABBREV(state, state->memtuples, state->memtupcount);
}
puttuple_common(state, &stup);
else
{
/* Abort abbreviation */
- int i;
-
stup.datum1 = original;
/*
* (TSS_BUILDRUNS state prevents control reaching here in any
* case).
*/
- for (i = 0; i < state->memtupcount; i++)
- {
- SortTuple *mtup = &state->memtuples[i];
-
- mtup->datum1 = PointerGetDatum(mtup->tuple);
- }
+ REMOVEABBREV(state, state->memtuples, state->memtupcount);
}
}
* Routines specialized for HeapTuple (actually MinimalTuple) case
*/
+static void
+removeabbrev_heap(Tuplesortstate *state, SortTuple *stups, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ {
+ HeapTupleData htup;
+
+ htup.t_len = ((MinimalTuple) stups[i].tuple)->t_len +
+ MINIMAL_TUPLE_OFFSET;
+ htup.t_data = (HeapTupleHeader) ((char *) stups[i].tuple -
+ MINIMAL_TUPLE_OFFSET);
+ stups[i].datum1 = heap_getattr(&htup,
+ state->sortKeys[0].ssup_attno,
+ state->tupDesc,
+ &stups[i].isnull1);
+ }
+}
+
static int
comparetup_heap(const SortTuple *a, const SortTuple *b, Tuplesortstate *state)
{
* comparisons per a btree index definition)
*/
+static void
+removeabbrev_cluster(Tuplesortstate *state, SortTuple *stups, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ {
+ HeapTuple tup;
+
+ tup = (HeapTuple) stups[i].tuple;
+ stups[i].datum1 = heap_getattr(tup,
+ state->indexInfo->ii_IndexAttrNumbers[0],
+ state->tupDesc,
+ &stups[i].isnull1);
+ }
+}
+
static int
comparetup_cluster(const SortTuple *a, const SortTuple *b,
Tuplesortstate *state)
* functions can be shared.
*/
+static void
+removeabbrev_index(Tuplesortstate *state, SortTuple *stups, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ {
+ IndexTuple tuple;
+
+ tuple = stups[i].tuple;
+ stups[i].datum1 = index_getattr(tuple,
+ 1,
+ RelationGetDescr(state->indexRel),
+ &stups[i].isnull1);
+ }
+}
+
static int
comparetup_index_btree(const SortTuple *a, const SortTuple *b,
Tuplesortstate *state)
* Routines specialized for DatumTuple case
*/
+static void
+removeabbrev_datum(Tuplesortstate *state, SortTuple *stups, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ stups[i].datum1 = PointerGetDatum(stups[i].tuple);
+}
+
static int
comparetup_datum(const SortTuple *a, const SortTuple *b, Tuplesortstate *state)
{