dest.h 4.1 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * dest.h
4
 *		Whenever the backend executes a query, the results
5 6
 *		have to go someplace - either to the standard output,
 *		to a local portal buffer or to a remote portal buffer.
7
 *
8 9 10
 *	  - stdout is the destination only when we are running a
 *		backend without a postmaster and are returning results
 *		back to the user.
11
 *
12 13 14 15
 *	  - a local portal buffer is the destination when a backend
 *		executes a user-defined function which calls PQexec() or
 *		PQfn().  In this case, the results are collected into a
 *		PortalBuffer which the user's function may diddle with.
16
 *
17 18 19 20 21 22 23 24
 *	  - a remote portal buffer is the destination when we are
 *		running a backend with a frontend and the frontend executes
 *		PQexec() or PQfn().  In this case, the results are sent
 *		to the frontend via the pq_ functions.
 *
 *	  - 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.
25
 *
26 27 28 29 30 31 32 33 34 35
 * 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 已提交
36
 * and contains additional fields (see printtup.c for an example).	These
37 38 39 40 41 42 43
 * 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.
44
 *
B
Add:  
Bruce Momjian 已提交
45 46
 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
 * Portions Copyright (c) 1994, Regents of the University of California
47
 *
B
Add:  
Bruce Momjian 已提交
48
 * $Id: dest.h,v 1.23 2000/01/26 05:58:35 momjian Exp $
49 50 51 52 53 54
 *
 *-------------------------------------------------------------------------
 */
#ifndef DEST_H
#define DEST_H

55
#include "access/htup.h"
56 57

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

73 74 75 76 77 78 79
/* ----------------
 *		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;
80

B
Bruce Momjian 已提交
81 82
struct _DestReceiver
{
83
	/* Called for each tuple to be output: */
B
Bruce Momjian 已提交
84
	void		(*receiveTuple) (HeapTuple tuple, TupleDesc typeinfo,
85
											 DestReceiver *self);
86
	/* Initialization and teardown: */
87 88
	void		(*setup) (DestReceiver *self, TupleDesc typeinfo);
	void		(*cleanup) (DestReceiver *self);
89 90
	/* Private fields might appear beyond this point... */
};
91

92
/* The primary destination management functions */
93

94
extern void BeginCommand(char *pname, int operation, TupleDesc attinfo,
B
Bruce Momjian 已提交
95 96 97
			 bool isIntoRel, bool isIntoPortal, char *tag,
			 CommandDest dest);
extern DestReceiver *DestToFunction(CommandDest dest);
98
extern void EndCommand(char *commandTag, CommandDest dest);
99 100 101

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

102 103 104
extern void SendCopyBegin(void);
extern void ReceiveCopyBegin(void);
extern void NullCommand(CommandDest dest);
B
Bruce Momjian 已提交
105
extern void ReadyForQuery(CommandDest dest);
106
extern void UpdateCommandInfo(int operation, Oid lastoid, uint32 tuples);
107

108
#endif	 /* DEST_H */