diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-10-17 22:15:09 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-10-17 22:15:09 +0000 |
| commit | 26c48b5e8cffafaf3b8acf345ca9fd8a1e408a54 (patch) | |
| tree | cbcf32d78330eb3414abed1117b0a54090302a97 /src/include | |
| parent | 59ed74e60bb3c1ad2b83ebacbb49f74517d8764e (diff) | |
| download | postgresql-26c48b5e8cffafaf3b8acf345ca9fd8a1e408a54.tar.gz | |
Final stage of psort reconstruction work: replace psort.c with
a generalized module 'tuplesort.c' that can sort either HeapTuples or
IndexTuples, and is not tied to execution of a Sort node. Clean up
memory leakages in sorting, and replace nbtsort.c's private implementation
of mergesorting with calls to tuplesort.c.
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/access/nbtree.h | 13 | ||||
| -rw-r--r-- | src/include/nodes/execnodes.h | 20 | ||||
| -rw-r--r-- | src/include/nodes/plannodes.h | 4 | ||||
| -rw-r--r-- | src/include/utils/tuplesort.h | 68 |
4 files changed, 83 insertions, 22 deletions
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h index 7c57a9a4f9..613595febf 100644 --- a/src/include/access/nbtree.h +++ b/src/include/access/nbtree.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: nbtree.h,v 1.31 1999/08/08 20:12:49 tgl Exp $ + * $Id: nbtree.h,v 1.32 1999/10/17 22:15:03 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -288,9 +288,12 @@ extern BTItem _bt_formitem(IndexTuple itup); /* * prototypes for functions in nbtsort.c */ -extern void *_bt_spoolinit(Relation index, int ntapes, bool isunique); -extern void _bt_spooldestroy(void *spool); -extern void _bt_spool(Relation index, BTItem btitem, void *spool); -extern void _bt_leafbuild(Relation index, void *spool); + +typedef struct BTSpool BTSpool; /* opaque type known only within nbtsort.c */ + +extern BTSpool *_bt_spoolinit(Relation index, bool isunique); +extern void _bt_spooldestroy(BTSpool *btspool); +extern void _bt_spool(BTItem btitem, BTSpool *btspool); +extern void _bt_leafbuild(BTSpool *btspool); #endif /* NBTREE_H */ diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 092fa57acb..44aa8b8ace 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: execnodes.h,v 1.36 1999/09/26 21:21:04 tgl Exp $ + * $Id: execnodes.h,v 1.37 1999/10/17 22:15:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -597,17 +597,9 @@ typedef struct GroupState /* ---------------- * SortState information * - *| sort nodes are really just a kind of a scan since - *| we implement sorts by retrieving the entire subplan - *| into a temp relation, sorting the temp relation into - *| another sorted relation, and then preforming a simple - *| unqualified sequential scan on the sorted relation.. - *| -cim 10/15/89 - * - * Flag indicated whether relation has been sorted - * Keys scan key structures used to keep info on sort keys - * TempRelation temporary relation containing result of executing - * the subplan. + * sort_Done indicates whether sort has been performed yet + * sort_Keys scan key structures describing the sort keys + * tuplesortstate private state of tuplesort.c * * CommonScanState information * @@ -628,9 +620,9 @@ typedef struct GroupState typedef struct SortState { CommonScanState csstate; /* its first field is NodeTag */ - bool sort_Flag; + bool sort_Done; ScanKey sort_Keys; - bool cleaned; + void *tuplesortstate; } SortState; /* ---------------- diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 095ee074d3..a03dacfb02 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: plannodes.h,v 1.30 1999/08/21 03:49:09 tgl Exp $ + * $Id: plannodes.h,v 1.31 1999/10/17 22:15:07 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -288,8 +288,6 @@ typedef struct Sort Oid nonameid; int keycount; SortState *sortstate; - void *psortstate; - bool cleaned; } Sort; /* ---------------- diff --git a/src/include/utils/tuplesort.h b/src/include/utils/tuplesort.h new file mode 100644 index 0000000000..7c5a320989 --- /dev/null +++ b/src/include/utils/tuplesort.h @@ -0,0 +1,68 @@ +/*------------------------------------------------------------------------- + * + * tuplesort.h + * Generalized tuple sorting routines. + * + * This module handles sorting of either heap tuples or index tuples + * (and could fairly easily support other kinds of sortable objects, + * if necessary). It works efficiently for both small and large amounts + * of data. Small amounts are sorted in-memory using qsort(). Large + * amounts are sorted using temporary files and a standard external sort + * algorithm. + * + * Copyright (c) 1994, Regents of the University of California + * + * $Id: tuplesort.h,v 1.1 1999/10/17 22:15:09 tgl Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef TUPLESORT_H +#define TUPLESORT_H + +#include "access/htup.h" +#include "access/itup.h" +#include "access/skey.h" +#include "access/tupdesc.h" +#include "utils/rel.h" + +/* Tuplesortstate is an opaque type whose details are not known outside tuplesort.c. */ + +typedef struct Tuplesortstate Tuplesortstate; + +/* + * We provide two different interfaces to what is essentially the same + * code: one for sorting HeapTuples and one for sorting IndexTuples. + * They differ primarily in the way that the sort key information is + * supplied. + */ + +extern Tuplesortstate *tuplesort_begin_heap(TupleDesc tupDesc, + int nkeys, ScanKey keys, + bool randomAccess); +extern Tuplesortstate *tuplesort_begin_index(Relation indexRel, + bool enforceUnique, + bool randomAccess); + +extern void tuplesort_puttuple(Tuplesortstate *state, void *tuple); + +extern void tuplesort_performsort(Tuplesortstate *state); + +extern void *tuplesort_gettuple(Tuplesortstate *state, bool forward, + bool *should_free); +#define tuplesort_getheaptuple(state, forward, should_free) \ + ((HeapTuple) tuplesort_gettuple(state, forward, should_free)) +#define tuplesort_getindextuple(state, forward, should_free) \ + ((IndexTuple) tuplesort_gettuple(state, forward, should_free)) + +extern void tuplesort_end(Tuplesortstate *state); + +/* + * These routines may only be called if randomAccess was specified 'true'. + * Backwards scan in gettuple is likewise only allowed if randomAccess. + */ + +extern void tuplesort_rescan(Tuplesortstate *state); +extern void tuplesort_markpos(Tuplesortstate *state); +extern void tuplesort_restorepos(Tuplesortstate *state); + +#endif /* TUPLESORT_H */ |
