aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/nodes/execnodes.h4
-rw-r--r--src/include/nodes/plannodes.h4
-rw-r--r--src/include/utils/lselect.h31
-rw-r--r--src/include/utils/psort.h65
4 files changed, 74 insertions, 30 deletions
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 3e01132faa3..ff01ff5a62e 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.6 1996/11/04 08:52:54 scrappy Exp $
+ * $Id: execnodes.h,v 1.7 1997/08/06 03:42:02 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -605,7 +605,7 @@ typedef struct SortState {
CommonScanState csstate; /* its first field is NodeTag */
bool sort_Flag;
ScanKey sort_Keys;
- Relation sort_TempRelation;
+ bool cleaned;
} SortState;
/* ----------------
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index b02a370facd..6e786c34f0e 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.5 1996/11/05 08:18:44 scrappy Exp $
+ * $Id: plannodes.h,v 1.6 1997/08/06 03:42:04 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -265,6 +265,8 @@ typedef struct Sort {
Oid tempid;
int keycount;
SortState *sortstate;
+ void *psortstate;
+ bool cleaned;
} Sort;
/* ----------------
diff --git a/src/include/utils/lselect.h b/src/include/utils/lselect.h
index 7cb5f8d185e..048ea932e28 100644
--- a/src/include/utils/lselect.h
+++ b/src/include/utils/lselect.h
@@ -6,15 +6,15 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: lselect.h,v 1.3 1996/11/04 11:51:19 scrappy Exp $
- *
+ * $Id: lselect.h,v 1.4 1997/08/06 03:42:07 momjian Exp $
+ *
*-------------------------------------------------------------------------
*/
#ifndef LSELECT_H
#define LSELECT_H
#include <stdio.h>
-#include <access/htup.h>
+#include "access/htup.h"
struct leftist {
short lt_dist; /* distance to leaf/empty node */
@@ -24,17 +24,26 @@ struct leftist {
struct leftist *lt_right;
};
-extern struct leftist *Tuples;
+/* replaces global variables in lselect.c to make it reentrant */
+typedef struct {
+ TupleDesc tupDesc;
+ int nKeys;
+ ScanKey scanKeys;
+ int sortMem; /* needed for psort */
+} LeftistContextData;
+typedef LeftistContextData *LeftistContext;
-extern struct leftist *lmerge(struct leftist *pt, struct leftist *qt);
-extern HeapTuple gettuple(struct leftist **treep, short *devnum);
-extern int puttuple(struct leftist **treep, HeapTuple newtuple, int devnum);
-extern void dumptuples(FILE *file);
-extern int tuplecmp(HeapTuple ltup, HeapTuple rtup);
+extern struct leftist *lmerge(struct leftist *pt, struct leftist *qt,
+ LeftistContext context);
+extern HeapTuple gettuple(struct leftist **treep, short *devnum,
+ LeftistContext context);
+extern void puttuple(struct leftist **treep, HeapTuple newtuple, short devnum,
+ LeftistContext context);
+extern int tuplecmp(HeapTuple ltup, HeapTuple rtup, LeftistContext context);
#ifdef EBUG
-extern void checktree(struct leftist *tree);
-extern int checktreer(struct leftist *tree, int level);
+extern void checktree(struct leftist *tree, LeftistContext context);
+extern int checktreer(struct leftist *tree, int level, LeftistContext context);
#endif /* EBUG */
#endif /* LSELECT_H */
diff --git a/src/include/utils/psort.h b/src/include/utils/psort.h
index 169c4bdc70f..7ece6090203 100644
--- a/src/include/utils/psort.h
+++ b/src/include/utils/psort.h
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: psort.h,v 1.3 1997/05/20 11:37:33 vadim Exp $
+ * $Id: psort.h,v 1.4 1997/08/06 03:42:13 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -14,11 +14,13 @@
#define PSORT_H
#include <stdio.h>
-#include <access/relscan.h>
+#include "access/relscan.h"
+#include "utils/lselect.h"
+#include "nodes/plannodes.h"
#define SORTMEM (1 << 18) /* 1/4 M - any static memory */
#define MAXTAPES 7 /* 7--See Fig. 70, p273 */
-#define TAPEEXT "pg_psort.XXXXXX" /* TEMPDIR/TAPEEXT */
+#define TAPEEXTLEN strlen("pg_psort.xxxxx.xxx") /* TEMPDIR/TAPEEXT */
#define FREE(x) pfree((char *) x)
struct tape {
@@ -35,13 +37,38 @@ struct cmplist {
struct cmplist *cp_next; /* next in chain */
};
-extern int Nkeys;
-extern ScanKey key;
-extern int SortMemory; /* free memory */
-extern Relation SortRdesc;
-extern struct leftist *Tuples;
+/* This structure preserves the state of psort between calls from different
+ * nodes to its interface functions. Basically, it includes all of the global
+ * variables in psort. In case you were wondering, pointers to these structures
+ * are included in Sort node structures. -Rex 2.6.1995
+ */
+typedef struct Psortstate {
+ LeftistContextData treeContext;
+
+ int TapeRange;
+ int Level;
+ int TotalDummy;
+ struct tape Tape[MAXTAPES];
+
+ int BytesRead;
+ int BytesWritten;
+ int tupcount;
+
+ struct leftist *Tuples;
+
+ FILE *psort_grab_file;
+ long psort_current; /* could be file offset, or array index */
+ long psort_saved; /* could be file offset, or array index */
+ bool using_tape_files;
+
+ HeapTuple *memtuples;
+} Psortstate;
#ifdef EBUG
+#include <stdio.h>
+#include "utils/elog.h"
+#include "storage/buf.h"
+#include "storage/bufmgr.h"
#define PDEBUG(PROC, S1)\
elog(DEBUG, "%s:%d>> PROC: %s.", __FILE__, __LINE__, S1)
@@ -69,15 +96,21 @@ if (1) CODE; else
#endif
/* psort.c */
-extern void psort(Relation oldrel, Relation newrel, int nkeys, ScanKey key);
-extern void initpsort(void);
+extern bool psort_begin(Sort *node, int nkeys, ScanKey key);
+extern void inittapes(Sort *node);
extern void resetpsort(void);
-extern void initialrun(Relation rdesc);
-extern bool createrun(HeapScanDesc sdesc, FILE *file);
-extern HeapTuple tuplecopy(HeapTuple tup, Relation rdesc, Buffer b);
-extern FILE *mergeruns(void);
-extern void merge(struct tape *dest);
-extern void endpsort(Relation rdesc, FILE *file);
+extern void initialrun(Sort *node, bool *empty);
+extern bool createrun(Sort *node, FILE *file, bool *empty);
+extern HeapTuple tuplecopy(HeapTuple tup);
+extern FILE *mergeruns(Sort *node);
+extern void merge(Sort *node, struct tape *dest);
+
+extern void dumptuples(Sort *node);
+extern HeapTuple psort_grabtuple(Sort *node);
+extern void psort_markpos(Sort *node);
+extern void psort_restorepos(Sort *node);
+extern void psort_end(Sort *node);
+
extern FILE *gettape(void);
extern void resettape(FILE *file);
extern void destroytape(FILE *file);