dest.h 4.0 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 45 46
 *
 * Copyright (c) 1994, Regents of the University of California
 *
47
 * $Id: dest.h,v 1.22 1999/07/15 23:04:17 momjian Exp $
48 49 50 51 52 53
 *
 *-------------------------------------------------------------------------
 */
#ifndef DEST_H
#define DEST_H

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

/* ----------------
57 58
 *		CommandDest is a simplistic means of identifying the desired
 *		destination.  Someday this will probably need to be improved.
59 60
 * ----------------
 */
61 62 63 64 65 66 67 68 69
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 */
70
} CommandDest;
71

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

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

91
/* The primary destination management functions */
92

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

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

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

107
#endif	 /* DEST_H */