dest.h 3.7 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * dest.h
4
 *		Whenever the backend executes a query, the results
5
 *		have to go someplace.
6
 *
7 8
 *	  - stdout is the destination only when we are running a
 *		backend without a postmaster and are returning results
9
 *		back to an interactive user.
10
 *
11
 *	  - a remote process is the destination when we are
12 13
 *		running a backend with a frontend and the frontend executes
 *		PQexec() or PQfn().  In this case, the results are sent
14
 *		to the frontend via the functions in backend/libpq.
15 16 17 18
 *
 *	  - None is the destination when the system executes
 *		a query internally.  This is not used now but it may be
 *		useful for the parallel optimiser/executor.
19
 *
20 21 22 23 24 25 26 27 28 29
 * dest.c defines three functions that implement destination management:
 *
 * BeginCommand: initialize the destination.
 * DestToFunction: return a pointer to a struct of destination-specific
 * receiver functions.
 * EndCommand: clean up the destination when output is complete.
 *
 * 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 已提交
30
 * and contains additional fields (see printtup.c for an example).	These
31 32 33 34 35 36 37
 * 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.
 *
 * XXX FIXME: the initialization and cleanup code that currently appears
 * in-line in BeginCommand and EndCommand probably should be moved out
 * to routines associated with each destination receiver type.
38
 *
39
 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
40
 * Portions Copyright (c) 1994, Regents of the University of California
41
 *
42
 * $Id: dest.h,v 1.27 2001/10/28 06:26:09 momjian Exp $
43 44 45 46 47 48
 *
 *-------------------------------------------------------------------------
 */
#ifndef DEST_H
#define DEST_H

49
#include "access/htup.h"
50 51

/* ----------------
52 53
 *		CommandDest is a simplistic means of identifying the desired
 *		destination.  Someday this will probably need to be improved.
54 55
 * ----------------
 */
56 57
typedef enum
{
58 59 60 61
	None,						/* results are discarded */
	Debug,						/* results go to debugging output */
	Remote,						/* results sent to frontend process */
	RemoteInternal,				/* results sent to frontend process in
62
								 * internal (binary) form */
63
	SPI							/* results sent to SPI manager */
64
} CommandDest;
65

66 67 68 69 70 71 72
/* ----------------
 *		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;
73

B
Bruce Momjian 已提交
74 75
struct _DestReceiver
{
76
	/* Called for each tuple to be output: */
B
Bruce Momjian 已提交
77
	void		(*receiveTuple) (HeapTuple tuple, TupleDesc typeinfo,
78
											 DestReceiver *self);
79
	/* Initialization and teardown: */
80 81
	void		(*setup) (DestReceiver *self, TupleDesc typeinfo);
	void		(*cleanup) (DestReceiver *self);
82 83
	/* Private fields might appear beyond this point... */
};
84

85
/* The primary destination management functions */
86

87
extern void BeginCommand(char *pname, int operation, TupleDesc attinfo,
B
Bruce Momjian 已提交
88 89 90
			 bool isIntoRel, bool isIntoPortal, char *tag,
			 CommandDest dest);
extern DestReceiver *DestToFunction(CommandDest dest);
91
extern void EndCommand(char *commandTag, CommandDest dest);
92 93 94

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

95 96 97
extern void SendCopyBegin(void);
extern void ReceiveCopyBegin(void);
extern void NullCommand(CommandDest dest);
B
Bruce Momjian 已提交
98
extern void ReadyForQuery(CommandDest dest);
99
extern void UpdateCommandInfo(int operation, Oid lastoid, uint32 tuples);
100

101
#endif	 /* DEST_H */