Commit 42c0cd33 authored by Bruce Momjian's avatar Bruce Momjian

I think I finally got psort working for all cases.

parent cc24b846
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.8 1997/08/06 05:38:38 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.9 1997/08/06 07:02:48 momjian Exp $
* *
* NOTES * NOTES
* Sorts the first relation into the second relation. * Sorts the first relation into the second relation.
...@@ -123,7 +123,7 @@ psort_begin(Sort *node, int nkeys, ScanKey key) ...@@ -123,7 +123,7 @@ psort_begin(Sort *node, int nkeys, ScanKey key)
PS(node)->BytesRead = 0; PS(node)->BytesRead = 0;
PS(node)->BytesWritten = 0; PS(node)->BytesWritten = 0;
PS(node)->treeContext.tupDesc = PS(node)->treeContext.tupDesc =
ExecGetTupType(outerPlan((Plan *)node)); ExecGetTupType(outerPlan((Plan *)node));
PS(node)->treeContext.nKeys = nkeys; PS(node)->treeContext.nKeys = nkeys;
PS(node)->treeContext.scanKeys = key; PS(node)->treeContext.scanKeys = key;
PS(node)->treeContext.sortMem = SortMem * 1024; PS(node)->treeContext.sortMem = SortMem * 1024;
...@@ -276,7 +276,7 @@ initialrun(Sort *node, bool *empty) ...@@ -276,7 +276,7 @@ initialrun(Sort *node, bool *empty)
tp = PS(node)->Tape; tp = PS(node)->Tape;
if ((bool)createrun(node, tp->tp_file, empty) != false) { if ((bool)createrun(node, NULL, empty) != false) {
if (! PS(node)->using_tape_files) if (! PS(node)->using_tape_files)
inittapes(node); inittapes(node);
extrapasses = 0; extrapasses = 0;
...@@ -307,7 +307,7 @@ initialrun(Sort *node, bool *empty) ...@@ -307,7 +307,7 @@ initialrun(Sort *node, bool *empty)
} /* D3 */ } /* D3 */
if (extrapasses) if (extrapasses)
if (--extrapasses) { if (--extrapasses) {
dumptuples(node); dumptuples(tp->tp_file, node);
ENDRUN(tp->tp_file); ENDRUN(tp->tp_file);
continue; continue;
} else } else
...@@ -360,9 +360,11 @@ createrun(Sort *node, FILE *file, bool *empty) ...@@ -360,9 +360,11 @@ createrun(Sort *node, FILE *file, bool *empty)
} }
lasttuple = tup = gettuple(&PS(node)->Tuples, &junk, lasttuple = tup = gettuple(&PS(node)->Tuples, &junk,
&PS(node)->treeContext); &PS(node)->treeContext);
if (! PS(node)->using_tape_files) if (! PS(node)->using_tape_files) {
inittapes(node); inittapes(node);
PUTTUP(node, tup, PS(node)->Tape->tp_file); file = PS(node)->Tape->tp_file; /* was NULL */
}
PUTTUP(node, tup, file);
TRACEOUT(createrun, tup); TRACEOUT(createrun, tup);
} }
if (LACKMEM(node)) if (LACKMEM(node))
...@@ -400,7 +402,7 @@ createrun(Sort *node, FILE *file, bool *empty) ...@@ -400,7 +402,7 @@ createrun(Sort *node, FILE *file, bool *empty)
FREE(lasttuple); FREE(lasttuple);
TRACEMEM(createrun); TRACEMEM(createrun);
} }
dumptuples(node); dumptuples(file, node);
if (PS(node)->using_tape_files) if (PS(node)->using_tape_files)
ENDRUN(file); ENDRUN(file);
/* delimit the end of the run */ /* delimit the end of the run */
...@@ -561,7 +563,7 @@ merge(Sort *node, struct tape *dest) ...@@ -561,7 +563,7 @@ merge(Sort *node, struct tape *dest)
* dumptuples - stores all the tuples in tree into file * dumptuples - stores all the tuples in tree into file
*/ */
void void
dumptuples(Sort *node) dumptuples(FILE *file, Sort *node)
{ {
register struct leftist *tp; register struct leftist *tp;
register struct leftist *newp; register struct leftist *newp;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: psort.h,v 1.5 1997/08/06 05:38:46 momjian Exp $ * $Id: psort.h,v 1.6 1997/08/06 07:02:49 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -104,7 +104,7 @@ extern HeapTuple tuplecopy(HeapTuple tup); ...@@ -104,7 +104,7 @@ extern HeapTuple tuplecopy(HeapTuple tup);
extern FILE *mergeruns(Sort *node); extern FILE *mergeruns(Sort *node);
extern void merge(Sort *node, struct tape *dest); extern void merge(Sort *node, struct tape *dest);
extern void dumptuples(Sort *node); extern void dumptuples(FILE *file, Sort *node);
extern HeapTuple psort_grabtuple(Sort *node); extern HeapTuple psort_grabtuple(Sort *node);
extern void psort_markpos(Sort *node); extern void psort_markpos(Sort *node);
extern void psort_restorepos(Sort *node); extern void psort_restorepos(Sort *node);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment