mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
Allow internal sorts to be stored in memory rather than in files.
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user