Skip to content

Commit 42c0cd3

Browse files
committed
I think I finally got psort working for all cases.
1 parent cc24b84 commit 42c0cd3

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/backend/utils/sort/psort.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.8 1997/08/06 05:38:38 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.9 1997/08/06 07:02:48 momjian Exp $
1111
*
1212
* NOTES
1313
* Sorts the first relation into the second relation.
@@ -123,7 +123,7 @@ psort_begin(Sort *node, int nkeys, ScanKey key)
123123
PS(node)->BytesRead = 0;
124124
PS(node)->BytesWritten = 0;
125125
PS(node)->treeContext.tupDesc =
126-
ExecGetTupType(outerPlan((Plan *)node));
126+
ExecGetTupType(outerPlan((Plan *)node));
127127
PS(node)->treeContext.nKeys = nkeys;
128128
PS(node)->treeContext.scanKeys = key;
129129
PS(node)->treeContext.sortMem = SortMem * 1024;
@@ -276,7 +276,7 @@ initialrun(Sort *node, bool *empty)
276276

277277
tp = PS(node)->Tape;
278278

279-
if ((bool)createrun(node, tp->tp_file, empty) != false) {
279+
if ((bool)createrun(node, NULL, empty) != false) {
280280
if (! PS(node)->using_tape_files)
281281
inittapes(node);
282282
extrapasses = 0;
@@ -307,7 +307,7 @@ initialrun(Sort *node, bool *empty)
307307
} /* D3 */
308308
if (extrapasses)
309309
if (--extrapasses) {
310-
dumptuples(node);
310+
dumptuples(tp->tp_file, node);
311311
ENDRUN(tp->tp_file);
312312
continue;
313313
} else
@@ -360,9 +360,11 @@ createrun(Sort *node, FILE *file, bool *empty)
360360
}
361361
lasttuple = tup = gettuple(&PS(node)->Tuples, &junk,
362362
&PS(node)->treeContext);
363-
if (! PS(node)->using_tape_files)
363+
if (! PS(node)->using_tape_files) {
364364
inittapes(node);
365-
PUTTUP(node, tup, PS(node)->Tape->tp_file);
365+
file = PS(node)->Tape->tp_file; /* was NULL */
366+
}
367+
PUTTUP(node, tup, file);
366368
TRACEOUT(createrun, tup);
367369
}
368370
if (LACKMEM(node))
@@ -400,7 +402,7 @@ createrun(Sort *node, FILE *file, bool *empty)
400402
FREE(lasttuple);
401403
TRACEMEM(createrun);
402404
}
403-
dumptuples(node);
405+
dumptuples(file, node);
404406
if (PS(node)->using_tape_files)
405407
ENDRUN(file);
406408
/* delimit the end of the run */
@@ -561,7 +563,7 @@ merge(Sort *node, struct tape *dest)
561563
* dumptuples - stores all the tuples in tree into file
562564
*/
563565
void
564-
dumptuples(Sort *node)
566+
dumptuples(FILE *file, Sort *node)
565567
{
566568
register struct leftist *tp;
567569
register struct leftist *newp;

src/include/utils/psort.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: psort.h,v 1.5 1997/08/06 05:38:46 momjian Exp $
9+
* $Id: psort.h,v 1.6 1997/08/06 07:02:49 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -104,7 +104,7 @@ extern HeapTuple tuplecopy(HeapTuple tup);
104104
extern FILE *mergeruns(Sort *node);
105105
extern void merge(Sort *node, struct tape *dest);
106106

107-
extern void dumptuples(Sort *node);
107+
extern void dumptuples(FILE *file, Sort *node);
108108
extern HeapTuple psort_grabtuple(Sort *node);
109109
extern void psort_markpos(Sort *node);
110110
extern void psort_restorepos(Sort *node);

0 commit comments

Comments
 (0)