psort.h 2.63 KB
Newer Older
1 2 3
/*-------------------------------------------------------------------------
 *
 * psort.h--
4
 *
5 6 7 8
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
9
 * $Id: psort.h,v 1.11 1997/09/15 14:29:01 vadim Exp $
10 11 12
 *
 *-------------------------------------------------------------------------
 */
13 14
#ifndef PSORT_H
#define PSORT_H
15

16
#include <stdio.h>
17 18 19
#include "access/relscan.h"
#include "utils/lselect.h"
#include "nodes/plannodes.h"
20

21 22 23
#define MAXTAPES		7		/* 7--See Fig. 70, p273 */
#define TAPEEXTLEN		strlen("pg_psort.xxxxx.xxx")	/* TEMPDIR/TAPEEXT */
#define FREE(x)			pfree((char *) x)
24

25 26
struct tape
{
27 28 29 30
	int			tp_dummy;		/* (D) */
	int			tp_fib;			/* (A) */
	FILE	   *tp_file;		/* (TAPE) */
	struct tape *tp_prev;
31 32
};

33 34
struct cmplist
{
35 36 37
	int			cp_attn;		/* attribute number */
	int			cp_num;			/* comparison function code */
	int			cp_rev;			/* invert comparison flag */
38
	struct cmplist *cp_next;	/* next in chain */
39 40
};

41 42 43
/* 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
44
 * are included in Sort node structures.						-Rex 2.6.1995
45
 */
46 47 48
typedef struct Psortstate
{
	LeftistContextData treeContext;
49

50 51 52 53
	int			TapeRange;
	int			Level;
	int			TotalDummy;
	struct tape Tape[MAXTAPES];
54

55 56 57
	int			BytesRead;
	int			BytesWritten;
	int			tupcount;
58

59
	struct leftist *Tuples;
60

61 62 63 64
	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;
65

66
	HeapTuple  *memtuples;
67
} Psortstate;
68 69

#ifdef	EBUG
70 71 72 73
#include <stdio.h>
#include "utils/elog.h"
#include "storage/buf.h"
#include "storage/bufmgr.h"
74

75
#define PDEBUG(PROC, S1)\
76 77
elog(DEBUG, "%s:%d>> PROC: %s.", __FILE__, __LINE__, S1)

78
#define PDEBUG2(PROC, S1, D1)\
79 80
elog(DEBUG, "%s:%d>> PROC: %s %d.", __FILE__, __LINE__, S1, D1)

81
#define PDEBUG4(PROC, S1, D1, S2, D2)\
82 83
elog(DEBUG, "%s:%d>> PROC: %s %d, %s %d.", __FILE__, __LINE__, S1, D1, S2, D2)

84
#define VDEBUG(VAR, FMT)\
85 86
elog(DEBUG, "%s:%d>> VAR =FMT", __FILE__, __LINE__, VAR)

87
#define ASSERT(EXPR, STR)\
88 89
if (!(EXPR)) elog(FATAL, "%s:%d>> %s", __FILE__, __LINE__, STR)

90
#define TRACE(VAL, CODE)\
91 92 93
if (1) CODE; else

#else
94 95 96 97
#define PDEBUG(MSG)
#define VDEBUG(VAR, FMT)
#define ASSERT(EXPR, MSG)
#define TRACE(VAL, CODE)
98 99 100
#endif

/* psort.c */
101
extern bool psort_begin(Sort *node, int nkeys, ScanKey key);
Vadim B. Mikheev's avatar
Vadim B. Mikheev committed
102
extern HeapTuple psort_grabtuple(Sort *node, bool *should_free);
103 104 105
extern void psort_markpos(Sort *node);
extern void psort_restorepos(Sort *node);
extern void psort_end(Sort *node);
106

107
#endif							/* PSORT_H */