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/cmdtag.h"
18 #include "tcop/tcopprot.h"
19 
20 typedef enum
21 {
22  PROCESS_UTILITY_TOPLEVEL, /* toplevel interactive command */
23  PROCESS_UTILITY_QUERY, /* a complete query, but not toplevel */
24  PROCESS_UTILITY_QUERY_NONATOMIC, /* a complete query, nonatomic
25  * execution context */
26  PROCESS_UTILITY_SUBCOMMAND /* a portion of a query */
28 
29 /* Info needed when recursing from ALTER TABLE */
31 {
32  PlannedStmt *pstmt; /* PlannedStmt for outer ALTER TABLE command */
33  const char *queryString; /* its query string */
34  Oid relid; /* OID of ALTER's target table */
35  ParamListInfo params; /* any parameters available to ALTER TABLE */
36  QueryEnvironment *queryEnv; /* execution environment for ALTER TABLE */
38 
39 /*
40  * These constants are used to describe the extent to which a particular
41  * command is read-only.
42  *
43  * COMMAND_OK_IN_READ_ONLY_TXN means that the command is permissible even when
44  * XactReadOnly is set. This bit should be set for commands that don't change
45  * the state of the database (data or schema) in a way that would affect the
46  * output of pg_dump.
47  *
48  * COMMAND_OK_IN_PARALLEL_MODE means that the command is permissible even
49  * when in parallel mode. Writing tuples is forbidden, as is anything that
50  * might confuse cooperating processes.
51  *
52  * COMMAND_OK_IN_RECOVERY means that the command is permissible even when in
53  * recovery. It can't write WAL, nor can it do things that would imperil
54  * replay of future WAL received from the master.
55  */
56 #define COMMAND_OK_IN_READ_ONLY_TXN 0x0001
57 #define COMMAND_OK_IN_PARALLEL_MODE 0x0002
58 #define COMMAND_OK_IN_RECOVERY 0x0004
59 
60 /*
61  * We say that a command is strictly read-only if it is sufficiently read-only
62  * for all purposes. For clarity, we also have a constant for commands that are
63  * in no way read-only.
64  */
65 #define COMMAND_IS_STRICTLY_READ_ONLY \
66  (COMMAND_OK_IN_READ_ONLY_TXN | COMMAND_OK_IN_RECOVERY | \
67  COMMAND_OK_IN_PARALLEL_MODE)
68 #define COMMAND_IS_NOT_READ_ONLY 0
69 
70 /* Hook for plugins to get control in ProcessUtility() */
72  const char *queryString, ProcessUtilityContext context,
77 
78 extern void ProcessUtility(PlannedStmt *pstmt, const char *queryString,
82 extern void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
86 
87 extern void ProcessUtilityForAlterTable(Node *stmt,
88  AlterTableUtilityContext *context);
89 
90 extern bool UtilityReturnsTuples(Node *parsetree);
91 
92 extern TupleDesc UtilityTupleDescriptor(Node *parsetree);
93 
94 extern Query *UtilityContainsQuery(Node *parsetree);
95 
96 extern CommandTag CreateCommandTag(Node *parsetree);
97 
98 static inline const char *
100 {
101  return GetCommandTagName(CreateCommandTag(parsetree));
102 }
103 
104 extern LogStmtLevel GetCommandLogLevel(Node *parsetree);
105 
106 extern bool CommandIsReadOnly(PlannedStmt *pstmt);
107 
108 #endif /* UTILITY_H */
CommandTag
Definition: cmdtag.h:20
void(* ProcessUtility_hook_type)(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.h:71
bool UtilityReturnsTuples(Node *parsetree)
Definition: utility.c:1913
LogStmtLevel
Definition: tcopprot.h:35
PlannedStmt * pstmt
Definition: utility.h:32
static const char * CreateCommandName(Node *parsetree)
Definition: utility.h:99
TupleDesc UtilityTupleDescriptor(Node *parsetree)
Definition: utility.c:1969
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:501
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:3121
Definition: nodes.h:529
ProcessUtilityContext
Definition: utility.h:20
bool CommandIsReadOnly(PlannedStmt *pstmt)
Definition: utility.c:99
unsigned int Oid
Definition: postgres_ext.h:31
struct AlterTableUtilityContext AlterTableUtilityContext
void ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
Definition: utility.c:1845
#define PGDLLIMPORT
Definition: c.h:1280
const char * queryString
Definition: utility.h:33
QueryEnvironment * queryEnv
Definition: utility.h:36
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:541
const char * GetCommandTagName(CommandTag commandTag)
Definition: cmdtag.c:45
PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:75
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:2063
ParamListInfo params
Definition: utility.h:35
CommandTag CreateCommandTag(Node *parsetree)
Definition: utility.c:2246