PostgreSQL Source Code  git master
utility.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * utility.h
4  * prototypes for utility.c.
5  *
6  *
7  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/tcop/utility.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef UTILITY_H
15 #define UTILITY_H
16 
17 #include "tcop/tcopprot.h"
18 
19 typedef enum
20 {
21  PROCESS_UTILITY_TOPLEVEL, /* toplevel interactive command */
22  PROCESS_UTILITY_QUERY, /* a complete query, but not toplevel */
23  PROCESS_UTILITY_QUERY_NONATOMIC, /* a complete query, nonatomic
24  * execution context */
25  PROCESS_UTILITY_SUBCOMMAND /* a portion of a query */
27 
28 /* Info needed when recursing from ALTER TABLE */
30 {
31  PlannedStmt *pstmt; /* PlannedStmt for outer ALTER TABLE command */
32  const char *queryString; /* its query string */
33  Oid relid; /* OID of ALTER's target table */
34  ParamListInfo params; /* any parameters available to ALTER TABLE */
35  QueryEnvironment *queryEnv; /* execution environment for ALTER TABLE */
37 
38 /*
39  * These constants are used to describe the extent to which a particular
40  * command is read-only.
41  *
42  * COMMAND_OK_IN_READ_ONLY_TXN means that the command is permissible even when
43  * XactReadOnly is set. This bit should be set for commands that don't change
44  * the state of the database (data or schema) in a way that would affect the
45  * output of pg_dump.
46  *
47  * COMMAND_OK_IN_PARALLEL_MODE means that the command is permissible even
48  * when in parallel mode. Writing tuples is forbidden, as is anything that
49  * might confuse cooperating processes.
50  *
51  * COMMAND_OK_IN_RECOVERY means that the command is permissible even when in
52  * recovery. It can't write WAL, nor can it do things that would imperil
53  * replay of future WAL received from the master.
54  */
55 #define COMMAND_OK_IN_READ_ONLY_TXN 0x0001
56 #define COMMAND_OK_IN_PARALLEL_MODE 0x0002
57 #define COMMAND_OK_IN_RECOVERY 0x0004
58 
59 /*
60  * We say that a command is strictly read-only if it is sufficiently read-only
61  * for all purposes. For clarity, we also have a constant for commands that are
62  * in no way read-only.
63  */
64 #define COMMAND_IS_STRICTLY_READ_ONLY \
65  (COMMAND_OK_IN_READ_ONLY_TXN | COMMAND_OK_IN_RECOVERY | \
66  COMMAND_OK_IN_PARALLEL_MODE)
67 #define COMMAND_IS_NOT_READ_ONLY 0
68 
69 /* Hook for plugins to get control in ProcessUtility() */
71  const char *queryString, ProcessUtilityContext context,
74  DestReceiver *dest, char *completionTag);
76 
77 extern void ProcessUtility(PlannedStmt *pstmt, const char *queryString,
80  DestReceiver *dest, char *completionTag);
81 extern void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
84  DestReceiver *dest, char *completionTag);
85 
86 extern void ProcessUtilityForAlterTable(Node *stmt,
87  AlterTableUtilityContext *context);
88 
89 extern bool UtilityReturnsTuples(Node *parsetree);
90 
91 extern TupleDesc UtilityTupleDescriptor(Node *parsetree);
92 
93 extern Query *UtilityContainsQuery(Node *parsetree);
94 
95 extern const char *CreateCommandTag(Node *parsetree);
96 
97 extern LogStmtLevel GetCommandLogLevel(Node *parsetree);
98 
99 extern bool CommandIsReadOnly(PlannedStmt *pstmt);
100 
101 #endif /* UTILITY_H */
bool UtilityReturnsTuples(Node *parsetree)
Definition: utility.c:1916
LogStmtLevel
Definition: tcopprot.h:35
PlannedStmt * pstmt
Definition: utility.h:31
TupleDesc UtilityTupleDescriptor(Node *parsetree)
Definition: utility.c:1972
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:3124
Definition: nodes.h:525
ProcessUtilityContext
Definition: utility.h:19
bool CommandIsReadOnly(PlannedStmt *pstmt)
Definition: utility.c:100
unsigned int Oid
Definition: postgres_ext.h:31
struct AlterTableUtilityContext AlterTableUtilityContext
void ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
Definition: utility.c:1848
#define PGDLLIMPORT
Definition: c.h:1271
const char * queryString
Definition: utility.h:32
void(* ProcessUtility_hook_type)(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.h:70
QueryEnvironment * queryEnv
Definition: utility.h:35
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.c:543
PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:75
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:2066
ParamListInfo params
Definition: utility.h:34
const char * CreateCommandTag(Node *parsetree)
Definition: utility.c:2252
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.c:504