dest.h 3.9 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * dest.h
4 5 6 7
 *	  support for communication destinations
 *
 * Whenever the backend executes a query, the results
 * have to go someplace.
8
 *
9
 *	  - stdout is the destination only when we are running a
10
 *		standalone backend (no postmaster) and are returning results
11
 *		back to an interactive user.
12
 *
13
 *	  - a remote process is the destination when we are
14 15
 *		running a backend with a frontend and the frontend executes
 *		PQexec() or PQfn().  In this case, the results are sent
16
 *		to the frontend via the functions in backend/libpq.
17 18
 *
 *	  - None is the destination when the system executes
19
 *		a query internally.  The results are discarded.
20
 *
21 22
 * dest.c defines three functions that implement destination management:
 *
23
 * BeginCommand: initialize the destination at start of command.
24 25
 * DestToFunction: return a pointer to a struct of destination-specific
 * receiver functions.
26 27 28 29 30 31 32 33
 * EndCommand: clean up the destination at end of command.
 *
 * BeginCommand/EndCommand are executed once per received SQL query.
 *
 * DestToFunction, and the receiver functions it links to, are executed
 * each time we run the executor to produce tuples, which may occur
 * multiple times per received query (eg, due to additional queries produced
 * by rewrite rules).
34 35 36 37
 *
 * The DestReceiver object returned by DestToFunction may be a statically
 * allocated object (for destination types that require no local state)
 * or can be a palloc'd object that has DestReceiver as its first field
B
Bruce Momjian 已提交
38
 * and contains additional fields (see printtup.c for an example).	These
39 40 41 42
 * additional fields are then accessible to the DestReceiver functions
 * by casting the DestReceiver* pointer passed to them.
 * The palloc'd object is pfree'd by the DestReceiver's cleanup function.
 *
43
 *
B
Bruce Momjian 已提交
44
 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
45
 * Portions Copyright (c) 1994, Regents of the University of California
46
 *
47
 * $Id: dest.h,v 1.33 2003/03/27 16:51:29 momjian Exp $
48 49 50 51 52 53
 *
 *-------------------------------------------------------------------------
 */
#ifndef DEST_H
#define DEST_H

54
#include "access/htup.h"
55

56 57 58 59 60

/* buffer size to use for command completion tags */
#define COMPLETION_TAG_BUFSIZE	64


61
/* ----------------
62 63
 *		CommandDest is a simplistic means of identifying the desired
 *		destination.  Someday this will probably need to be improved.
64 65
 * ----------------
 */
66 67
typedef enum
{
68 69 70 71
	None,						/* results are discarded */
	Debug,						/* results go to debugging output */
	Remote,						/* results sent to frontend process */
	RemoteInternal,				/* results sent to frontend process in
72
								 * internal (binary) form */
73 74
	SPI,						/* results sent to SPI manager */
	Tuplestore					/* results sent to Tuplestore */
75
} CommandDest;
76

77 78 79 80 81 82 83
/* ----------------
 *		DestReceiver is a base type for destination-specific local state.
 *		In the simplest cases, there is no state info, just the function
 *		pointers that the executor must call.
 * ----------------
 */
typedef struct _DestReceiver DestReceiver;
84

B
Bruce Momjian 已提交
85 86
struct _DestReceiver
{
87
	/* Called for each tuple to be output: */
B
Bruce Momjian 已提交
88
	void		(*receiveTuple) (HeapTuple tuple, TupleDesc typeinfo,
B
Bruce Momjian 已提交
89
											 DestReceiver *self);
90
	/* Initialization and teardown: */
91
	void		(*setup) (DestReceiver *self, int operation,
B
Bruce Momjian 已提交
92
							 const char *portalName, TupleDesc typeinfo);
93
	void		(*cleanup) (DestReceiver *self);
94 95
	/* Private fields might appear beyond this point... */
};
96

97
/* The primary destination management functions */
98

99
extern void BeginCommand(const char *commandTag, CommandDest dest);
B
Bruce Momjian 已提交
100
extern DestReceiver *DestToFunction(CommandDest dest);
101
extern void EndCommand(const char *commandTag, CommandDest dest);
102 103 104

/* Additional functions that go with destination management, more or less. */

105 106 107
extern void SendCopyBegin(void);
extern void ReceiveCopyBegin(void);
extern void NullCommand(CommandDest dest);
B
Bruce Momjian 已提交
108
extern void ReadyForQuery(CommandDest dest);
109

110
#endif   /* DEST_H */