This commit is contained in:
blue-lemon0104
2026-04-07 13:35:22 +08:00
commit 0120fa9ce3
1530 changed files with 424864 additions and 0 deletions

140
pg_include/tcop/dest.h Executable file
View File

@@ -0,0 +1,140 @@
/*-------------------------------------------------------------------------
*
* dest.h
* support for communication destinations
*
* Whenever the backend executes a query that returns tuples, the results
* have to go someplace. For example:
*
* - stdout is the destination only when we are running a
* standalone backend (no postmaster) and are returning results
* back to an interactive user.
*
* - a remote process 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 functions in backend/libpq.
*
* - DestNone is the destination when the system executes
* a query internally. The results are discarded.
*
* dest.c defines three functions that implement destination management:
*
* BeginCommand: initialize the destination at start of command.
* CreateDestReceiver: return a pointer to a struct of destination-specific
* receiver functions.
* EndCommand: clean up the destination at end of command.
*
* BeginCommand/EndCommand are executed once per received SQL query.
*
* CreateDestReceiver returns a receiver object appropriate to the specified
* destination. The executor, as well as utility statements that can return
* tuples, are passed the resulting DestReceiver* pointer. Each executor run
* or utility execution calls the receiver's rStartup method, then the
* receiveSlot method (zero or more times), then the rShutdown method.
* The same receiver object may be re-used multiple times; eventually it is
* destroyed by calling its rDestroy method.
*
* In some cases, receiver objects require additional parameters that must
* be passed to them after calling CreateDestReceiver. Since the set of
* parameters varies for different receiver types, this is not handled by
* this module, but by direct calls from the calling code to receiver type
* specific functions.
*
* The DestReceiver object returned by CreateDestReceiver may be a statically
* allocated object (for destination types that require no local state),
* in which case rDestroy is a no-op. Alternatively it can be a palloc'd
* object that has DestReceiver as its first field and contains additional
* fields (see printtup.c for an example). These 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 rDestroy
* method. Note that the caller of CreateDestReceiver should take care to
* do so in a memory context that is long-lived enough for the receiver
* object not to disappear while still needed.
*
* Special provision: None_Receiver is a permanently available receiver
* object for the DestNone destination. This avoids useless creation/destroy
* calls in portal and cursor manipulations.
*
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/tcop/dest.h
*
*-------------------------------------------------------------------------
*/
#ifndef DEST_H
#define DEST_H
#include "executor/tuptable.h"
/* buffer size to use for command completion tags */
#define COMPLETION_TAG_BUFSIZE 64
/* ----------------
* CommandDest is a simplistic means of identifying the desired
* destination. Someday this will probably need to be improved.
*
* Note: only the values DestNone, DestDebug, DestRemote are legal for the
* global variable whereToSendOutput. The other values may be used
* as the destination for individual commands.
* ----------------
*/
typedef enum
{
DestNone, /* results are discarded */
DestDebug, /* results go to debugging output */
DestRemote, /* results sent to frontend process */
DestRemoteExecute, /* sent to frontend, in Execute command */
DestSPI, /* results sent to SPI manager */
DestTuplestore, /* results sent to Tuplestore */
DestIntoRel, /* results sent to relation (SELECT INTO) */
DestCopyOut, /* results sent to COPY TO code */
DestSQLFunction /* results sent to SQL-language func mgr */
} CommandDest;
/* ----------------
* 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.
*
* Note: the receiveSlot routine must be passed a slot containing a TupleDesc
* identical to the one given to the rStartup routine.
* ----------------
*/
typedef struct _DestReceiver DestReceiver;
struct _DestReceiver
{
/* Called for each tuple to be output: */
void (*receiveSlot) (TupleTableSlot *slot,
DestReceiver *self);
/* Per-executor-run initialization and shutdown: */
void (*rStartup) (DestReceiver *self,
int operation,
TupleDesc typeinfo);
void (*rShutdown) (DestReceiver *self);
/* Destroy the receiver object itself (if dynamically allocated) */
void (*rDestroy) (DestReceiver *self);
/* CommandDest code for this receiver */
CommandDest mydest;
/* Private fields might appear beyond this point... */
};
extern DestReceiver *None_Receiver; /* permanent receiver for DestNone */
/* The primary destination management functions */
extern void BeginCommand(const char *commandTag, CommandDest dest);
extern DestReceiver *CreateDestReceiver(CommandDest dest);
extern void EndCommand(const char *commandTag, CommandDest dest);
/* Additional functions that go with destination management, more or less. */
extern void NullCommand(CommandDest dest);
extern void ReadyForQuery(CommandDest dest);
#endif /* DEST_H */

