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-2024, 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 primary.
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() */
71 typedef void (*ProcessUtility_hook_type) (PlannedStmt *pstmt,
72  const char *queryString,
73  bool readOnlyTree,
75  ParamListInfo params,
76  QueryEnvironment *queryEnv,
79 
80 extern void ProcessUtility(PlannedStmt *pstmt, const char *queryString,
81  bool readOnlyTree,
83  QueryEnvironment *queryEnv,
85 extern void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
86  bool readOnlyTree,
88  QueryEnvironment *queryEnv,
90 
93 
94 extern bool UtilityReturnsTuples(Node *parsetree);
95 
96 extern TupleDesc UtilityTupleDescriptor(Node *parsetree);
97 
98 extern Query *UtilityContainsQuery(Node *parsetree);
99 
100 extern CommandTag CreateCommandTag(Node *parsetree);
101 
102 static inline const char *
104 {
105  return GetCommandTagName(CreateCommandTag(parsetree));
106 }
107 
108 extern LogStmtLevel GetCommandLogLevel(Node *parsetree);
109 
110 extern bool CommandIsReadOnly(PlannedStmt *pstmt);
111 
112 #endif /* UTILITY_H */
#define PGDLLIMPORT
Definition: c.h:1316
const char * GetCommandTagName(CommandTag commandTag)
Definition: cmdtag.c:47
CommandTag
Definition: cmdtag.h:23
#define stmt
Definition: indent_codes.h:59
unsigned int Oid
Definition: postgres_ext.h:31
tree context
Definition: radixtree.h:1829
ParamListInfo params
Definition: utility.h:35
QueryEnvironment * queryEnv
Definition: utility.h:36
PlannedStmt * pstmt
Definition: utility.h:32
const char * queryString
Definition: utility.h:33
Definition: nodes.h:129
LogStmtLevel
Definition: tcopprot.h:36
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:540
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:499
bool UtilityReturnsTuples(Node *parsetree)
Definition: utility.c:2025
bool CommandIsReadOnly(PlannedStmt *pstmt)
Definition: utility.c:94
static const char * CreateCommandName(Node *parsetree)
Definition: utility.h:103
CommandTag CreateCommandTag(Node *parsetree)
Definition: utility.c:2359
void ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
Definition: utility.c:1956
void(* ProcessUtility_hook_type)(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.h:71
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:2176
PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:70
TupleDesc UtilityTupleDescriptor(Node *parsetree)
Definition: utility.c:2081
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:3246
ProcessUtilityContext
Definition: utility.h:21
@ PROCESS_UTILITY_SUBCOMMAND
Definition: utility.h:26
@ PROCESS_UTILITY_TOPLEVEL
Definition: utility.h:22
@ PROCESS_UTILITY_QUERY_NONATOMIC
Definition: utility.h:24
@ PROCESS_UTILITY_QUERY
Definition: utility.h:23
struct AlterTableUtilityContext AlterTableUtilityContext