186#define COPYTUP(state,tup) ((*(state)->copytup) (state, tup))
187#define WRITETUP(state,tup) ((*(state)->writetup) (state, tup))
188#define READTUP(state,len) ((*(state)->readtup) (state, len))
189#define LACKMEM(state) ((state)->availMem < 0)
190#define USEMEM(state,amt) ((state)->availMem -= (amt))
191#define FREEMEM(state,amt) ((state)->availMem += (amt))
264 state->eflags = eflags;
265 state->interXact = interXact;
266 state->truncated =
false;
267 state->usedDisk =
false;
282 state->memtupdeleted = 0;
283 state->memtupcount = 0;
290 state->memtupsize =
Max(16384 /
sizeof(
void *),
293 state->growmemtuples =
true;
298 state->activeptr = 0;
299 state->readptrcount = 1;
300 state->readptrsize = 8;
304 state->readptrs[0].eflags = eflags;
305 state->readptrs[0].eof_reached =
false;
306 state->readptrs[0].current = 0;
340 eflags = randomAccess ?
377 elog(
ERROR,
"too late to call tuplestore_set_eflags");
379 state->readptrs[0].eflags = eflags;
380 for (
i = 1;
i <
state->readptrcount;
i++)
381 eflags |=
state->readptrs[
i].eflags;
382 state->eflags = eflags;
401 if ((
state->eflags | eflags) !=
state->eflags)
402 elog(
ERROR,
"too late to require new tuplestore eflags");
406 if (
state->readptrcount >=
state->readptrsize)
417 state->readptrs[
state->readptrcount].eflags = eflags;
419 state->eflags |= eflags;
421 return state->readptrcount++;
443#ifdef USE_ASSERT_CHECKING
475 state->truncated =
false;
476 state->memtupdeleted = 0;
477 state->memtupcount = 0;
479 readptr =
state->readptrs;
480 for (
i = 0;
i <
state->readptrcount; readptr++,
i++)
516 if (ptr ==
state->activeptr)
519 readptr = &
state->readptrs[ptr];
522 switch (
state->status)
548 state->writepos_file,
549 state->writepos_offset,
553 errmsg(
"could not seek in tuplestore temporary file")));
563 errmsg(
"could not seek in tuplestore temporary file")));
571 state->activeptr = ptr;
583 return state->tuples;
594 return state->readptrs[
state->activeptr].eof_reached;
616 int memtupsize =
state->memtupsize;
620 if (!
state->growmemtuples)
635 state->growmemtuples =
false;
675 state->growmemtuples =
false;
692 state->growmemtuples =
false;
712 state->memtuples = (
void **)
714 state->memtupsize *
sizeof(
void *));
717 elog(
ERROR,
"unexpected out-of-memory situation in tuplestore");
722 state->growmemtuples =
false;
809 switch (
state->status)
816 readptr =
state->readptrs;
817 for (
i = 0;
i <
state->readptrcount; readptr++,
i++)
832 if (
state->memtupcount >=
state->memtupsize - 1)
839 state->memtuples[
state->memtupcount++] = tuple;
894 readptr =
state->readptrs;
895 for (
i = 0;
i <
state->readptrcount; readptr++,
i++)
913 if (!
state->readptrs[
state->activeptr].eof_reached)
922 errmsg(
"could not seek in tuplestore temporary file")));
928 readptr =
state->readptrs;
929 for (
i = 0;
i <
state->readptrcount; readptr++,
i++)
965 switch (
state->status)
1019 &
state->writepos_file, &
state->writepos_offset);
1026 errmsg(
"could not seek in tuplestore temporary file")));
1076 -(
pgoff_t) (tuplen + 2 *
sizeof(
unsigned int)),
1086 -(
pgoff_t) (tuplen +
sizeof(
unsigned int)),
1090 errmsg(
"could not seek in tuplestore temporary file")));
1107 errmsg(
"could not seek in tuplestore temporary file")));
1112 elog(
ERROR,
"invalid tuplestore state");
1229 switch (
state->status)
1266 while (ntuples-- > 0)
1295 for (
i =
state->memtupdeleted;;
i++)
1300 for (
j = 0;
j <
state->readptrcount; readptr++,
j++)
1306 if (
i >=
state->memtupcount)
1310 state->memtupdeleted = 0;
1311 state->memtupcount = 0;
1325 switch (
state->status)
1341 errmsg(
"could not seek in tuplestore temporary file")));
1344 elog(
ERROR,
"invalid tuplestore state");
1373 eflags =
state->readptrs[0].eflags;
1374 for (
i = 1;
i <
state->readptrcount;
i++)
1375 eflags |=
state->readptrs[
i].eflags;
1376 state->eflags = eflags;
1381 switch (
state->status)
1398 if (
dptr->eof_reached)
1401 state->writepos_file,
1402 state->writepos_offset,
1406 errmsg(
"could not seek in tuplestore temporary file")));
1415 errmsg(
"could not seek in tuplestore temporary file")));
1420 if (!
dptr->eof_reached)
1427 elog(
ERROR,
"invalid tuplestore state");
1467 for (
i = 0;
i <
state->readptrcount;
i++)
1469 if (!
state->readptrs[
i].eof_reached)
1503 state->truncated =
true;
1526 state->memtupdeleted = 0;
1528 for (
i = 0;
i <
state->readptrcount;
i++)
1530 if (!
state->readptrs[
i].eof_reached)
1555 state->usedDisk =
true;
1571 if (
state->usedDisk)
1645 if (
state->backward)
1661 tuple->
t_len = tuplen;
1663 if (
state->backward)
void PrepareTempTablespaces(void)
static Datum values[MAXATTR]
void BufFileReadExact(BufFile *file, void *ptr, size_t size)
BufFile * BufFileCreateTemp(bool interXact)
int BufFileSeek(BufFile *file, int fileno, pgoff_t offset, int whence)
void BufFileWrite(BufFile *file, const void *ptr, size_t size)
size_t BufFileReadMaybeEOF(BufFile *file, void *ptr, size_t size, bool eofOK)
void BufFileTell(BufFile *file, int *fileno, pgoff_t *offset)
int64 BufFileSize(BufFile *file)
void BufFileClose(BufFile *file)
#define Assert(condition)
int errcode_for_file_access(void)
#define ereport(elevel,...)
void ExecForceStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
TupleTableSlot * ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
#define EXEC_FLAG_BACKWARD
#define palloc0_object(type)
MemoryContext GenerationContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup, Size extra)
MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull, Size extra)
void heap_free_minimal_tuple(MinimalTuple mtup)
MinimalTuple minimal_tuple_from_heap_tuple(HeapTuple htup, Size extra)
MinimalTupleData * MinimalTuple
#define MINIMAL_TUPLE_DATA_OFFSET
void MemoryContextReset(MemoryContext context)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
Size GetMemoryChunkSpace(void *pointer)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
void * repalloc_huge(void *pointer, Size size)
#define ALLOCSET_DEFAULT_SIZES
#define ALLOCSET_SEPARATE_THRESHOLD
#define CHECK_FOR_INTERRUPTS()
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
ResourceOwner CurrentResourceOwner
void(* writetup)(Tuplestorestate *state, void *tup)
#define WRITETUP(state, tup)
void tuplestore_get_stats(Tuplestorestate *state, char **max_storage_type, int64 *max_space)
#define READTUP(state, len)
bool tuplestore_gettupleslot(Tuplestorestate *state, bool forward, bool copy, TupleTableSlot *slot)
#define USEMEM(state, amt)
static void writetup_heap(Tuplestorestate *state, void *tup)
void tuplestore_puttupleslot(Tuplestorestate *state, TupleTableSlot *slot)
static void * copytup_heap(Tuplestorestate *state, void *tup)
void tuplestore_select_read_pointer(Tuplestorestate *state, int ptr)
#define COPYTUP(state, tup)
void tuplestore_clear(Tuplestorestate *state)
static bool grow_memtuples(Tuplestorestate *state)
#define FREEMEM(state, amt)
bool tuplestore_gettupleslot_force(Tuplestorestate *state, bool forward, bool copy, TupleTableSlot *slot)
static Tuplestorestate * tuplestore_begin_common(int eflags, bool interXact, int maxKBytes)
static void tuplestore_puttuple_common(Tuplestorestate *state, void *tuple)
int64 tuplestore_tuple_count(Tuplestorestate *state)
void tuplestore_rescan(Tuplestorestate *state)
int tuplestore_alloc_read_pointer(Tuplestorestate *state, int eflags)
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
void tuplestore_trim(Tuplestorestate *state)
void tuplestore_copy_read_pointer(Tuplestorestate *state, int srcptr, int destptr)
bool tuplestore_advance(Tuplestorestate *state, bool forward)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
static void * readtup_heap(Tuplestorestate *state, unsigned int len)
bool tuplestore_in_memory(Tuplestorestate *state)
void tuplestore_end(Tuplestorestate *state)
static void * tuplestore_gettuple(Tuplestorestate *state, bool forward, bool *should_free)
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
bool tuplestore_ateof(Tuplestorestate *state)
static void dumptuples(Tuplestorestate *state)
static void tuplestore_updatemax(Tuplestorestate *state)
void tuplestore_set_eflags(Tuplestorestate *state, int eflags)
bool tuplestore_skiptuples(Tuplestorestate *state, int64 ntuples, bool forward)
static unsigned int getlen(Tuplestorestate *state, bool eofOK)
static MinimalTuple ExecCopySlotMinimalTuple(TupleTableSlot *slot)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)