20
pg_include/tcop/fastpath.h Executable file
View File

@@ -0,0 +1,20 @@
/*-------------------------------------------------------------------------
*
* fastpath.h
*
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/tcop/fastpath.h
*
*-------------------------------------------------------------------------
*/
#ifndef FASTPATH_H
#define FASTPATH_H
#include "lib/stringinfo.h"
extern int HandleFunctionRequest(StringInfo msgBuf);
#endif /* FASTPATH_H */

45
pg_include/tcop/pquery.h Executable file
View File

@@ -0,0 +1,45 @@
/*-------------------------------------------------------------------------
*
* pquery.h
* prototypes for pquery.c.
*
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/tcop/pquery.h
*
*-------------------------------------------------------------------------
*/
#ifndef PQUERY_H
#define PQUERY_H
#include "nodes/parsenodes.h"
#include "utils/portal.h"
extern PGDLLIMPORT Portal ActivePortal;
extern PortalStrategy ChoosePortalStrategy(List *stmts);
extern List *FetchPortalTargetList(Portal portal);
extern List *FetchStatementTargetList(Node *stmt);
extern void PortalStart(Portal portal, ParamListInfo params,
int eflags, Snapshot snapshot);
extern void PortalSetResultFormat(Portal portal, int nFormats,
int16 *formats);
extern bool PortalRun(Portal portal, long count, bool isTopLevel,
DestReceiver *dest, DestReceiver *altdest,
char *completionTag);
extern long PortalRunFetch(Portal portal,
FetchDirection fdirection,
long count,
DestReceiver *dest);
#endif /* PQUERY_H */

44
pg_include/tcop/tcopdebug.h Executable file
View File

@@ -0,0 +1,44 @@
/*-------------------------------------------------------------------------
*
* tcopdebug.h
* #defines governing debugging behaviour in the traffic cop
*
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/tcop/tcopdebug.h
*
*-------------------------------------------------------------------------
*/
#ifndef TCOPDEBUG_H
#define TCOPDEBUG_H
/* ----------------------------------------------------------------
* debugging defines.
*
* If you want certain debugging behaviour, then #define
* the variable to 1, else #undef it. -cim 10/26/89
* ----------------------------------------------------------------
*/
/* ----------------
* TCOP_SHOWSTATS controls whether or not buffer and
* access method statistics are shown for each query. -cim 2/9/89
* ----------------
*/
#undef TCOP_SHOWSTATS
/* ----------------
* TCOP_DONTUSENEWLINE controls the default setting of
* the UseNewLine variable in postgres.c
* ----------------
*/
#undef TCOP_DONTUSENEWLINE
/* ----------------------------------------------------------------
* #defines controlled by above definitions
* ----------------------------------------------------------------
*/
#endif /* TCOPDEBUG_H */

85
pg_include/tcop/tcopprot.h Executable file
View File

@@ -0,0 +1,85 @@
/*-------------------------------------------------------------------------
*
* tcopprot.h
* prototypes for postgres.c.
*
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/tcop/tcopprot.h
*
* OLD COMMENTS
* This file was created so that other c files could get the two
* function prototypes without having to include tcop.h which single
* handedly includes the whole f*cking tree -- mer 5 Nov. 1991
*
*-------------------------------------------------------------------------
*/
#ifndef TCOPPROT_H
#define TCOPPROT_H
#include "executor/execdesc.h"
#include "nodes/parsenodes.h"
#include "storage/procsignal.h"
#include "utils/guc.h"
/* Required daylight between max_stack_depth and the kernel limit, in bytes */
#define STACK_DEPTH_SLOP (512 * 1024L)
extern CommandDest whereToSendOutput;
extern PGDLLIMPORT const char *debug_query_string;
extern int max_stack_depth;
extern int PostAuthDelay;
/* GUC-configurable parameters */
typedef enum
{
LOGSTMT_NONE, /* log no statements */
LOGSTMT_DDL, /* log data definition statements */
LOGSTMT_MOD, /* log modification statements, plus DDL */
LOGSTMT_ALL /* log all statements */
} LogStmtLevel;
extern int log_statement;
extern List *pg_parse_query(const char *query_string);
extern List *pg_analyze_and_rewrite(Node *parsetree, const char *query_string,
Oid *paramTypes, int numParams);
extern List *pg_analyze_and_rewrite_params(Node *parsetree,
const char *query_string,
ParserSetupHook parserSetup,
void *parserSetupArg);
extern PlannedStmt *pg_plan_query(Query *querytree, int cursorOptions,
ParamListInfo boundParams);
extern List *pg_plan_queries(List *querytrees, int cursorOptions,
ParamListInfo boundParams);
extern bool check_max_stack_depth(int *newval, void **extra, GucSource source);
extern void assign_max_stack_depth(int newval, void *extra);
extern void die(SIGNAL_ARGS);
extern void quickdie(SIGNAL_ARGS);
extern void StatementCancelHandler(SIGNAL_ARGS);
extern void FloatExceptionHandler(SIGNAL_ARGS);
extern void RecoveryConflictInterrupt(ProcSignalReason reason); /* called from SIGUSR1
* handler */
extern void prepare_for_client_read(void);
extern void client_read_ended(void);
extern void process_postgres_switches(int argc, char *argv[],
GucContext ctx, const char **dbname);
extern int PostgresMain(int argc, char *argv[],
const char *dbname, const char *username);
extern long get_stack_depth_rlimit(void);
extern void ResetUsage(void);
extern void ShowUsage(const char *title);
extern int check_log_duration(char *msec_str, bool was_logged);
extern void set_debug_options(int debug_flag,
GucContext context, GucSource source);
extern bool set_plan_disabling_options(const char *arg,
GucContext context, GucSource source);
extern const char *get_stats_option_name(const char *arg);
#endif /* TCOPPROT_H */

47
pg_include/tcop/utility.h Executable file
View File

@@ -0,0 +1,47 @@
/*-------------------------------------------------------------------------
*
* utility.h
* prototypes for utility.c.
*
*
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/tcop/utility.h
*
*-------------------------------------------------------------------------
*/
#ifndef UTILITY_H
#define UTILITY_H
#include "tcop/tcopprot.h"
/* Hook for plugins to get control in ProcessUtility() */
typedef void (*ProcessUtility_hook_type) (Node *parsetree,
const char *queryString, ParamListInfo params, bool isTopLevel,
DestReceiver *dest, char *completionTag);
extern PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook;
extern void ProcessUtility(Node *parsetree, const char *queryString,
ParamListInfo params, bool isTopLevel,
DestReceiver *dest, char *completionTag);
extern void standard_ProcessUtility(Node *parsetree, const char *queryString,
ParamListInfo params, bool isTopLevel,
DestReceiver *dest, char *completionTag);
extern bool UtilityReturnsTuples(Node *parsetree);
extern TupleDesc UtilityTupleDescriptor(Node *parsetree);
extern Query *UtilityContainsQuery(Node *parsetree);
extern const char *CreateCommandTag(Node *parsetree);
extern LogStmtLevel GetCommandLogLevel(Node *parsetree);
extern bool CommandIsReadOnly(Node *parsetree);
extern void CheckRelationOwnership(RangeVar *rel, bool noCatalogs);
#endif /* UTILITY_H */