PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
utility.c File Reference
#include "postgres.h"
#include "access/reloptions.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "catalog/namespace.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_inherits.h"
#include "catalog/toasting.h"
#include "commands/alter.h"
#include "commands/async.h"
#include "commands/cluster.h"
#include "commands/collationcmds.h"
#include "commands/comment.h"
#include "commands/conversioncmds.h"
#include "commands/copy.h"
#include "commands/createas.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/discard.h"
#include "commands/event_trigger.h"
#include "commands/explain.h"
#include "commands/extension.h"
#include "commands/lockcmds.h"
#include "commands/matview.h"
#include "commands/policy.h"
#include "commands/portalcmds.h"
#include "commands/prepare.h"
#include "commands/proclang.h"
#include "commands/publicationcmds.h"
#include "commands/schemacmds.h"
#include "commands/seclabel.h"
#include "commands/sequence.h"
#include "commands/subscriptioncmds.h"
#include "commands/tablecmds.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "commands/typecmds.h"
#include "commands/user.h"
#include "commands/vacuum.h"
#include "commands/view.h"
#include "miscadmin.h"
#include "parser/parse_utilcmd.h"
#include "postmaster/bgwriter.h"
#include "rewrite/rewriteDefine.h"
#include "storage/fd.h"
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
Include dependency graph for utility.c:

Go to the source code of this file.

Functions

static int ClassifyUtilityCommandAsReadOnly (Node *parsetree)
 
static void ProcessUtilitySlow (ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
static void ExecDropStmt (DropStmt *stmt, bool isTopLevel)
 
bool CommandIsReadOnly (PlannedStmt *pstmt)
 
void PreventCommandIfReadOnly (const char *cmdname)
 
void PreventCommandIfParallelMode (const char *cmdname)
 
void PreventCommandDuringRecovery (const char *cmdname)
 
static void CheckRestrictedOperation (const char *cmdname)
 
void ProcessUtility (PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
void standard_ProcessUtility (PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
void ProcessUtilityForAlterTable (Node *stmt, AlterTableUtilityContext *context)
 
bool UtilityReturnsTuples (Node *parsetree)
 
TupleDesc UtilityTupleDescriptor (Node *parsetree)
 
QueryUtilityContainsQuery (Node *parsetree)
 
static CommandTag AlterObjectTypeCommandTag (ObjectType objtype)
 
CommandTag CreateCommandTag (Node *parsetree)
 
LogStmtLevel GetCommandLogLevel (Node *parsetree)
 

Variables

ProcessUtility_hook_type ProcessUtility_hook = NULL
 

Function Documentation

◆ AlterObjectTypeCommandTag()

static CommandTag AlterObjectTypeCommandTag ( ObjectType  objtype)
static

Definition at line 2216 of file utility.c.

2217{
2218 CommandTag tag;
2219
2220 switch (objtype)
2221 {
2222 case OBJECT_AGGREGATE:
2223 tag = CMDTAG_ALTER_AGGREGATE;
2224 break;
2225 case OBJECT_ATTRIBUTE:
2226 tag = CMDTAG_ALTER_TYPE;
2227 break;
2228 case OBJECT_CAST:
2229 tag = CMDTAG_ALTER_CAST;
2230 break;
2231 case OBJECT_COLLATION:
2232 tag = CMDTAG_ALTER_COLLATION;
2233 break;
2234 case OBJECT_COLUMN:
2235 tag = CMDTAG_ALTER_TABLE;
2236 break;
2237 case OBJECT_CONVERSION:
2238 tag = CMDTAG_ALTER_CONVERSION;
2239 break;
2240 case OBJECT_DATABASE:
2241 tag = CMDTAG_ALTER_DATABASE;
2242 break;
2243 case OBJECT_DOMAIN:
2245 tag = CMDTAG_ALTER_DOMAIN;
2246 break;
2247 case OBJECT_EXTENSION:
2248 tag = CMDTAG_ALTER_EXTENSION;
2249 break;
2250 case OBJECT_FDW:
2251 tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
2252 break;
2254 tag = CMDTAG_ALTER_SERVER;
2255 break;
2257 tag = CMDTAG_ALTER_FOREIGN_TABLE;
2258 break;
2259 case OBJECT_FUNCTION:
2260 tag = CMDTAG_ALTER_FUNCTION;
2261 break;
2262 case OBJECT_INDEX:
2263 tag = CMDTAG_ALTER_INDEX;
2264 break;
2265 case OBJECT_LANGUAGE:
2266 tag = CMDTAG_ALTER_LANGUAGE;
2267 break;
2268 case OBJECT_LARGEOBJECT:
2269 tag = CMDTAG_ALTER_LARGE_OBJECT;
2270 break;
2271 case OBJECT_OPCLASS:
2272 tag = CMDTAG_ALTER_OPERATOR_CLASS;
2273 break;
2274 case OBJECT_OPERATOR:
2275 tag = CMDTAG_ALTER_OPERATOR;
2276 break;
2277 case OBJECT_OPFAMILY:
2278 tag = CMDTAG_ALTER_OPERATOR_FAMILY;
2279 break;
2280 case OBJECT_POLICY:
2281 tag = CMDTAG_ALTER_POLICY;
2282 break;
2283 case OBJECT_PROCEDURE:
2284 tag = CMDTAG_ALTER_PROCEDURE;
2285 break;
2286 case OBJECT_ROLE:
2287 tag = CMDTAG_ALTER_ROLE;
2288 break;
2289 case OBJECT_ROUTINE:
2290 tag = CMDTAG_ALTER_ROUTINE;
2291 break;
2292 case OBJECT_RULE:
2293 tag = CMDTAG_ALTER_RULE;
2294 break;
2295 case OBJECT_SCHEMA:
2296 tag = CMDTAG_ALTER_SCHEMA;
2297 break;
2298 case OBJECT_SEQUENCE:
2299 tag = CMDTAG_ALTER_SEQUENCE;
2300 break;
2301 case OBJECT_TABLE:
2303 tag = CMDTAG_ALTER_TABLE;
2304 break;
2305 case OBJECT_TABLESPACE:
2306 tag = CMDTAG_ALTER_TABLESPACE;
2307 break;
2308 case OBJECT_TRIGGER:
2309 tag = CMDTAG_ALTER_TRIGGER;
2310 break;
2312 tag = CMDTAG_ALTER_EVENT_TRIGGER;
2313 break;
2315 tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
2316 break;
2318 tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
2319 break;
2320 case OBJECT_TSPARSER:
2321 tag = CMDTAG_ALTER_TEXT_SEARCH_PARSER;
2322 break;
2323 case OBJECT_TSTEMPLATE:
2324 tag = CMDTAG_ALTER_TEXT_SEARCH_TEMPLATE;
2325 break;
2326 case OBJECT_TYPE:
2327 tag = CMDTAG_ALTER_TYPE;
2328 break;
2329 case OBJECT_VIEW:
2330 tag = CMDTAG_ALTER_VIEW;
2331 break;
2332 case OBJECT_MATVIEW:
2333 tag = CMDTAG_ALTER_MATERIALIZED_VIEW;
2334 break;
2335 case OBJECT_PUBLICATION:
2336 tag = CMDTAG_ALTER_PUBLICATION;
2337 break;
2339 tag = CMDTAG_ALTER_SUBSCRIPTION;
2340 break;
2342 tag = CMDTAG_ALTER_STATISTICS;
2343 break;
2344 default:
2345 tag = CMDTAG_UNKNOWN;
2346 break;
2347 }
2348
2349 return tag;
2350}
CommandTag
Definition: cmdtag.h:23
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:2282
@ OBJECT_FDW
Definition: parsenodes.h:2284
@ OBJECT_TSPARSER
Definition: parsenodes.h:2315
@ OBJECT_COLLATION
Definition: parsenodes.h:2275
@ OBJECT_OPCLASS
Definition: parsenodes.h:2292
@ OBJECT_AGGREGATE
Definition: parsenodes.h:2269
@ OBJECT_MATVIEW
Definition: parsenodes.h:2291
@ OBJECT_SCHEMA
Definition: parsenodes.h:2304
@ OBJECT_POLICY
Definition: parsenodes.h:2296
@ OBJECT_OPERATOR
Definition: parsenodes.h:2293
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:2286
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2313
@ OBJECT_OPFAMILY
Definition: parsenodes.h:2294
@ OBJECT_DOMAIN
Definition: parsenodes.h:2280
@ OBJECT_COLUMN
Definition: parsenodes.h:2274
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2310
@ OBJECT_ROLE
Definition: parsenodes.h:2301
@ OBJECT_ROUTINE
Definition: parsenodes.h:2302
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:2290
@ OBJECT_PROCEDURE
Definition: parsenodes.h:2297
@ OBJECT_EXTENSION
Definition: parsenodes.h:2283
@ OBJECT_INDEX
Definition: parsenodes.h:2288
@ OBJECT_DATABASE
Definition: parsenodes.h:2277
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2305
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2316
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2289
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:2285
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2314
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:2272
@ OBJECT_PUBLICATION
Definition: parsenodes.h:2298
@ OBJECT_RULE
Definition: parsenodes.h:2303
@ OBJECT_CONVERSION
Definition: parsenodes.h:2276
@ OBJECT_TABLE
Definition: parsenodes.h:2309
@ OBJECT_VIEW
Definition: parsenodes.h:2319
@ OBJECT_TYPE
Definition: parsenodes.h:2317
@ OBJECT_FUNCTION
Definition: parsenodes.h:2287
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2308
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:2281
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2306
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2307
@ OBJECT_CAST
Definition: parsenodes.h:2273
@ OBJECT_TRIGGER
Definition: parsenodes.h:2312

References OBJECT_AGGREGATE, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, and OBJECT_VIEW.

Referenced by CreateCommandTag().

◆ CheckRestrictedOperation()

static void CheckRestrictedOperation ( const char *  cmdname)
static

Definition at line 459 of file utility.c.

460{
463 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
464 /* translator: %s is name of a SQL command, eg PREPARE */
465 errmsg("cannot execute %s within security-restricted operation",
466 cmdname)));
467}
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
bool InSecurityRestrictedOperation(void)
Definition: miscinit.c:687

References ereport, errcode(), errmsg(), ERROR, and InSecurityRestrictedOperation().

Referenced by standard_ProcessUtility().

◆ ClassifyUtilityCommandAsReadOnly()

static int ClassifyUtilityCommandAsReadOnly ( Node parsetree)
static

Definition at line 128 of file utility.c.

129{
130 switch (nodeTag(parsetree))
131 {
132 case T_AlterCollationStmt:
133 case T_AlterDatabaseRefreshCollStmt:
134 case T_AlterDatabaseSetStmt:
135 case T_AlterDatabaseStmt:
136 case T_AlterDefaultPrivilegesStmt:
137 case T_AlterDomainStmt:
138 case T_AlterEnumStmt:
139 case T_AlterEventTrigStmt:
140 case T_AlterExtensionContentsStmt:
141 case T_AlterExtensionStmt:
142 case T_AlterFdwStmt:
143 case T_AlterForeignServerStmt:
144 case T_AlterFunctionStmt:
145 case T_AlterObjectDependsStmt:
146 case T_AlterObjectSchemaStmt:
147 case T_AlterOpFamilyStmt:
148 case T_AlterOperatorStmt:
149 case T_AlterOwnerStmt:
150 case T_AlterPolicyStmt:
151 case T_AlterPublicationStmt:
152 case T_AlterRoleSetStmt:
153 case T_AlterRoleStmt:
154 case T_AlterSeqStmt:
155 case T_AlterStatsStmt:
156 case T_AlterSubscriptionStmt:
157 case T_AlterTSConfigurationStmt:
158 case T_AlterTSDictionaryStmt:
159 case T_AlterTableMoveAllStmt:
160 case T_AlterTableSpaceOptionsStmt:
161 case T_AlterTableStmt:
162 case T_AlterTypeStmt:
163 case T_AlterUserMappingStmt:
164 case T_CommentStmt:
165 case T_CompositeTypeStmt:
166 case T_CreateAmStmt:
167 case T_CreateCastStmt:
168 case T_CreateConversionStmt:
169 case T_CreateDomainStmt:
170 case T_CreateEnumStmt:
171 case T_CreateEventTrigStmt:
172 case T_CreateExtensionStmt:
173 case T_CreateFdwStmt:
174 case T_CreateForeignServerStmt:
175 case T_CreateForeignTableStmt:
176 case T_CreateFunctionStmt:
177 case T_CreateOpClassStmt:
178 case T_CreateOpFamilyStmt:
179 case T_CreatePLangStmt:
180 case T_CreatePolicyStmt:
181 case T_CreatePublicationStmt:
182 case T_CreateRangeStmt:
183 case T_CreateRoleStmt:
184 case T_CreateSchemaStmt:
185 case T_CreateSeqStmt:
186 case T_CreateStatsStmt:
187 case T_CreateStmt:
188 case T_CreateSubscriptionStmt:
189 case T_CreateTableAsStmt:
190 case T_CreateTableSpaceStmt:
191 case T_CreateTransformStmt:
192 case T_CreateTrigStmt:
193 case T_CreateUserMappingStmt:
194 case T_CreatedbStmt:
195 case T_DefineStmt:
196 case T_DropOwnedStmt:
197 case T_DropRoleStmt:
198 case T_DropStmt:
199 case T_DropSubscriptionStmt:
200 case T_DropTableSpaceStmt:
201 case T_DropUserMappingStmt:
202 case T_DropdbStmt:
203 case T_GrantRoleStmt:
204 case T_GrantStmt:
205 case T_ImportForeignSchemaStmt:
206 case T_IndexStmt:
207 case T_ReassignOwnedStmt:
208 case T_RefreshMatViewStmt:
209 case T_RenameStmt:
210 case T_RuleStmt:
211 case T_SecLabelStmt:
212 case T_TruncateStmt:
213 case T_ViewStmt:
214 {
215 /* DDL is not read-only, and neither is TRUNCATE. */
217 }
218
219 case T_AlterSystemStmt:
220 {
221 /*
222 * Surprisingly, ALTER SYSTEM meets all our definitions of
223 * read-only: it changes nothing that affects the output of
224 * pg_dump, it doesn't write WAL or imperil the application of
225 * future WAL, and it doesn't depend on any state that needs
226 * to be synchronized with parallel workers.
227 *
228 * So, despite the fact that it writes to a file, it's read
229 * only!
230 */
232 }
233
234 case T_CallStmt:
235 case T_DoStmt:
236 {
237 /*
238 * Commands inside the DO block or the called procedure might
239 * not be read only, but they'll be checked separately when we
240 * try to execute them. Here we only need to worry about the
241 * DO or CALL command itself.
242 */
244 }
245
246 case T_CheckPointStmt:
247 {
248 /*
249 * You might think that this should not be permitted in
250 * recovery, but we interpret a CHECKPOINT command during
251 * recovery as a request for a restartpoint instead. We allow
252 * this since it can be a useful way of reducing switchover
253 * time when using various forms of replication.
254 */
256 }
257
258 case T_ClosePortalStmt:
259 case T_ConstraintsSetStmt:
260 case T_DeallocateStmt:
261 case T_DeclareCursorStmt:
262 case T_DiscardStmt:
263 case T_ExecuteStmt:
264 case T_FetchStmt:
265 case T_LoadStmt:
266 case T_PrepareStmt:
267 case T_UnlistenStmt:
268 case T_VariableSetStmt:
269 {
270 /*
271 * These modify only backend-local state, so they're OK to run
272 * in a read-only transaction or on a standby. However, they
273 * are disallowed in parallel mode, because they either rely
274 * upon or modify backend-local state that might not be
275 * synchronized among cooperating backends.
276 */
278 }
279
280 case T_ClusterStmt:
281 case T_ReindexStmt:
282 case T_VacuumStmt:
283 {
284 /*
285 * These commands write WAL, so they're not strictly
286 * read-only, and running them in parallel workers isn't
287 * supported.
288 *
289 * However, they don't change the database state in a way that
290 * would affect pg_dump output, so it's fine to run them in a
291 * read-only transaction. (CLUSTER might change the order of
292 * rows on disk, which could affect the ordering of pg_dump
293 * output, but that's not semantically significant.)
294 */
296 }
297
298 case T_CopyStmt:
299 {
300 CopyStmt *stmt = (CopyStmt *) parsetree;
301
302 /*
303 * You might think that COPY FROM is not at all read only, but
304 * it's OK to copy into a temporary table, because that
305 * wouldn't change the output of pg_dump. If the target table
306 * turns out to be non-temporary, DoCopy itself will call
307 * PreventCommandIfReadOnly.
308 */
309 if (stmt->is_from)
311 else
313 }
314
315 case T_ExplainStmt:
316 case T_VariableShowStmt:
317 {
318 /*
319 * These commands don't modify any data and are safe to run in
320 * a parallel worker.
321 */
323 }
324
325 case T_ListenStmt:
326 case T_NotifyStmt:
327 {
328 /*
329 * NOTIFY requires an XID assignment, so it can't be permitted
330 * on a standby. Perhaps LISTEN could, since without NOTIFY it
331 * would be OK to just do nothing, at least until promotion,
332 * but we currently prohibit it lest the user get the wrong
333 * idea.
334 *
335 * (We do allow T_UnlistenStmt on a standby, though, because
336 * it's a no-op.)
337 */
339 }
340
341 case T_LockStmt:
342 {
343 LockStmt *stmt = (LockStmt *) parsetree;
344
345 /*
346 * Only weaker locker modes are allowed during recovery. The
347 * restrictions here must match those in
348 * LockAcquireExtended().
349 */
350 if (stmt->mode > RowExclusiveLock)
352 else
354 }
355
356 case T_TransactionStmt:
357 {
358 TransactionStmt *stmt = (TransactionStmt *) parsetree;
359
360 /*
361 * PREPARE, COMMIT PREPARED, and ROLLBACK PREPARED all write
362 * WAL, so they're not read-only in the strict sense; but the
363 * first and third do not change pg_dump output, so they're OK
364 * in a read-only transactions.
365 *
366 * We also consider COMMIT PREPARED to be OK in a read-only
367 * transaction environment, by way of exception.
368 */
369 switch (stmt->kind)
370 {
371 case TRANS_STMT_BEGIN:
372 case TRANS_STMT_START:
379
384 }
385 elog(ERROR, "unrecognized TransactionStmtKind: %d",
386 (int) stmt->kind);
387 return 0; /* silence stupider compilers */
388 }
389
390 default:
391 elog(ERROR, "unrecognized node type: %d",
392 (int) nodeTag(parsetree));
393 return 0; /* silence stupider compilers */
394 }
395}
#define elog(elevel,...)
Definition: elog.h:225
#define stmt
Definition: indent_codes.h:59
#define RowExclusiveLock
Definition: lockdefs.h:38
#define nodeTag(nodeptr)
Definition: nodes.h:133
@ TRANS_STMT_ROLLBACK_TO
Definition: parsenodes.h:3689
@ TRANS_STMT_START
Definition: parsenodes.h:3684
@ TRANS_STMT_SAVEPOINT
Definition: parsenodes.h:3687
@ TRANS_STMT_BEGIN
Definition: parsenodes.h:3683
@ TRANS_STMT_ROLLBACK
Definition: parsenodes.h:3686
@ TRANS_STMT_COMMIT_PREPARED
Definition: parsenodes.h:3691
@ TRANS_STMT_COMMIT
Definition: parsenodes.h:3685
@ TRANS_STMT_ROLLBACK_PREPARED
Definition: parsenodes.h:3692
@ TRANS_STMT_PREPARE
Definition: parsenodes.h:3690
@ TRANS_STMT_RELEASE
Definition: parsenodes.h:3688
#define COMMAND_OK_IN_RECOVERY
Definition: utility.h:58
#define COMMAND_IS_STRICTLY_READ_ONLY
Definition: utility.h:65
#define COMMAND_IS_NOT_READ_ONLY
Definition: utility.h:68
#define COMMAND_OK_IN_READ_ONLY_TXN
Definition: utility.h:56

References COMMAND_IS_NOT_READ_ONLY, COMMAND_IS_STRICTLY_READ_ONLY, COMMAND_OK_IN_READ_ONLY_TXN, COMMAND_OK_IN_RECOVERY, elog, ERROR, nodeTag, RowExclusiveLock, stmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, and TRANS_STMT_START.

Referenced by standard_ProcessUtility().

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

Definition at line 94 of file utility.c.

95{
96 Assert(IsA(pstmt, PlannedStmt));
97 switch (pstmt->commandType)
98 {
99 case CMD_SELECT:
100 if (pstmt->rowMarks != NIL)
101 return false; /* SELECT FOR [KEY] UPDATE/SHARE */
102 else if (pstmt->hasModifyingCTE)
103 return false; /* data-modifying CTE */
104 else
105 return true;
106 case CMD_UPDATE:
107 case CMD_INSERT:
108 case CMD_DELETE:
109 case CMD_MERGE:
110 return false;
111 case CMD_UTILITY:
112 /* For now, treat all utility commands as read/write */
113 return false;
114 default:
115 elog(WARNING, "unrecognized commandType: %d",
116 (int) pstmt->commandType);
117 break;
118 }
119 return false;
120}
#define Assert(condition)
Definition: c.h:812
#define WARNING
Definition: elog.h:36
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
@ CMD_MERGE
Definition: nodes.h:269
@ CMD_UTILITY
Definition: nodes.h:270
@ CMD_INSERT
Definition: nodes.h:267
@ CMD_DELETE
Definition: nodes.h:268
@ CMD_UPDATE
Definition: nodes.h:266
@ CMD_SELECT
Definition: nodes.h:265
#define NIL
Definition: pg_list.h:68
bool hasModifyingCTE
Definition: plannodes.h:58
List * rowMarks
Definition: plannodes.h:87
CmdType commandType
Definition: plannodes.h:52

References Assert, CMD_DELETE, CMD_INSERT, CMD_MERGE, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, PlannedStmt::commandType, elog, PlannedStmt::hasModifyingCTE, IsA, NIL, PlannedStmt::rowMarks, and WARNING.

Referenced by _SPI_execute_plan(), init_execution_state(), and SPI_cursor_open_internal().

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

Definition at line 2362 of file utility.c.

2363{
2364 CommandTag tag;
2365
2366 switch (nodeTag(parsetree))
2367 {
2368 /* recurse if we're given a RawStmt */
2369 case T_RawStmt:
2370 tag = CreateCommandTag(((RawStmt *) parsetree)->stmt);
2371 break;
2372
2373 /* raw plannable queries */
2374 case T_InsertStmt:
2375 tag = CMDTAG_INSERT;
2376 break;
2377
2378 case T_DeleteStmt:
2379 tag = CMDTAG_DELETE;
2380 break;
2381
2382 case T_UpdateStmt:
2383 tag = CMDTAG_UPDATE;
2384 break;
2385
2386 case T_MergeStmt:
2387 tag = CMDTAG_MERGE;
2388 break;
2389
2390 case T_SelectStmt:
2391 tag = CMDTAG_SELECT;
2392 break;
2393
2394 case T_PLAssignStmt:
2395 tag = CMDTAG_SELECT;
2396 break;
2397
2398 /* utility statements --- same whether raw or cooked */
2399 case T_TransactionStmt:
2400 {
2401 TransactionStmt *stmt = (TransactionStmt *) parsetree;
2402
2403 switch (stmt->kind)
2404 {
2405 case TRANS_STMT_BEGIN:
2406 tag = CMDTAG_BEGIN;
2407 break;
2408
2409 case TRANS_STMT_START:
2410 tag = CMDTAG_START_TRANSACTION;
2411 break;
2412
2413 case TRANS_STMT_COMMIT:
2414 tag = CMDTAG_COMMIT;
2415 break;
2416
2419 tag = CMDTAG_ROLLBACK;
2420 break;
2421
2423 tag = CMDTAG_SAVEPOINT;
2424 break;
2425
2426 case TRANS_STMT_RELEASE:
2427 tag = CMDTAG_RELEASE;
2428 break;
2429
2430 case TRANS_STMT_PREPARE:
2431 tag = CMDTAG_PREPARE_TRANSACTION;
2432 break;
2433
2435 tag = CMDTAG_COMMIT_PREPARED;
2436 break;
2437
2439 tag = CMDTAG_ROLLBACK_PREPARED;
2440 break;
2441
2442 default:
2443 tag = CMDTAG_UNKNOWN;
2444 break;
2445 }
2446 }
2447 break;
2448
2449 case T_DeclareCursorStmt:
2450 tag = CMDTAG_DECLARE_CURSOR;
2451 break;
2452
2453 case T_ClosePortalStmt:
2454 {
2455 ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
2456
2457 if (stmt->portalname == NULL)
2458 tag = CMDTAG_CLOSE_CURSOR_ALL;
2459 else
2460 tag = CMDTAG_CLOSE_CURSOR;
2461 }
2462 break;
2463
2464 case T_FetchStmt:
2465 {
2466 FetchStmt *stmt = (FetchStmt *) parsetree;
2467
2468 tag = (stmt->ismove) ? CMDTAG_MOVE : CMDTAG_FETCH;
2469 }
2470 break;
2471
2472 case T_CreateDomainStmt:
2473 tag = CMDTAG_CREATE_DOMAIN;
2474 break;
2475
2476 case T_CreateSchemaStmt:
2477 tag = CMDTAG_CREATE_SCHEMA;
2478 break;
2479
2480 case T_CreateStmt:
2481 tag = CMDTAG_CREATE_TABLE;
2482 break;
2483
2484 case T_CreateTableSpaceStmt:
2485 tag = CMDTAG_CREATE_TABLESPACE;
2486 break;
2487
2488 case T_DropTableSpaceStmt:
2489 tag = CMDTAG_DROP_TABLESPACE;
2490 break;
2491
2492 case T_AlterTableSpaceOptionsStmt:
2493 tag = CMDTAG_ALTER_TABLESPACE;
2494 break;
2495
2496 case T_CreateExtensionStmt:
2497 tag = CMDTAG_CREATE_EXTENSION;
2498 break;
2499
2500 case T_AlterExtensionStmt:
2501 tag = CMDTAG_ALTER_EXTENSION;
2502 break;
2503
2504 case T_AlterExtensionContentsStmt:
2505 tag = CMDTAG_ALTER_EXTENSION;
2506 break;
2507
2508 case T_CreateFdwStmt:
2509 tag = CMDTAG_CREATE_FOREIGN_DATA_WRAPPER;
2510 break;
2511
2512 case T_AlterFdwStmt:
2513 tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
2514 break;
2515
2516 case T_CreateForeignServerStmt:
2517 tag = CMDTAG_CREATE_SERVER;
2518 break;
2519
2520 case T_AlterForeignServerStmt:
2521 tag = CMDTAG_ALTER_SERVER;
2522 break;
2523
2524 case T_CreateUserMappingStmt:
2525 tag = CMDTAG_CREATE_USER_MAPPING;
2526 break;
2527
2528 case T_AlterUserMappingStmt:
2529 tag = CMDTAG_ALTER_USER_MAPPING;
2530 break;
2531
2532 case T_DropUserMappingStmt:
2533 tag = CMDTAG_DROP_USER_MAPPING;
2534 break;
2535
2536 case T_CreateForeignTableStmt:
2537 tag = CMDTAG_CREATE_FOREIGN_TABLE;
2538 break;
2539
2540 case T_ImportForeignSchemaStmt:
2541 tag = CMDTAG_IMPORT_FOREIGN_SCHEMA;
2542 break;
2543
2544 case T_DropStmt:
2545 switch (((DropStmt *) parsetree)->removeType)
2546 {
2547 case OBJECT_TABLE:
2548 tag = CMDTAG_DROP_TABLE;
2549 break;
2550 case OBJECT_SEQUENCE:
2551 tag = CMDTAG_DROP_SEQUENCE;
2552 break;
2553 case OBJECT_VIEW:
2554 tag = CMDTAG_DROP_VIEW;
2555 break;
2556 case OBJECT_MATVIEW:
2557 tag = CMDTAG_DROP_MATERIALIZED_VIEW;
2558 break;
2559 case OBJECT_INDEX:
2560 tag = CMDTAG_DROP_INDEX;
2561 break;
2562 case OBJECT_TYPE:
2563 tag = CMDTAG_DROP_TYPE;
2564 break;
2565 case OBJECT_DOMAIN:
2566 tag = CMDTAG_DROP_DOMAIN;
2567 break;
2568 case OBJECT_COLLATION:
2569 tag = CMDTAG_DROP_COLLATION;
2570 break;
2571 case OBJECT_CONVERSION:
2572 tag = CMDTAG_DROP_CONVERSION;
2573 break;
2574 case OBJECT_SCHEMA:
2575 tag = CMDTAG_DROP_SCHEMA;
2576 break;
2577 case OBJECT_TSPARSER:
2578 tag = CMDTAG_DROP_TEXT_SEARCH_PARSER;
2579 break;
2581 tag = CMDTAG_DROP_TEXT_SEARCH_DICTIONARY;
2582 break;
2583 case OBJECT_TSTEMPLATE:
2584 tag = CMDTAG_DROP_TEXT_SEARCH_TEMPLATE;
2585 break;
2587 tag = CMDTAG_DROP_TEXT_SEARCH_CONFIGURATION;
2588 break;
2590 tag = CMDTAG_DROP_FOREIGN_TABLE;
2591 break;
2592 case OBJECT_EXTENSION:
2593 tag = CMDTAG_DROP_EXTENSION;
2594 break;
2595 case OBJECT_FUNCTION:
2596 tag = CMDTAG_DROP_FUNCTION;
2597 break;
2598 case OBJECT_PROCEDURE:
2599 tag = CMDTAG_DROP_PROCEDURE;
2600 break;
2601 case OBJECT_ROUTINE:
2602 tag = CMDTAG_DROP_ROUTINE;
2603 break;
2604 case OBJECT_AGGREGATE:
2605 tag = CMDTAG_DROP_AGGREGATE;
2606 break;
2607 case OBJECT_OPERATOR:
2608 tag = CMDTAG_DROP_OPERATOR;
2609 break;
2610 case OBJECT_LANGUAGE:
2611 tag = CMDTAG_DROP_LANGUAGE;
2612 break;
2613 case OBJECT_CAST:
2614 tag = CMDTAG_DROP_CAST;
2615 break;
2616 case OBJECT_TRIGGER:
2617 tag = CMDTAG_DROP_TRIGGER;
2618 break;
2620 tag = CMDTAG_DROP_EVENT_TRIGGER;
2621 break;
2622 case OBJECT_RULE:
2623 tag = CMDTAG_DROP_RULE;
2624 break;
2625 case OBJECT_FDW:
2626 tag = CMDTAG_DROP_FOREIGN_DATA_WRAPPER;
2627 break;
2629 tag = CMDTAG_DROP_SERVER;
2630 break;
2631 case OBJECT_OPCLASS:
2632 tag = CMDTAG_DROP_OPERATOR_CLASS;
2633 break;
2634 case OBJECT_OPFAMILY:
2635 tag = CMDTAG_DROP_OPERATOR_FAMILY;
2636 break;
2637 case OBJECT_POLICY:
2638 tag = CMDTAG_DROP_POLICY;
2639 break;
2640 case OBJECT_TRANSFORM:
2641 tag = CMDTAG_DROP_TRANSFORM;
2642 break;
2644 tag = CMDTAG_DROP_ACCESS_METHOD;
2645 break;
2646 case OBJECT_PUBLICATION:
2647 tag = CMDTAG_DROP_PUBLICATION;
2648 break;
2650 tag = CMDTAG_DROP_STATISTICS;
2651 break;
2652 default:
2653 tag = CMDTAG_UNKNOWN;
2654 }
2655 break;
2656
2657 case T_TruncateStmt:
2658 tag = CMDTAG_TRUNCATE_TABLE;
2659 break;
2660
2661 case T_CommentStmt:
2662 tag = CMDTAG_COMMENT;
2663 break;
2664
2665 case T_SecLabelStmt:
2666 tag = CMDTAG_SECURITY_LABEL;
2667 break;
2668
2669 case T_CopyStmt:
2670 tag = CMDTAG_COPY;
2671 break;
2672
2673 case T_RenameStmt:
2674
2675 /*
2676 * When the column is renamed, the command tag is created from its
2677 * relation type
2678 */
2679 tag = AlterObjectTypeCommandTag(((RenameStmt *) parsetree)->renameType == OBJECT_COLUMN ?
2680 ((RenameStmt *) parsetree)->relationType :
2681 ((RenameStmt *) parsetree)->renameType);
2682 break;
2683
2684 case T_AlterObjectDependsStmt:
2685 tag = AlterObjectTypeCommandTag(((AlterObjectDependsStmt *) parsetree)->objectType);
2686 break;
2687
2688 case T_AlterObjectSchemaStmt:
2689 tag = AlterObjectTypeCommandTag(((AlterObjectSchemaStmt *) parsetree)->objectType);
2690 break;
2691
2692 case T_AlterOwnerStmt:
2693 tag = AlterObjectTypeCommandTag(((AlterOwnerStmt *) parsetree)->objectType);
2694 break;
2695
2696 case T_AlterTableMoveAllStmt:
2697 tag = AlterObjectTypeCommandTag(((AlterTableMoveAllStmt *) parsetree)->objtype);
2698 break;
2699
2700 case T_AlterTableStmt:
2701 tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->objtype);
2702 break;
2703
2704 case T_AlterDomainStmt:
2705 tag = CMDTAG_ALTER_DOMAIN;
2706 break;
2707
2708 case T_AlterFunctionStmt:
2709 switch (((AlterFunctionStmt *) parsetree)->objtype)
2710 {
2711 case OBJECT_FUNCTION:
2712 tag = CMDTAG_ALTER_FUNCTION;
2713 break;
2714 case OBJECT_PROCEDURE:
2715 tag = CMDTAG_ALTER_PROCEDURE;
2716 break;
2717 case OBJECT_ROUTINE:
2718 tag = CMDTAG_ALTER_ROUTINE;
2719 break;
2720 default:
2721 tag = CMDTAG_UNKNOWN;
2722 }
2723 break;
2724
2725 case T_GrantStmt:
2726 {
2727 GrantStmt *stmt = (GrantStmt *) parsetree;
2728
2729 tag = (stmt->is_grant) ? CMDTAG_GRANT : CMDTAG_REVOKE;
2730 }
2731 break;
2732
2733 case T_GrantRoleStmt:
2734 {
2735 GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;
2736
2737 tag = (stmt->is_grant) ? CMDTAG_GRANT_ROLE : CMDTAG_REVOKE_ROLE;
2738 }
2739 break;
2740
2741 case T_AlterDefaultPrivilegesStmt:
2742 tag = CMDTAG_ALTER_DEFAULT_PRIVILEGES;
2743 break;
2744
2745 case T_DefineStmt:
2746 switch (((DefineStmt *) parsetree)->kind)
2747 {
2748 case OBJECT_AGGREGATE:
2749 tag = CMDTAG_CREATE_AGGREGATE;
2750 break;
2751 case OBJECT_OPERATOR:
2752 tag = CMDTAG_CREATE_OPERATOR;
2753 break;
2754 case OBJECT_TYPE:
2755 tag = CMDTAG_CREATE_TYPE;
2756 break;
2757 case OBJECT_TSPARSER:
2758 tag = CMDTAG_CREATE_TEXT_SEARCH_PARSER;
2759 break;
2761 tag = CMDTAG_CREATE_TEXT_SEARCH_DICTIONARY;
2762 break;
2763 case OBJECT_TSTEMPLATE:
2764 tag = CMDTAG_CREATE_TEXT_SEARCH_TEMPLATE;
2765 break;
2767 tag = CMDTAG_CREATE_TEXT_SEARCH_CONFIGURATION;
2768 break;
2769 case OBJECT_COLLATION:
2770 tag = CMDTAG_CREATE_COLLATION;
2771 break;
2773 tag = CMDTAG_CREATE_ACCESS_METHOD;
2774 break;
2775 default:
2776 tag = CMDTAG_UNKNOWN;
2777 }
2778 break;
2779
2780 case T_CompositeTypeStmt:
2781 tag = CMDTAG_CREATE_TYPE;
2782 break;
2783
2784 case T_CreateEnumStmt:
2785 tag = CMDTAG_CREATE_TYPE;
2786 break;
2787
2788 case T_CreateRangeStmt:
2789 tag = CMDTAG_CREATE_TYPE;
2790 break;
2791
2792 case T_AlterEnumStmt:
2793 tag = CMDTAG_ALTER_TYPE;
2794 break;
2795
2796 case T_ViewStmt:
2797 tag = CMDTAG_CREATE_VIEW;
2798 break;
2799
2800 case T_CreateFunctionStmt:
2801 if (((CreateFunctionStmt *) parsetree)->is_procedure)
2802 tag = CMDTAG_CREATE_PROCEDURE;
2803 else
2804 tag = CMDTAG_CREATE_FUNCTION;
2805 break;
2806
2807 case T_IndexStmt:
2808 tag = CMDTAG_CREATE_INDEX;
2809 break;
2810
2811 case T_RuleStmt:
2812 tag = CMDTAG_CREATE_RULE;
2813 break;
2814
2815 case T_CreateSeqStmt:
2816 tag = CMDTAG_CREATE_SEQUENCE;
2817 break;
2818
2819 case T_AlterSeqStmt:
2820 tag = CMDTAG_ALTER_SEQUENCE;
2821 break;
2822
2823 case T_DoStmt:
2824 tag = CMDTAG_DO;
2825 break;
2826
2827 case T_CreatedbStmt:
2828 tag = CMDTAG_CREATE_DATABASE;
2829 break;
2830
2831 case T_AlterDatabaseStmt:
2832 case T_AlterDatabaseRefreshCollStmt:
2833 case T_AlterDatabaseSetStmt:
2834 tag = CMDTAG_ALTER_DATABASE;
2835 break;
2836
2837 case T_DropdbStmt:
2838 tag = CMDTAG_DROP_DATABASE;
2839 break;
2840
2841 case T_NotifyStmt:
2842 tag = CMDTAG_NOTIFY;
2843 break;
2844
2845 case T_ListenStmt:
2846 tag = CMDTAG_LISTEN;
2847 break;
2848
2849 case T_UnlistenStmt:
2850 tag = CMDTAG_UNLISTEN;
2851 break;
2852
2853 case T_LoadStmt:
2854 tag = CMDTAG_LOAD;
2855 break;
2856
2857 case T_CallStmt:
2858 tag = CMDTAG_CALL;
2859 break;
2860
2861 case T_ClusterStmt:
2862 tag = CMDTAG_CLUSTER;
2863 break;
2864
2865 case T_VacuumStmt:
2866 if (((VacuumStmt *) parsetree)->is_vacuumcmd)
2867 tag = CMDTAG_VACUUM;
2868 else
2869 tag = CMDTAG_ANALYZE;
2870 break;
2871
2872 case T_ExplainStmt:
2873 tag = CMDTAG_EXPLAIN;
2874 break;
2875
2876 case T_CreateTableAsStmt:
2877 switch (((CreateTableAsStmt *) parsetree)->objtype)
2878 {
2879 case OBJECT_TABLE:
2880 if (((CreateTableAsStmt *) parsetree)->is_select_into)
2881 tag = CMDTAG_SELECT_INTO;
2882 else
2883 tag = CMDTAG_CREATE_TABLE_AS;
2884 break;
2885 case OBJECT_MATVIEW:
2886 tag = CMDTAG_CREATE_MATERIALIZED_VIEW;
2887 break;
2888 default:
2889 tag = CMDTAG_UNKNOWN;
2890 }
2891 break;
2892
2893 case T_RefreshMatViewStmt:
2894 tag = CMDTAG_REFRESH_MATERIALIZED_VIEW;
2895 break;
2896
2897 case T_AlterSystemStmt:
2898 tag = CMDTAG_ALTER_SYSTEM;
2899 break;
2900
2901 case T_VariableSetStmt:
2902 switch (((VariableSetStmt *) parsetree)->kind)
2903 {
2904 case VAR_SET_VALUE:
2905 case VAR_SET_CURRENT:
2906 case VAR_SET_DEFAULT:
2907 case VAR_SET_MULTI:
2908 tag = CMDTAG_SET;
2909 break;
2910 case VAR_RESET:
2911 case VAR_RESET_ALL:
2912 tag = CMDTAG_RESET;
2913 break;
2914 default:
2915 tag = CMDTAG_UNKNOWN;
2916 }
2917 break;
2918
2919 case T_VariableShowStmt:
2920 tag = CMDTAG_SHOW;
2921 break;
2922
2923 case T_DiscardStmt:
2924 switch (((DiscardStmt *) parsetree)->target)
2925 {
2926 case DISCARD_ALL:
2927 tag = CMDTAG_DISCARD_ALL;
2928 break;
2929 case DISCARD_PLANS:
2930 tag = CMDTAG_DISCARD_PLANS;
2931 break;
2932 case DISCARD_TEMP:
2933 tag = CMDTAG_DISCARD_TEMP;
2934 break;
2935 case DISCARD_SEQUENCES:
2936 tag = CMDTAG_DISCARD_SEQUENCES;
2937 break;
2938 default:
2939 tag = CMDTAG_UNKNOWN;
2940 }
2941 break;
2942
2943 case T_CreateTransformStmt:
2944 tag = CMDTAG_CREATE_TRANSFORM;
2945 break;
2946
2947 case T_CreateTrigStmt:
2948 tag = CMDTAG_CREATE_TRIGGER;
2949 break;
2950
2951 case T_CreateEventTrigStmt:
2952 tag = CMDTAG_CREATE_EVENT_TRIGGER;
2953 break;
2954
2955 case T_AlterEventTrigStmt:
2956 tag = CMDTAG_ALTER_EVENT_TRIGGER;
2957 break;
2958
2959 case T_CreatePLangStmt:
2960 tag = CMDTAG_CREATE_LANGUAGE;
2961 break;
2962
2963 case T_CreateRoleStmt:
2964 tag = CMDTAG_CREATE_ROLE;
2965 break;
2966
2967 case T_AlterRoleStmt:
2968 tag = CMDTAG_ALTER_ROLE;
2969 break;
2970
2971 case T_AlterRoleSetStmt:
2972 tag = CMDTAG_ALTER_ROLE;
2973 break;
2974
2975 case T_DropRoleStmt:
2976 tag = CMDTAG_DROP_ROLE;
2977 break;
2978
2979 case T_DropOwnedStmt:
2980 tag = CMDTAG_DROP_OWNED;
2981 break;
2982
2983 case T_ReassignOwnedStmt:
2984 tag = CMDTAG_REASSIGN_OWNED;
2985 break;
2986
2987 case T_LockStmt:
2988 tag = CMDTAG_LOCK_TABLE;
2989 break;
2990
2991 case T_ConstraintsSetStmt:
2992 tag = CMDTAG_SET_CONSTRAINTS;
2993 break;
2994
2995 case T_CheckPointStmt:
2996 tag = CMDTAG_CHECKPOINT;
2997 break;
2998
2999 case T_ReindexStmt:
3000 tag = CMDTAG_REINDEX;
3001 break;
3002
3003 case T_CreateConversionStmt:
3004 tag = CMDTAG_CREATE_CONVERSION;
3005 break;
3006
3007 case T_CreateCastStmt:
3008 tag = CMDTAG_CREATE_CAST;
3009 break;
3010
3011 case T_CreateOpClassStmt:
3012 tag = CMDTAG_CREATE_OPERATOR_CLASS;
3013 break;
3014
3015 case T_CreateOpFamilyStmt:
3016 tag = CMDTAG_CREATE_OPERATOR_FAMILY;
3017 break;
3018
3019 case T_AlterOpFamilyStmt:
3020 tag = CMDTAG_ALTER_OPERATOR_FAMILY;
3021 break;
3022
3023 case T_AlterOperatorStmt:
3024 tag = CMDTAG_ALTER_OPERATOR;
3025 break;
3026
3027 case T_AlterTypeStmt:
3028 tag = CMDTAG_ALTER_TYPE;
3029 break;
3030
3031 case T_AlterTSDictionaryStmt:
3032 tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
3033 break;
3034
3035 case T_AlterTSConfigurationStmt:
3036 tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
3037 break;
3038
3039 case T_CreatePolicyStmt:
3040 tag = CMDTAG_CREATE_POLICY;
3041 break;
3042
3043 case T_AlterPolicyStmt:
3044 tag = CMDTAG_ALTER_POLICY;
3045 break;
3046
3047 case T_CreateAmStmt:
3048 tag = CMDTAG_CREATE_ACCESS_METHOD;
3049 break;
3050
3051 case T_CreatePublicationStmt:
3052 tag = CMDTAG_CREATE_PUBLICATION;
3053 break;
3054
3055 case T_AlterPublicationStmt:
3056 tag = CMDTAG_ALTER_PUBLICATION;
3057 break;
3058
3059 case T_CreateSubscriptionStmt:
3060 tag = CMDTAG_CREATE_SUBSCRIPTION;
3061 break;
3062
3063 case T_AlterSubscriptionStmt:
3064 tag = CMDTAG_ALTER_SUBSCRIPTION;
3065 break;
3066
3067 case T_DropSubscriptionStmt:
3068 tag = CMDTAG_DROP_SUBSCRIPTION;
3069 break;
3070
3071 case T_AlterCollationStmt:
3072 tag = CMDTAG_ALTER_COLLATION;
3073 break;
3074
3075 case T_PrepareStmt:
3076 tag = CMDTAG_PREPARE;
3077 break;
3078
3079 case T_ExecuteStmt:
3080 tag = CMDTAG_EXECUTE;
3081 break;
3082
3083 case T_CreateStatsStmt:
3084 tag = CMDTAG_CREATE_STATISTICS;
3085 break;
3086
3087 case T_AlterStatsStmt:
3088 tag = CMDTAG_ALTER_STATISTICS;
3089 break;
3090
3091 case T_DeallocateStmt:
3092 {
3093 DeallocateStmt *stmt = (DeallocateStmt *) parsetree;
3094
3095 if (stmt->name == NULL)
3096 tag = CMDTAG_DEALLOCATE_ALL;
3097 else
3098 tag = CMDTAG_DEALLOCATE;
3099 }
3100 break;
3101
3102 /* already-planned queries */
3103 case T_PlannedStmt:
3104 {
3105 PlannedStmt *stmt = (PlannedStmt *) parsetree;
3106
3107 switch (stmt->commandType)
3108 {
3109 case CMD_SELECT:
3110
3111 /*
3112 * We take a little extra care here so that the result
3113 * will be useful for complaints about read-only
3114 * statements
3115 */
3116 if (stmt->rowMarks != NIL)
3117 {
3118 /* not 100% but probably close enough */
3119 switch (((PlanRowMark *) linitial(stmt->rowMarks))->strength)
3120 {
3121 case LCS_FORKEYSHARE:
3122 tag = CMDTAG_SELECT_FOR_KEY_SHARE;
3123 break;
3124 case LCS_FORSHARE:
3125 tag = CMDTAG_SELECT_FOR_SHARE;
3126 break;
3127 case LCS_FORNOKEYUPDATE:
3128 tag = CMDTAG_SELECT_FOR_NO_KEY_UPDATE;
3129 break;
3130 case LCS_FORUPDATE:
3131 tag = CMDTAG_SELECT_FOR_UPDATE;
3132 break;
3133 default:
3134 tag = CMDTAG_SELECT;
3135 break;
3136 }
3137 }
3138 else
3139 tag = CMDTAG_SELECT;
3140 break;
3141 case CMD_UPDATE:
3142 tag = CMDTAG_UPDATE;
3143 break;
3144 case CMD_INSERT:
3145 tag = CMDTAG_INSERT;
3146 break;
3147 case CMD_DELETE:
3148 tag = CMDTAG_DELETE;
3149 break;
3150 case CMD_MERGE:
3151 tag = CMDTAG_MERGE;
3152 break;
3153 case CMD_UTILITY:
3154 tag = CreateCommandTag(stmt->utilityStmt);
3155 break;
3156 default:
3157 elog(WARNING, "unrecognized commandType: %d",
3158 (int) stmt->commandType);
3159 tag = CMDTAG_UNKNOWN;
3160 break;
3161 }
3162 }
3163 break;
3164
3165 /* parsed-and-rewritten-but-not-planned queries */
3166 case T_Query:
3167 {
3168 Query *stmt = (Query *) parsetree;
3169
3170 switch (stmt->commandType)
3171 {
3172 case CMD_SELECT:
3173
3174 /*
3175 * We take a little extra care here so that the result
3176 * will be useful for complaints about read-only
3177 * statements
3178 */
3179 if (stmt->rowMarks != NIL)
3180 {
3181 /* not 100% but probably close enough */
3182 switch (((RowMarkClause *) linitial(stmt->rowMarks))->strength)
3183 {
3184 case LCS_FORKEYSHARE:
3185 tag = CMDTAG_SELECT_FOR_KEY_SHARE;
3186 break;
3187 case LCS_FORSHARE:
3188 tag = CMDTAG_SELECT_FOR_SHARE;
3189 break;
3190 case LCS_FORNOKEYUPDATE:
3191 tag = CMDTAG_SELECT_FOR_NO_KEY_UPDATE;
3192 break;
3193 case LCS_FORUPDATE:
3194 tag = CMDTAG_SELECT_FOR_UPDATE;
3195 break;
3196 default:
3197 tag = CMDTAG_UNKNOWN;
3198 break;
3199 }
3200 }
3201 else
3202 tag = CMDTAG_SELECT;
3203 break;
3204 case CMD_UPDATE:
3205 tag = CMDTAG_UPDATE;
3206 break;
3207 case CMD_INSERT:
3208 tag = CMDTAG_INSERT;
3209 break;
3210 case CMD_DELETE:
3211 tag = CMDTAG_DELETE;
3212 break;
3213 case CMD_MERGE:
3214 tag = CMDTAG_MERGE;
3215 break;
3216 case CMD_UTILITY:
3217 tag = CreateCommandTag(stmt->utilityStmt);
3218 break;
3219 default:
3220 elog(WARNING, "unrecognized commandType: %d",
3221 (int) stmt->commandType);
3222 tag = CMDTAG_UNKNOWN;
3223 break;
3224 }
3225 }
3226 break;
3227
3228 default:
3229 elog(WARNING, "unrecognized node type: %d",
3230 (int) nodeTag(parsetree));
3231 tag = CMDTAG_UNKNOWN;
3232 break;
3233 }
3234
3235 return tag;
3236}
@ LCS_FORUPDATE
Definition: lockoptions.h:27
@ LCS_FORSHARE
Definition: lockoptions.h:25
@ LCS_FORKEYSHARE
Definition: lockoptions.h:24
@ LCS_FORNOKEYUPDATE
Definition: lockoptions.h:26
@ VAR_SET_DEFAULT
Definition: parsenodes.h:2620
@ VAR_RESET
Definition: parsenodes.h:2623
@ VAR_SET_MULTI
Definition: parsenodes.h:2622
@ VAR_SET_VALUE
Definition: parsenodes.h:2619
@ VAR_SET_CURRENT
Definition: parsenodes.h:2621
@ VAR_RESET_ALL
Definition: parsenodes.h:2624
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:2268
@ OBJECT_TRANSFORM
Definition: parsenodes.h:2311
@ DISCARD_ALL
Definition: parsenodes.h:3954
@ DISCARD_PLANS
Definition: parsenodes.h:3955
@ DISCARD_SEQUENCES
Definition: parsenodes.h:3956
@ DISCARD_TEMP
Definition: parsenodes.h:3957
#define linitial(l)
Definition: pg_list.h:178
CommandTag CreateCommandTag(Node *parsetree)
Definition: utility.c:2362
static CommandTag AlterObjectTypeCommandTag(ObjectType objtype)
Definition: utility.c:2216

References AlterObjectTypeCommandTag(), CMD_DELETE, CMD_INSERT, CMD_MERGE, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, CreateCommandTag(), DISCARD_ALL, DISCARD_PLANS, DISCARD_SEQUENCES, DISCARD_TEMP, elog, LCS_FORKEYSHARE, LCS_FORNOKEYUPDATE, LCS_FORSHARE, LCS_FORUPDATE, linitial, NIL, nodeTag, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DOMAIN, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_TABLE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, stmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, VAR_RESET, VAR_RESET_ALL, VAR_SET_CURRENT, VAR_SET_DEFAULT, VAR_SET_MULTI, VAR_SET_VALUE, and WARNING.

Referenced by _SPI_prepare_oneshot_plan(), _SPI_prepare_plan(), CreateCommandName(), CreateCommandTag(), EventTriggerGetTag(), exec_parse_message(), exec_simple_query(), interpret_AS_clause(), PrepareQuery(), REGRESS_utility_command(), and standard_ProcessUtility().

◆ ExecDropStmt()

static void ExecDropStmt ( DropStmt stmt,
bool  isTopLevel 
)
static

Definition at line 1995 of file utility.c.

1996{
1997 switch (stmt->removeType)
1998 {
1999 case OBJECT_INDEX:
2000 if (stmt->concurrent)
2001 PreventInTransactionBlock(isTopLevel,
2002 "DROP INDEX CONCURRENTLY");
2003 /* fall through */
2004
2005 case OBJECT_TABLE:
2006 case OBJECT_SEQUENCE:
2007 case OBJECT_VIEW:
2008 case OBJECT_MATVIEW:
2011 break;
2012 default:
2014 break;
2015 }
2016}
void RemoveObjects(DropStmt *stmt)
Definition: dropcmds.c:53
void RemoveRelations(DropStmt *drop)
Definition: tablecmds.c:1488
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3640

References OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_VIEW, PreventInTransactionBlock(), RemoveObjects(), RemoveRelations(), and stmt.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3249 of file utility.c.

3250{
3251 LogStmtLevel lev;
3252
3253 switch (nodeTag(parsetree))
3254 {
3255 /* recurse if we're given a RawStmt */
3256 case T_RawStmt:
3257 lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
3258 break;
3259
3260 /* raw plannable queries */
3261 case T_InsertStmt:
3262 case T_DeleteStmt:
3263 case T_UpdateStmt:
3264 case T_MergeStmt:
3265 lev = LOGSTMT_MOD;
3266 break;
3267
3268 case T_SelectStmt:
3269 if (((SelectStmt *) parsetree)->intoClause)
3270 lev = LOGSTMT_DDL; /* SELECT INTO */
3271 else
3272 lev = LOGSTMT_ALL;
3273 break;
3274
3275 case T_PLAssignStmt:
3276 lev = LOGSTMT_ALL;
3277 break;
3278
3279 /* utility statements --- same whether raw or cooked */
3280 case T_TransactionStmt:
3281 lev = LOGSTMT_ALL;
3282 break;
3283
3284 case T_DeclareCursorStmt:
3285 lev = LOGSTMT_ALL;
3286 break;
3287
3288 case T_ClosePortalStmt:
3289 lev = LOGSTMT_ALL;
3290 break;
3291
3292 case T_FetchStmt:
3293 lev = LOGSTMT_ALL;
3294 break;
3295
3296 case T_CreateSchemaStmt:
3297 lev = LOGSTMT_DDL;
3298 break;
3299
3300 case T_CreateStmt:
3301 case T_CreateForeignTableStmt:
3302 lev = LOGSTMT_DDL;
3303 break;
3304
3305 case T_CreateTableSpaceStmt:
3306 case T_DropTableSpaceStmt:
3307 case T_AlterTableSpaceOptionsStmt:
3308 lev = LOGSTMT_DDL;
3309 break;
3310
3311 case T_CreateExtensionStmt:
3312 case T_AlterExtensionStmt:
3313 case T_AlterExtensionContentsStmt:
3314 lev = LOGSTMT_DDL;
3315 break;
3316
3317 case T_CreateFdwStmt:
3318 case T_AlterFdwStmt:
3319 case T_CreateForeignServerStmt:
3320 case T_AlterForeignServerStmt:
3321 case T_CreateUserMappingStmt:
3322 case T_AlterUserMappingStmt:
3323 case T_DropUserMappingStmt:
3324 case T_ImportForeignSchemaStmt:
3325 lev = LOGSTMT_DDL;
3326 break;
3327
3328 case T_DropStmt:
3329 lev = LOGSTMT_DDL;
3330 break;
3331
3332 case T_TruncateStmt:
3333 lev = LOGSTMT_MOD;
3334 break;
3335
3336 case T_CommentStmt:
3337 lev = LOGSTMT_DDL;
3338 break;
3339
3340 case T_SecLabelStmt:
3341 lev = LOGSTMT_DDL;
3342 break;
3343
3344 case T_CopyStmt:
3345 if (((CopyStmt *) parsetree)->is_from)
3346 lev = LOGSTMT_MOD;
3347 else
3348 lev = LOGSTMT_ALL;
3349 break;
3350
3351 case T_PrepareStmt:
3352 {
3353 PrepareStmt *stmt = (PrepareStmt *) parsetree;
3354
3355 /* Look through a PREPARE to the contained stmt */
3356 lev = GetCommandLogLevel(stmt->query);
3357 }
3358 break;
3359
3360 case T_ExecuteStmt:
3361 {
3362 ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
3364
3365 /* Look through an EXECUTE to the referenced stmt */
3366 ps = FetchPreparedStatement(stmt->name, false);
3367 if (ps && ps->plansource->raw_parse_tree)
3368 lev = GetCommandLogLevel(ps->plansource->raw_parse_tree->stmt);
3369 else
3370 lev = LOGSTMT_ALL;
3371 }
3372 break;
3373
3374 case T_DeallocateStmt:
3375 lev = LOGSTMT_ALL;
3376 break;
3377
3378 case T_RenameStmt:
3379 lev = LOGSTMT_DDL;
3380 break;
3381
3382 case T_AlterObjectDependsStmt:
3383 lev = LOGSTMT_DDL;
3384 break;
3385
3386 case T_AlterObjectSchemaStmt:
3387 lev = LOGSTMT_DDL;
3388 break;
3389
3390 case T_AlterOwnerStmt:
3391 lev = LOGSTMT_DDL;
3392 break;
3393
3394 case T_AlterOperatorStmt:
3395 lev = LOGSTMT_DDL;
3396 break;
3397
3398 case T_AlterTypeStmt:
3399 lev = LOGSTMT_DDL;
3400 break;
3401
3402 case T_AlterTableMoveAllStmt:
3403 case T_AlterTableStmt:
3404 lev = LOGSTMT_DDL;
3405 break;
3406
3407 case T_AlterDomainStmt:
3408 lev = LOGSTMT_DDL;
3409 break;
3410
3411 case T_GrantStmt:
3412 lev = LOGSTMT_DDL;
3413 break;
3414
3415 case T_GrantRoleStmt:
3416 lev = LOGSTMT_DDL;
3417 break;
3418
3419 case T_AlterDefaultPrivilegesStmt:
3420 lev = LOGSTMT_DDL;
3421 break;
3422
3423 case T_DefineStmt:
3424 lev = LOGSTMT_DDL;
3425 break;
3426
3427 case T_CompositeTypeStmt:
3428 lev = LOGSTMT_DDL;
3429 break;
3430
3431 case T_CreateEnumStmt:
3432 lev = LOGSTMT_DDL;
3433 break;
3434
3435 case T_CreateRangeStmt:
3436 lev = LOGSTMT_DDL;
3437 break;
3438
3439 case T_AlterEnumStmt:
3440 lev = LOGSTMT_DDL;
3441 break;
3442
3443 case T_ViewStmt:
3444 lev = LOGSTMT_DDL;
3445 break;
3446
3447 case T_CreateFunctionStmt:
3448 lev = LOGSTMT_DDL;
3449 break;
3450
3451 case T_AlterFunctionStmt:
3452 lev = LOGSTMT_DDL;
3453 break;
3454
3455 case T_IndexStmt:
3456 lev = LOGSTMT_DDL;
3457 break;
3458
3459 case T_RuleStmt:
3460 lev = LOGSTMT_DDL;
3461 break;
3462
3463 case T_CreateSeqStmt:
3464 lev = LOGSTMT_DDL;
3465 break;
3466
3467 case T_AlterSeqStmt:
3468 lev = LOGSTMT_DDL;
3469 break;
3470
3471 case T_DoStmt:
3472 lev = LOGSTMT_ALL;
3473 break;
3474
3475 case T_CreatedbStmt:
3476 lev = LOGSTMT_DDL;
3477 break;
3478
3479 case T_AlterDatabaseStmt:
3480 case T_AlterDatabaseRefreshCollStmt:
3481 case T_AlterDatabaseSetStmt:
3482 lev = LOGSTMT_DDL;
3483 break;
3484
3485 case T_DropdbStmt:
3486 lev = LOGSTMT_DDL;
3487 break;
3488
3489 case T_NotifyStmt:
3490 lev = LOGSTMT_ALL;
3491 break;
3492
3493 case T_ListenStmt:
3494 lev = LOGSTMT_ALL;
3495 break;
3496
3497 case T_UnlistenStmt:
3498 lev = LOGSTMT_ALL;
3499 break;
3500
3501 case T_LoadStmt:
3502 lev = LOGSTMT_ALL;
3503 break;
3504
3505 case T_CallStmt:
3506 lev = LOGSTMT_ALL;
3507 break;
3508
3509 case T_ClusterStmt:
3510 lev = LOGSTMT_DDL;
3511 break;
3512
3513 case T_VacuumStmt:
3514 lev = LOGSTMT_ALL;
3515 break;
3516
3517 case T_ExplainStmt:
3518 {
3519 ExplainStmt *stmt = (ExplainStmt *) parsetree;
3520 bool analyze = false;
3521 ListCell *lc;
3522
3523 /* Look through an EXPLAIN ANALYZE to the contained stmt */
3524 foreach(lc, stmt->options)
3525 {
3526 DefElem *opt = (DefElem *) lfirst(lc);
3527
3528 if (strcmp(opt->defname, "analyze") == 0)
3529 analyze = defGetBoolean(opt);
3530 /* don't "break", as explain.c will use the last value */
3531 }
3532 if (analyze)
3533 return GetCommandLogLevel(stmt->query);
3534
3535 /* Plain EXPLAIN isn't so interesting */
3536 lev = LOGSTMT_ALL;
3537 }
3538 break;
3539
3540 case T_CreateTableAsStmt:
3541 lev = LOGSTMT_DDL;
3542 break;
3543
3544 case T_RefreshMatViewStmt:
3545 lev = LOGSTMT_DDL;
3546 break;
3547
3548 case T_AlterSystemStmt:
3549 lev = LOGSTMT_DDL;
3550 break;
3551
3552 case T_VariableSetStmt:
3553 lev = LOGSTMT_ALL;
3554 break;
3555
3556 case T_VariableShowStmt:
3557 lev = LOGSTMT_ALL;
3558 break;
3559
3560 case T_DiscardStmt:
3561 lev = LOGSTMT_ALL;
3562 break;
3563
3564 case T_CreateTrigStmt:
3565 lev = LOGSTMT_DDL;
3566 break;
3567
3568 case T_CreateEventTrigStmt:
3569 lev = LOGSTMT_DDL;
3570 break;
3571
3572 case T_AlterEventTrigStmt:
3573 lev = LOGSTMT_DDL;
3574 break;
3575
3576 case T_CreatePLangStmt:
3577 lev = LOGSTMT_DDL;
3578 break;
3579
3580 case T_CreateDomainStmt:
3581 lev = LOGSTMT_DDL;
3582 break;
3583
3584 case T_CreateRoleStmt:
3585 lev = LOGSTMT_DDL;
3586 break;
3587
3588 case T_AlterRoleStmt:
3589 lev = LOGSTMT_DDL;
3590 break;
3591
3592 case T_AlterRoleSetStmt:
3593 lev = LOGSTMT_DDL;
3594 break;
3595
3596 case T_DropRoleStmt:
3597 lev = LOGSTMT_DDL;
3598 break;
3599
3600 case T_DropOwnedStmt:
3601 lev = LOGSTMT_DDL;
3602 break;
3603
3604 case T_ReassignOwnedStmt:
3605 lev = LOGSTMT_DDL;
3606 break;
3607
3608 case T_LockStmt:
3609 lev = LOGSTMT_ALL;
3610 break;
3611
3612 case T_ConstraintsSetStmt:
3613 lev = LOGSTMT_ALL;
3614 break;
3615
3616 case T_CheckPointStmt:
3617 lev = LOGSTMT_ALL;
3618 break;
3619
3620 case T_ReindexStmt:
3621 lev = LOGSTMT_ALL; /* should this be DDL? */
3622 break;
3623
3624 case T_CreateConversionStmt:
3625 lev = LOGSTMT_DDL;
3626 break;
3627
3628 case T_CreateCastStmt:
3629 lev = LOGSTMT_DDL;
3630 break;
3631
3632 case T_CreateOpClassStmt:
3633 lev = LOGSTMT_DDL;
3634 break;
3635
3636 case T_CreateOpFamilyStmt:
3637 lev = LOGSTMT_DDL;
3638 break;
3639
3640 case T_CreateTransformStmt:
3641 lev = LOGSTMT_DDL;
3642 break;
3643
3644 case T_AlterOpFamilyStmt:
3645 lev = LOGSTMT_DDL;
3646 break;
3647
3648 case T_CreatePolicyStmt:
3649 lev = LOGSTMT_DDL;
3650 break;
3651
3652 case T_AlterPolicyStmt:
3653 lev = LOGSTMT_DDL;
3654 break;
3655
3656 case T_AlterTSDictionaryStmt:
3657 lev = LOGSTMT_DDL;
3658 break;
3659
3660 case T_AlterTSConfigurationStmt:
3661 lev = LOGSTMT_DDL;
3662 break;
3663
3664 case T_CreateAmStmt:
3665 lev = LOGSTMT_DDL;
3666 break;
3667
3668 case T_CreatePublicationStmt:
3669 lev = LOGSTMT_DDL;
3670 break;
3671
3672 case T_AlterPublicationStmt:
3673 lev = LOGSTMT_DDL;
3674 break;
3675
3676 case T_CreateSubscriptionStmt:
3677 lev = LOGSTMT_DDL;
3678 break;
3679
3680 case T_AlterSubscriptionStmt:
3681 lev = LOGSTMT_DDL;
3682 break;
3683
3684 case T_DropSubscriptionStmt:
3685 lev = LOGSTMT_DDL;
3686 break;
3687
3688 case T_CreateStatsStmt:
3689 lev = LOGSTMT_DDL;
3690 break;
3691
3692 case T_AlterStatsStmt:
3693 lev = LOGSTMT_DDL;
3694 break;
3695
3696 case T_AlterCollationStmt:
3697 lev = LOGSTMT_DDL;
3698 break;
3699
3700 /* already-planned queries */
3701 case T_PlannedStmt:
3702 {
3703 PlannedStmt *stmt = (PlannedStmt *) parsetree;
3704
3705 switch (stmt->commandType)
3706 {
3707 case CMD_SELECT:
3708 lev = LOGSTMT_ALL;
3709 break;
3710
3711 case CMD_UPDATE:
3712 case CMD_INSERT:
3713 case CMD_DELETE:
3714 case CMD_MERGE:
3715 lev = LOGSTMT_MOD;
3716 break;
3717
3718 case CMD_UTILITY:
3719 lev = GetCommandLogLevel(stmt->utilityStmt);
3720 break;
3721
3722 default:
3723 elog(WARNING, "unrecognized commandType: %d",
3724 (int) stmt->commandType);
3725 lev = LOGSTMT_ALL;
3726 break;
3727 }
3728 }
3729 break;
3730
3731 /* parsed-and-rewritten-but-not-planned queries */
3732 case T_Query:
3733 {
3734 Query *stmt = (Query *) parsetree;
3735
3736 switch (stmt->commandType)
3737 {
3738 case CMD_SELECT:
3739 lev = LOGSTMT_ALL;
3740 break;
3741
3742 case CMD_UPDATE:
3743 case CMD_INSERT:
3744 case CMD_DELETE:
3745 case CMD_MERGE:
3746 lev = LOGSTMT_MOD;
3747 break;
3748
3749 case CMD_UTILITY:
3750 lev = GetCommandLogLevel(stmt->utilityStmt);
3751 break;
3752
3753 default:
3754 elog(WARNING, "unrecognized commandType: %d",
3755 (int) stmt->commandType);
3756 lev = LOGSTMT_ALL;
3757 break;
3758 }
3759 }
3760 break;
3761
3762 default:
3763 elog(WARNING, "unrecognized node type: %d",
3764 (int) nodeTag(parsetree));
3765 lev = LOGSTMT_ALL;
3766 break;
3767 }
3768
3769 return lev;
3770}
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:431
bool defGetBoolean(DefElem *def)
Definition: define.c:94
struct parser_state ps
#define lfirst(lc)
Definition: pg_list.h:172
static long analyze(struct nfa *nfa)
Definition: regc_nfa.c:3051
char * defname
Definition: parsenodes.h:817
LogStmtLevel
Definition: tcopprot.h:32
@ LOGSTMT_MOD
Definition: tcopprot.h:35
@ LOGSTMT_DDL
Definition: tcopprot.h:34
@ LOGSTMT_ALL
Definition: tcopprot.h:36
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:3249

References analyze(), CMD_DELETE, CMD_INSERT, CMD_MERGE, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, defGetBoolean(), DefElem::defname, elog, FetchPreparedStatement(), GetCommandLogLevel(), lfirst, LOGSTMT_ALL, LOGSTMT_DDL, LOGSTMT_MOD, nodeTag, ps, stmt, and WARNING.

Referenced by check_log_statement(), and GetCommandLogLevel().

◆ PreventCommandDuringRecovery()

void PreventCommandDuringRecovery ( const char *  cmdname)

Definition at line 441 of file utility.c.

442{
443 if (RecoveryInProgress())
445 (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
446 /* translator: %s is name of a SQL command, eg CREATE */
447 errmsg("cannot execute %s during recovery",
448 cmdname)));
449}
bool RecoveryInProgress(void)
Definition: xlog.c:6334

References ereport, errcode(), errmsg(), ERROR, and RecoveryInProgress().

Referenced by pg_current_xact_id(), pg_notify(), and standard_ProcessUtility().

◆ PreventCommandIfParallelMode()

void PreventCommandIfParallelMode ( const char *  cmdname)

Definition at line 422 of file utility.c.

423{
424 if (IsInParallelMode())
426 (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
427 /* translator: %s is name of a SQL command, eg CREATE */
428 errmsg("cannot execute %s during a parallel operation",
429 cmdname)));
430}
bool IsInParallelMode(void)
Definition: xact.c:1088

References ereport, errcode(), errmsg(), ERROR, and IsInParallelMode().

Referenced by do_setval(), ExecCheckXactReadOnly(), nextval_internal(), and standard_ProcessUtility().

◆ PreventCommandIfReadOnly()

void PreventCommandIfReadOnly ( const char *  cmdname)

Definition at line 404 of file utility.c.

405{
406 if (XactReadOnly)
408 (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
409 /* translator: %s is name of a SQL command, eg CREATE */
410 errmsg("cannot execute %s in a read-only transaction",
411 cmdname)));
412}
bool XactReadOnly
Definition: xact.c:81

References ereport, errcode(), errmsg(), ERROR, and XactReadOnly.

Referenced by be_lo_creat(), be_lo_create(), be_lo_from_bytea(), be_lo_open(), be_lo_put(), be_lo_truncate(), be_lo_truncate64(), be_lo_unlink(), be_lowrite(), do_setval(), DoCopy(), ExecCheckXactReadOnly(), lo_import_internal(), nextval_internal(), and standard_ProcessUtility().

◆ ProcessUtility()

void ProcessUtility ( PlannedStmt pstmt,
const char *  queryString,
bool  readOnlyTree,
ProcessUtilityContext  context,
ParamListInfo  params,
QueryEnvironment queryEnv,
DestReceiver dest,
QueryCompletion qc 
)

Definition at line 499 of file utility.c.

507{
508 Assert(IsA(pstmt, PlannedStmt));
509 Assert(pstmt->commandType == CMD_UTILITY);
510 Assert(queryString != NULL); /* required as of 8.4 */
511 Assert(qc == NULL || qc->commandTag == CMDTAG_UNKNOWN);
512
513 /*
514 * We provide a function hook variable that lets loadable plugins get
515 * control when ProcessUtility is called. Such a plugin would normally
516 * call standard_ProcessUtility().
517 */
519 (*ProcessUtility_hook) (pstmt, queryString, readOnlyTree,
520 context, params, queryEnv,
521 dest, qc);
522 else
523 standard_ProcessUtility(pstmt, queryString, readOnlyTree,
524 context, params, queryEnv,
525 dest, qc);
526}
tree context
Definition: radixtree.h:1837
CommandTag commandTag
Definition: cmdtag.h:31
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:543
ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:70

References Assert, CMD_UTILITY, QueryCompletion::commandTag, PlannedStmt::commandType, context, generate_unaccent_rules::dest, IsA, ProcessUtility_hook, and standard_ProcessUtility().

Referenced by _SPI_execute_plan(), CreateSchemaCommand(), execute_sql_string(), ImportForeignSchema(), PortalRunUtility(), postquel_getnext(), ProcessUtilityForAlterTable(), and ProcessUtilitySlow().

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

Definition at line 1959 of file utility.c.

1960{
1961 PlannedStmt *wrapper;
1962
1963 /*
1964 * For event triggers, we must "close" the current complex-command set,
1965 * and start a new one afterwards; this is needed to ensure the ordering
1966 * of command events is consistent with the way they were executed.
1967 */
1969
1970 /* Create a suitable wrapper */
1971 wrapper = makeNode(PlannedStmt);
1972 wrapper->commandType = CMD_UTILITY;
1973 wrapper->canSetTag = false;
1974 wrapper->utilityStmt = stmt;
1975 wrapper->stmt_location = context->pstmt->stmt_location;
1976 wrapper->stmt_len = context->pstmt->stmt_len;
1977
1978 ProcessUtility(wrapper,
1979 context->queryString,
1980 false,
1982 context->params,
1983 context->queryEnv,
1985 NULL);
1986
1987 EventTriggerAlterTableStart(context->pstmt->utilityStmt);
1989}
DestReceiver * None_Receiver
Definition: dest.c:96
void EventTriggerAlterTableStart(Node *parsetree)
void EventTriggerAlterTableRelid(Oid objectId)
void EventTriggerAlterTableEnd(void)
#define makeNode(_type_)
Definition: nodes.h:155
bool canSetTag
Definition: plannodes.h:60
ParseLoc stmt_len
Definition: plannodes.h:99
ParseLoc stmt_location
Definition: plannodes.h:98
Node * utilityStmt
Definition: plannodes.h:95
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:499
@ PROCESS_UTILITY_SUBCOMMAND
Definition: utility.h:26

References PlannedStmt::canSetTag, CMD_UTILITY, PlannedStmt::commandType, context, EventTriggerAlterTableEnd(), EventTriggerAlterTableRelid(), EventTriggerAlterTableStart(), makeNode, None_Receiver, PROCESS_UTILITY_SUBCOMMAND, ProcessUtility(), stmt, PlannedStmt::stmt_len, PlannedStmt::stmt_location, and PlannedStmt::utilityStmt.

Referenced by ATParseTransformCmd(), and ATRewriteTables().

◆ ProcessUtilitySlow()

static void ProcessUtilitySlow ( ParseState pstate,
PlannedStmt pstmt,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
QueryEnvironment queryEnv,
DestReceiver dest,
QueryCompletion qc 
)
static

Definition at line 1092 of file utility.c.

1100{
1101 Node *parsetree = pstmt->utilityStmt;
1102 bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
1103 bool isCompleteQuery = (context != PROCESS_UTILITY_SUBCOMMAND);
1104 bool needCleanup;
1105 bool commandCollected = false;
1106 ObjectAddress address;
1107 ObjectAddress secondaryObject = InvalidObjectAddress;
1108
1109 /* All event trigger calls are done only when isCompleteQuery is true */
1110 needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
1111
1112 /* PG_TRY block is to ensure we call EventTriggerEndCompleteQuery */
1113 PG_TRY();
1114 {
1115 if (isCompleteQuery)
1116 EventTriggerDDLCommandStart(parsetree);
1117
1118 switch (nodeTag(parsetree))
1119 {
1120 /*
1121 * relation and attribute manipulation
1122 */
1123 case T_CreateSchemaStmt:
1125 queryString,
1126 pstmt->stmt_location,
1127 pstmt->stmt_len);
1128
1129 /*
1130 * EventTriggerCollectSimpleCommand called by
1131 * CreateSchemaCommand
1132 */
1133 commandCollected = true;
1134 break;
1135
1136 case T_CreateStmt:
1137 case T_CreateForeignTableStmt:
1138 {
1139 List *stmts;
1140 RangeVar *table_rv = NULL;
1141
1142 /* Run parse analysis ... */
1143 stmts = transformCreateStmt((CreateStmt *) parsetree,
1144 queryString);
1145
1146 /*
1147 * ... and do it. We can't use foreach() because we may
1148 * modify the list midway through, so pick off the
1149 * elements one at a time, the hard way.
1150 */
1151 while (stmts != NIL)
1152 {
1153 Node *stmt = (Node *) linitial(stmts);
1154
1155 stmts = list_delete_first(stmts);
1156
1157 if (IsA(stmt, CreateStmt))
1158 {
1159 CreateStmt *cstmt = (CreateStmt *) stmt;
1160 Datum toast_options;
1161 const char *const validnsps[] = HEAP_RELOPT_NAMESPACES;
1162
1163 /* Remember transformed RangeVar for LIKE */
1164 table_rv = cstmt->relation;
1165
1166 /* Create the table itself */
1167 address = DefineRelation(cstmt,
1168 RELKIND_RELATION,
1169 InvalidOid, NULL,
1170 queryString);
1172 secondaryObject,
1173 stmt);
1174
1175 /*
1176 * Let NewRelationCreateToastTable decide if this
1177 * one needs a secondary relation too.
1178 */
1180
1181 /*
1182 * parse and validate reloptions for the toast
1183 * table
1184 */
1185 toast_options = transformRelOptions((Datum) 0,
1186 cstmt->options,
1187 "toast",
1188 validnsps,
1189 true,
1190 false);
1191 (void) heap_reloptions(RELKIND_TOASTVALUE,
1192 toast_options,
1193 true);
1194
1196 toast_options);
1197 }
1198 else if (IsA(stmt, CreateForeignTableStmt))
1199 {
1201
1202 /* Remember transformed RangeVar for LIKE */
1203 table_rv = cstmt->base.relation;
1204
1205 /* Create the table itself */
1206 address = DefineRelation(&cstmt->base,
1207 RELKIND_FOREIGN_TABLE,
1208 InvalidOid, NULL,
1209 queryString);
1210 CreateForeignTable(cstmt,
1211 address.objectId);
1213 secondaryObject,
1214 stmt);
1215 }
1216 else if (IsA(stmt, TableLikeClause))
1217 {
1218 /*
1219 * Do delayed processing of LIKE options. This
1220 * will result in additional sub-statements for us
1221 * to process. Those should get done before any
1222 * remaining actions, so prepend them to "stmts".
1223 */
1225 List *morestmts;
1226
1227 Assert(table_rv != NULL);
1228
1229 morestmts = expandTableLikeClause(table_rv, like);
1230 stmts = list_concat(morestmts, stmts);
1231 }
1232 else
1233 {
1234 /*
1235 * Recurse for anything else. Note the recursive
1236 * call will stash the objects so created into our
1237 * event trigger context.
1238 */
1239 PlannedStmt *wrapper;
1240
1241 wrapper = makeNode(PlannedStmt);
1242 wrapper->commandType = CMD_UTILITY;
1243 wrapper->canSetTag = false;
1244 wrapper->utilityStmt = stmt;
1245 wrapper->stmt_location = pstmt->stmt_location;
1246 wrapper->stmt_len = pstmt->stmt_len;
1247
1248 ProcessUtility(wrapper,
1249 queryString,
1250 false,
1252 params,
1253 NULL,
1255 NULL);
1256 }
1257
1258 /* Need CCI between commands */
1259 if (stmts != NIL)
1261 }
1262
1263 /*
1264 * The multiple commands generated here are stashed
1265 * individually, so disable collection below.
1266 */
1267 commandCollected = true;
1268 }
1269 break;
1270
1271 case T_AlterTableStmt:
1272 {
1273 AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
1274 Oid relid;
1275 LOCKMODE lockmode;
1276 ListCell *cell;
1277
1278 /*
1279 * Disallow ALTER TABLE .. DETACH CONCURRENTLY in a
1280 * transaction block or function. (Perhaps it could be
1281 * allowed in a procedure, but don't hold your breath.)
1282 */
1283 foreach(cell, atstmt->cmds)
1284 {
1285 AlterTableCmd *cmd = (AlterTableCmd *) lfirst(cell);
1286
1287 /* Disallow DETACH CONCURRENTLY in a transaction block */
1288 if (cmd->subtype == AT_DetachPartition)
1289 {
1290 if (((PartitionCmd *) cmd->def)->concurrent)
1291 PreventInTransactionBlock(isTopLevel,
1292 "ALTER TABLE ... DETACH CONCURRENTLY");
1293 }
1294 }
1295
1296 /*
1297 * Figure out lock mode, and acquire lock. This also does
1298 * basic permissions checks, so that we won't wait for a
1299 * lock on (for example) a relation on which we have no
1300 * permissions.
1301 */
1302 lockmode = AlterTableGetLockLevel(atstmt->cmds);
1303 relid = AlterTableLookupRelation(atstmt, lockmode);
1304
1305 if (OidIsValid(relid))
1306 {
1307 AlterTableUtilityContext atcontext;
1308
1309 /* Set up info needed for recursive callbacks ... */
1310 atcontext.pstmt = pstmt;
1311 atcontext.queryString = queryString;
1312 atcontext.relid = relid;
1313 atcontext.params = params;
1314 atcontext.queryEnv = queryEnv;
1315
1316 /* ... ensure we have an event trigger context ... */
1317 EventTriggerAlterTableStart(parsetree);
1319
1320 /* ... and do it */
1321 AlterTable(atstmt, lockmode, &atcontext);
1322
1323 /* done */
1325 }
1326 else
1328 (errmsg("relation \"%s\" does not exist, skipping",
1329 atstmt->relation->relname)));
1330 }
1331
1332 /* ALTER TABLE stashes commands internally */
1333 commandCollected = true;
1334 break;
1335
1336 case T_AlterDomainStmt:
1337 {
1338 AlterDomainStmt *stmt = (AlterDomainStmt *) parsetree;
1339
1340 /*
1341 * Some or all of these functions are recursive to cover
1342 * inherited things, so permission checks are done there.
1343 */
1344 switch (stmt->subtype)
1345 {
1346 case 'T': /* ALTER DOMAIN DEFAULT */
1347
1348 /*
1349 * Recursively alter column default for table and,
1350 * if requested, for descendants
1351 */
1352 address =
1353 AlterDomainDefault(stmt->typeName,
1354 stmt->def);
1355 break;
1356 case 'N': /* ALTER DOMAIN DROP NOT NULL */
1357 address =
1358 AlterDomainNotNull(stmt->typeName,
1359 false);
1360 break;
1361 case 'O': /* ALTER DOMAIN SET NOT NULL */
1362 address =
1363 AlterDomainNotNull(stmt->typeName,
1364 true);
1365 break;
1366 case 'C': /* ADD CONSTRAINT */
1367 address =
1369 stmt->def,
1370 &secondaryObject);
1371 break;
1372 case 'X': /* DROP CONSTRAINT */
1373 address =
1375 stmt->name,
1376 stmt->behavior,
1377 stmt->missing_ok);
1378 break;
1379 case 'V': /* VALIDATE CONSTRAINT */
1380 address =
1382 stmt->name);
1383 break;
1384 default: /* oops */
1385 elog(ERROR, "unrecognized alter domain type: %d",
1386 (int) stmt->subtype);
1387 break;
1388 }
1389 }
1390 break;
1391
1392 /*
1393 * ************* object creation / destruction **************
1394 */
1395 case T_DefineStmt:
1396 {
1397 DefineStmt *stmt = (DefineStmt *) parsetree;
1398
1399 switch (stmt->kind)
1400 {
1401 case OBJECT_AGGREGATE:
1402 address =
1403 DefineAggregate(pstate, stmt->defnames, stmt->args,
1404 stmt->oldstyle,
1405 stmt->definition,
1406 stmt->replace);
1407 break;
1408 case OBJECT_OPERATOR:
1409 Assert(stmt->args == NIL);
1410 address = DefineOperator(stmt->defnames,
1411 stmt->definition);
1412 break;
1413 case OBJECT_TYPE:
1414 Assert(stmt->args == NIL);
1415 address = DefineType(pstate,
1416 stmt->defnames,
1417 stmt->definition);
1418 break;
1419 case OBJECT_TSPARSER:
1420 Assert(stmt->args == NIL);
1421 address = DefineTSParser(stmt->defnames,
1422 stmt->definition);
1423 break;
1425 Assert(stmt->args == NIL);
1426 address = DefineTSDictionary(stmt->defnames,
1427 stmt->definition);
1428 break;
1429 case OBJECT_TSTEMPLATE:
1430 Assert(stmt->args == NIL);
1431 address = DefineTSTemplate(stmt->defnames,
1432 stmt->definition);
1433 break;
1435 Assert(stmt->args == NIL);
1436 address = DefineTSConfiguration(stmt->defnames,
1437 stmt->definition,
1438 &secondaryObject);
1439 break;
1440 case OBJECT_COLLATION:
1441 Assert(stmt->args == NIL);
1442 address = DefineCollation(pstate,
1443 stmt->defnames,
1444 stmt->definition,
1445 stmt->if_not_exists);
1446 break;
1447 default:
1448 elog(ERROR, "unrecognized define stmt type: %d",
1449 (int) stmt->kind);
1450 break;
1451 }
1452 }
1453 break;
1454
1455 case T_IndexStmt: /* CREATE INDEX */
1456 {
1457 IndexStmt *stmt = (IndexStmt *) parsetree;
1458 Oid relid;
1459 LOCKMODE lockmode;
1460 int nparts = -1;
1461 bool is_alter_table;
1462
1463 if (stmt->concurrent)
1464 PreventInTransactionBlock(isTopLevel,
1465 "CREATE INDEX CONCURRENTLY");
1466
1467 /*
1468 * Look up the relation OID just once, right here at the
1469 * beginning, so that we don't end up repeating the name
1470 * lookup later and latching onto a different relation
1471 * partway through. To avoid lock upgrade hazards, it's
1472 * important that we take the strongest lock that will
1473 * eventually be needed here, so the lockmode calculation
1474 * needs to match what DefineIndex() does.
1475 */
1476 lockmode = stmt->concurrent ? ShareUpdateExclusiveLock
1477 : ShareLock;
1478 relid =
1479 RangeVarGetRelidExtended(stmt->relation, lockmode,
1480 0,
1482 NULL);
1483
1484 /*
1485 * CREATE INDEX on partitioned tables (but not regular
1486 * inherited tables) recurses to partitions, so we must
1487 * acquire locks early to avoid deadlocks.
1488 *
1489 * We also take the opportunity to verify that all
1490 * partitions are something we can put an index on, to
1491 * avoid building some indexes only to fail later. While
1492 * at it, also count the partitions, so that DefineIndex
1493 * needn't do a duplicative find_all_inheritors search.
1494 */
1495 if (stmt->relation->inh &&
1496 get_rel_relkind(relid) == RELKIND_PARTITIONED_TABLE)
1497 {
1498 ListCell *lc;
1499 List *inheritors = NIL;
1500
1501 inheritors = find_all_inheritors(relid, lockmode, NULL);
1502 foreach(lc, inheritors)
1503 {
1504 Oid partrelid = lfirst_oid(lc);
1505 char relkind = get_rel_relkind(partrelid);
1506
1507 if (relkind != RELKIND_RELATION &&
1508 relkind != RELKIND_MATVIEW &&
1509 relkind != RELKIND_PARTITIONED_TABLE &&
1510 relkind != RELKIND_FOREIGN_TABLE)
1511 elog(ERROR, "unexpected relkind \"%c\" on partition \"%s\"",
1512 relkind, stmt->relation->relname);
1513
1514 if (relkind == RELKIND_FOREIGN_TABLE &&
1515 (stmt->unique || stmt->primary))
1516 ereport(ERROR,
1517 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1518 errmsg("cannot create unique index on partitioned table \"%s\"",
1519 stmt->relation->relname),
1520 errdetail("Table \"%s\" contains partitions that are foreign tables.",
1521 stmt->relation->relname)));
1522 }
1523 /* count direct and indirect children, but not rel */
1524 nparts = list_length(inheritors) - 1;
1525 list_free(inheritors);
1526 }
1527
1528 /*
1529 * If the IndexStmt is already transformed, it must have
1530 * come from generateClonedIndexStmt, which in current
1531 * usage means it came from expandTableLikeClause rather
1532 * than from original parse analysis. And that means we
1533 * must treat it like ALTER TABLE ADD INDEX, not CREATE.
1534 * (This is a bit grotty, but currently it doesn't seem
1535 * worth adding a separate bool field for the purpose.)
1536 */
1537 is_alter_table = stmt->transformed;
1538
1539 /* Run parse analysis ... */
1540 stmt = transformIndexStmt(relid, stmt, queryString);
1541
1542 /* ... and do it */
1543 EventTriggerAlterTableStart(parsetree);
1544 address =
1545 DefineIndex(relid, /* OID of heap relation */
1546 stmt,
1547 InvalidOid, /* no predefined OID */
1548 InvalidOid, /* no parent index */
1549 InvalidOid, /* no parent constraint */
1550 nparts, /* # of partitions, or -1 */
1551 is_alter_table,
1552 true, /* check_rights */
1553 true, /* check_not_in_use */
1554 false, /* skip_build */
1555 false); /* quiet */
1556
1557 /*
1558 * Add the CREATE INDEX node itself to stash right away;
1559 * if there were any commands stashed in the ALTER TABLE
1560 * code, we need them to appear after this one.
1561 */
1562 EventTriggerCollectSimpleCommand(address, secondaryObject,
1563 parsetree);
1564 commandCollected = true;
1566 }
1567 break;
1568
1569 case T_ReindexStmt:
1570 ExecReindex(pstate, (ReindexStmt *) parsetree, isTopLevel);
1571
1572 /* EventTriggerCollectSimpleCommand is called directly */
1573 commandCollected = true;
1574 break;
1575
1576 case T_CreateExtensionStmt:
1577 address = CreateExtension(pstate, (CreateExtensionStmt *) parsetree);
1578 break;
1579
1580 case T_AlterExtensionStmt:
1581 address = ExecAlterExtensionStmt(pstate, (AlterExtensionStmt *) parsetree);
1582 break;
1583
1584 case T_AlterExtensionContentsStmt:
1586 &secondaryObject);
1587 break;
1588
1589 case T_CreateFdwStmt:
1590 address = CreateForeignDataWrapper(pstate, (CreateFdwStmt *) parsetree);
1591 break;
1592
1593 case T_AlterFdwStmt:
1594 address = AlterForeignDataWrapper(pstate, (AlterFdwStmt *) parsetree);
1595 break;
1596
1597 case T_CreateForeignServerStmt:
1598 address = CreateForeignServer((CreateForeignServerStmt *) parsetree);
1599 break;
1600
1601 case T_AlterForeignServerStmt:
1602 address = AlterForeignServer((AlterForeignServerStmt *) parsetree);
1603 break;
1604
1605 case T_CreateUserMappingStmt:
1606 address = CreateUserMapping((CreateUserMappingStmt *) parsetree);
1607 break;
1608
1609 case T_AlterUserMappingStmt:
1610 address = AlterUserMapping((AlterUserMappingStmt *) parsetree);
1611 break;
1612
1613 case T_DropUserMappingStmt:
1615 /* no commands stashed for DROP */
1616 commandCollected = true;
1617 break;
1618
1619 case T_ImportForeignSchemaStmt:
1621 /* commands are stashed inside ImportForeignSchema */
1622 commandCollected = true;
1623 break;
1624
1625 case T_CompositeTypeStmt: /* CREATE TYPE (composite) */
1626 {
1627 CompositeTypeStmt *stmt = (CompositeTypeStmt *) parsetree;
1628
1629 address = DefineCompositeType(stmt->typevar,
1630 stmt->coldeflist);
1631 }
1632 break;
1633
1634 case T_CreateEnumStmt: /* CREATE TYPE AS ENUM */
1635 address = DefineEnum((CreateEnumStmt *) parsetree);
1636 break;
1637
1638 case T_CreateRangeStmt: /* CREATE TYPE AS RANGE */
1639 address = DefineRange(pstate, (CreateRangeStmt *) parsetree);
1640 break;
1641
1642 case T_AlterEnumStmt: /* ALTER TYPE (enum) */
1643 address = AlterEnum((AlterEnumStmt *) parsetree);
1644 break;
1645
1646 case T_ViewStmt: /* CREATE VIEW */
1647 EventTriggerAlterTableStart(parsetree);
1648 address = DefineView((ViewStmt *) parsetree, queryString,
1649 pstmt->stmt_location, pstmt->stmt_len);
1650 EventTriggerCollectSimpleCommand(address, secondaryObject,
1651 parsetree);
1652 /* stashed internally */
1653 commandCollected = true;
1655 break;
1656
1657 case T_CreateFunctionStmt: /* CREATE FUNCTION */
1658 address = CreateFunction(pstate, (CreateFunctionStmt *) parsetree);
1659 break;
1660
1661 case T_AlterFunctionStmt: /* ALTER FUNCTION */
1662 address = AlterFunction(pstate, (AlterFunctionStmt *) parsetree);
1663 break;
1664
1665 case T_RuleStmt: /* CREATE RULE */
1666 address = DefineRule((RuleStmt *) parsetree, queryString);
1667 break;
1668
1669 case T_CreateSeqStmt:
1670 address = DefineSequence(pstate, (CreateSeqStmt *) parsetree);
1671 break;
1672
1673 case T_AlterSeqStmt:
1674 address = AlterSequence(pstate, (AlterSeqStmt *) parsetree);
1675 break;
1676
1677 case T_CreateTableAsStmt:
1678 address = ExecCreateTableAs(pstate, (CreateTableAsStmt *) parsetree,
1679 params, queryEnv, qc);
1680 break;
1681
1682 case T_RefreshMatViewStmt:
1683
1684 /*
1685 * REFRESH CONCURRENTLY executes some DDL commands internally.
1686 * Inhibit DDL command collection here to avoid those commands
1687 * from showing up in the deparsed command queue. The refresh
1688 * command itself is queued, which is enough.
1689 */
1691 PG_TRY(2);
1692 {
1693 address = ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
1694 queryString, qc);
1695 }
1696 PG_FINALLY(2);
1697 {
1699 }
1700 PG_END_TRY(2);
1701 break;
1702
1703 case T_CreateTrigStmt:
1704 address = CreateTrigger((CreateTrigStmt *) parsetree,
1705 queryString, InvalidOid, InvalidOid,
1707 InvalidOid, NULL, false, false);
1708 break;
1709
1710 case T_CreatePLangStmt:
1711 address = CreateProceduralLanguage((CreatePLangStmt *) parsetree);
1712 break;
1713
1714 case T_CreateDomainStmt:
1715 address = DefineDomain(pstate, (CreateDomainStmt *) parsetree);
1716 break;
1717
1718 case T_CreateConversionStmt:
1719 address = CreateConversionCommand((CreateConversionStmt *) parsetree);
1720 break;
1721
1722 case T_CreateCastStmt:
1723 address = CreateCast((CreateCastStmt *) parsetree);
1724 break;
1725
1726 case T_CreateOpClassStmt:
1727 DefineOpClass((CreateOpClassStmt *) parsetree);
1728 /* command is stashed in DefineOpClass */
1729 commandCollected = true;
1730 break;
1731
1732 case T_CreateOpFamilyStmt:
1733 address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1734
1735 /*
1736 * DefineOpFamily calls EventTriggerCollectSimpleCommand
1737 * directly.
1738 */
1739 commandCollected = true;
1740 break;
1741
1742 case T_CreateTransformStmt:
1743 address = CreateTransform((CreateTransformStmt *) parsetree);
1744 break;
1745
1746 case T_AlterOpFamilyStmt:
1747 AlterOpFamily((AlterOpFamilyStmt *) parsetree);
1748 /* commands are stashed in AlterOpFamily */
1749 commandCollected = true;
1750 break;
1751
1752 case T_AlterTSDictionaryStmt:
1753 address = AlterTSDictionary((AlterTSDictionaryStmt *) parsetree);
1754 break;
1755
1756 case T_AlterTSConfigurationStmt:
1758
1759 /*
1760 * Commands are stashed in MakeConfigurationMapping and
1761 * DropConfigurationMapping, which are called from
1762 * AlterTSConfiguration
1763 */
1764 commandCollected = true;
1765 break;
1766
1767 case T_AlterTableMoveAllStmt:
1769 /* commands are stashed in AlterTableMoveAll */
1770 commandCollected = true;
1771 break;
1772
1773 case T_DropStmt:
1774 ExecDropStmt((DropStmt *) parsetree, isTopLevel);
1775 /* no commands stashed for DROP */
1776 commandCollected = true;
1777 break;
1778
1779 case T_RenameStmt:
1780 address = ExecRenameStmt((RenameStmt *) parsetree);
1781 break;
1782
1783 case T_AlterObjectDependsStmt:
1784 address =
1786 &secondaryObject);
1787 break;
1788
1789 case T_AlterObjectSchemaStmt:
1790 address =
1792 &secondaryObject);
1793 break;
1794
1795 case T_AlterOwnerStmt:
1796 address = ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
1797 break;
1798
1799 case T_AlterOperatorStmt:
1800 address = AlterOperator((AlterOperatorStmt *) parsetree);
1801 break;
1802
1803 case T_AlterTypeStmt:
1804 address = AlterType((AlterTypeStmt *) parsetree);
1805 break;
1806
1807 case T_CommentStmt:
1808 address = CommentObject((CommentStmt *) parsetree);
1809 break;
1810
1811 case T_GrantStmt:
1812 ExecuteGrantStmt((GrantStmt *) parsetree);
1813 /* commands are stashed in ExecGrantStmt_oids */
1814 commandCollected = true;
1815 break;
1816
1817 case T_DropOwnedStmt:
1818 DropOwnedObjects((DropOwnedStmt *) parsetree);
1819 /* no commands stashed for DROP */
1820 commandCollected = true;
1821 break;
1822
1823 case T_AlterDefaultPrivilegesStmt:
1826 commandCollected = true;
1827 break;
1828
1829 case T_CreatePolicyStmt: /* CREATE POLICY */
1830 address = CreatePolicy((CreatePolicyStmt *) parsetree);
1831 break;
1832
1833 case T_AlterPolicyStmt: /* ALTER POLICY */
1834 address = AlterPolicy((AlterPolicyStmt *) parsetree);
1835 break;
1836
1837 case T_SecLabelStmt:
1838 address = ExecSecLabelStmt((SecLabelStmt *) parsetree);
1839 break;
1840
1841 case T_CreateAmStmt:
1842 address = CreateAccessMethod((CreateAmStmt *) parsetree);
1843 break;
1844
1845 case T_CreatePublicationStmt:
1846 address = CreatePublication(pstate, (CreatePublicationStmt *) parsetree);
1847 break;
1848
1849 case T_AlterPublicationStmt:
1850 AlterPublication(pstate, (AlterPublicationStmt *) parsetree);
1851
1852 /*
1853 * AlterPublication calls EventTriggerCollectSimpleCommand
1854 * directly
1855 */
1856 commandCollected = true;
1857 break;
1858
1859 case T_CreateSubscriptionStmt:
1860 address = CreateSubscription(pstate,
1861 (CreateSubscriptionStmt *) parsetree,
1862 isTopLevel);
1863 break;
1864
1865 case T_AlterSubscriptionStmt:
1866 address = AlterSubscription(pstate,
1867 (AlterSubscriptionStmt *) parsetree,
1868 isTopLevel);
1869 break;
1870
1871 case T_DropSubscriptionStmt:
1872 DropSubscription((DropSubscriptionStmt *) parsetree, isTopLevel);
1873 /* no commands stashed for DROP */
1874 commandCollected = true;
1875 break;
1876
1877 case T_CreateStatsStmt:
1878 {
1879 Oid relid;
1880 CreateStatsStmt *stmt = (CreateStatsStmt *) parsetree;
1881 RangeVar *rel = (RangeVar *) linitial(stmt->relations);
1882
1883 if (!IsA(rel, RangeVar))
1884 ereport(ERROR,
1885 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1886 errmsg("only a single relation is allowed in CREATE STATISTICS")));
1887
1888 /*
1889 * CREATE STATISTICS will influence future execution plans
1890 * but does not interfere with currently executing plans.
1891 * So it should be enough to take ShareUpdateExclusiveLock
1892 * on relation, conflicting with ANALYZE and other DDL
1893 * that sets statistical information, but not with normal
1894 * queries.
1895 *
1896 * XXX RangeVarCallbackOwnsRelation not needed here, to
1897 * keep the same behavior as before.
1898 */
1899 relid = RangeVarGetRelid(rel, ShareUpdateExclusiveLock, false);
1900
1901 /* Run parse analysis ... */
1902 stmt = transformStatsStmt(relid, stmt, queryString);
1903
1904 address = CreateStatistics(stmt);
1905 }
1906 break;
1907
1908 case T_AlterStatsStmt:
1909 address = AlterStatistics((AlterStatsStmt *) parsetree);
1910 break;
1911
1912 case T_AlterCollationStmt:
1913 address = AlterCollation((AlterCollationStmt *) parsetree);
1914 break;
1915
1916 default:
1917 elog(ERROR, "unrecognized node type: %d",
1918 (int) nodeTag(parsetree));
1919 break;
1920 }
1921
1922 /*
1923 * Remember the object so that ddl_command_end event triggers have
1924 * access to it.
1925 */
1926 if (!commandCollected)
1927 EventTriggerCollectSimpleCommand(address, secondaryObject,
1928 parsetree);
1929
1930 if (isCompleteQuery)
1931 {
1932 EventTriggerSQLDrop(parsetree);
1933 EventTriggerDDLCommandEnd(parsetree);
1934 }
1935 }
1936 PG_FINALLY();
1937 {
1938 if (needCleanup)
1940 }
1941 PG_END_TRY();
1942}
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:392
void ExecAlterDefaultPrivilegesStmt(ParseState *pstate, AlterDefaultPrivilegesStmt *stmt)
Definition: aclchk.c:903
ObjectAddress DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List *parameters, bool replace)
Definition: aggregatecmds.c:53
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition: alter.c:821
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:455
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition: alter.c:357
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:518
ObjectAddress CreateAccessMethod(CreateAmStmt *stmt)
Definition: amcmds.c:43
#define OidIsValid(objectId)
Definition: c.h:729
ObjectAddress AlterCollation(AlterCollationStmt *stmt)
ObjectAddress DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_exists)
Definition: collationcmds.c:53
ObjectAddress DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
Definition: sequence.c:121
ObjectAddress AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
Definition: sequence.c:437
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectAddress CreateConversionCommand(CreateConversionStmt *stmt)
ObjectAddress ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, ParamListInfo params, QueryEnvironment *queryEnv, QueryCompletion *qc)
Definition: createas.c:221
int errdetail(const char *fmt,...)
Definition: elog.c:1203
#define PG_TRY(...)
Definition: elog.h:371
#define PG_END_TRY(...)
Definition: elog.h:396
#define NOTICE
Definition: elog.h:35
#define PG_FINALLY(...)
Definition: elog.h:388
void EventTriggerUndoInhibitCommandCollection(void)
void EventTriggerCollectAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt)
void EventTriggerDDLCommandStart(Node *parsetree)
void EventTriggerInhibitCommandCollection(void)
bool EventTriggerBeginCompleteQuery(void)
void EventTriggerSQLDrop(Node *parsetree)
void EventTriggerEndCompleteQuery(void)
void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
void EventTriggerDDLCommandEnd(Node *parsetree)
ObjectAddress CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt)
Definition: extension.c:1879
ObjectAddress ExecAlterExtensionStmt(ParseState *pstate, AlterExtensionStmt *stmt)
Definition: extension.c:3098
ObjectAddress ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt, ObjectAddress *objAddr)
Definition: extension.c:3403
void ImportForeignSchema(ImportForeignSchemaStmt *stmt)
Definition: foreigncmds.c:1484
ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt)
Definition: foreigncmds.c:974
ObjectAddress AlterForeignDataWrapper(ParseState *pstate, AlterFdwStmt *stmt)
Definition: foreigncmds.c:674
ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt)
Definition: foreigncmds.c:838
Oid RemoveUserMapping(DropUserMappingStmt *stmt)
Definition: foreigncmds.c:1324
ObjectAddress CreateForeignDataWrapper(ParseState *pstate, CreateFdwStmt *stmt)
Definition: foreigncmds.c:558
ObjectAddress AlterUserMapping(AlterUserMappingStmt *stmt)
Definition: foreigncmds.c:1226
void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid)
Definition: foreigncmds.c:1404
ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt)
Definition: foreigncmds.c:1100
ObjectAddress CreateCast(CreateCastStmt *stmt)
ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
ObjectAddress AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt)
ObjectAddress CreateTransform(CreateTransformStmt *stmt)
void ExecReindex(ParseState *pstate, const ReindexStmt *stmt, bool isTopLevel)
Definition: indexcmds.c:2801
ObjectAddress DefineIndex(Oid tableId, IndexStmt *stmt, Oid indexRelationId, Oid parentIndexId, Oid parentConstraintId, int total_parts, bool is_alter_table, bool check_rights, bool check_not_in_use, bool skip_build, bool quiet)
Definition: indexcmds.c:543
List * list_delete_first(List *list)
Definition: list.c:943
List * list_concat(List *list1, const List *list2)
Definition: list.c:561
void list_free(List *list)
Definition: list.c:1546
int LOCKMODE
Definition: lockdefs.h:26
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
#define ShareLock
Definition: lockdefs.h:40
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:2003
ObjectAddress ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, QueryCompletion *qc)
Definition: matview.c:121
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:441
#define RangeVarGetRelid(relation, lockmode, missing_ok)
Definition: namespace.h:80
const ObjectAddress InvalidObjectAddress
ObjectAddress DefineOpClass(CreateOpClassStmt *stmt)
Definition: opclasscmds.c:333
ObjectAddress DefineOpFamily(CreateOpFamilyStmt *stmt)
Definition: opclasscmds.c:772
Oid AlterOpFamily(AlterOpFamilyStmt *stmt)
Definition: opclasscmds.c:817
ObjectAddress AlterOperator(AlterOperatorStmt *stmt)
Definition: operatorcmds.c:462
ObjectAddress DefineOperator(List *names, List *parameters)
Definition: operatorcmds.c:67
List * transformCreateStmt(CreateStmt *stmt, const char *queryString)
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
List * expandTableLikeClause(RangeVar *heapRel, TableLikeClause *table_like_clause)
CreateStatsStmt * transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString)
@ AT_DetachPartition
Definition: parsenodes.h:2420
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
Definition: pg_inherits.c:255
static int list_length(const List *l)
Definition: pg_list.h:152
#define lfirst_oid(lc)
Definition: pg_list.h:174
ObjectAddress CreatePolicy(CreatePolicyStmt *stmt)
Definition: policy.c:569
ObjectAddress AlterPolicy(AlterPolicyStmt *stmt)
Definition: policy.c:768
uintptr_t Datum
Definition: postgres.h:64
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt)
Definition: proclang.c:37
ObjectAddress CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
void AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt)
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, const char *const validnsps[], bool acceptOidsOff, bool isReset)
Definition: reloptions.c:1156
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:2019
#define HEAP_RELOPT_NAMESPACES
Definition: reloptions.h:61
ObjectAddress DefineRule(RuleStmt *stmt, const char *queryString)
Oid CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: schemacmds.c:52
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:115
ObjectAddress AlterStatistics(AlterStatsStmt *stmt)
Definition: statscmds.c:599
ObjectAddress CreateStatistics(CreateStatsStmt *stmt)
Definition: statscmds.c:62
AlterTableType subtype
Definition: parsenodes.h:2438
RangeVar * relation
Definition: parsenodes.h:2352
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
List * options
Definition: parsenodes.h:2684
RangeVar * relation
Definition: parsenodes.h:2675
Definition: pg_list.h:54
Definition: nodes.h:129
char * relname
Definition: primnodes.h:82
void DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
ObjectAddress CreateSubscription(ParseState *pstate, CreateSubscriptionStmt *stmt, bool isTopLevel)
ObjectAddress AlterSubscription(ParseState *pstate, AlterSubscriptionStmt *stmt, bool isTopLevel)
void AlterTable(AlterTableStmt *stmt, LOCKMODE lockmode, AlterTableUtilityContext *context)
Definition: tablecmds.c:4451
LOCKMODE AlterTableGetLockLevel(List *cmds)
Definition: tablecmds.c:4525
Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
Definition: tablecmds.c:4392
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
Definition: tablecmds.c:713
Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
Definition: tablecmds.c:15775
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
Definition: tablecmds.c:18321
void NewRelationCreateToastTable(Oid relOid, Datum reloptions)
Definition: toasting.c:71
ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, Oid funcoid, Oid parentTriggerOid, Node *whenClause, bool isInternal, bool in_partition)
Definition: trigger.c:158
ObjectAddress AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
Definition: tsearchcmds.c:1156
ObjectAddress DefineTSTemplate(List *names, List *parameters)
Definition: tsearchcmds.c:690
ObjectAddress DefineTSDictionary(List *names, List *parameters)
Definition: tsearchcmds.c:397
ObjectAddress DefineTSConfiguration(List *names, List *parameters, ObjectAddress *copied)
Definition: tsearchcmds.c:899
ObjectAddress AlterTSDictionary(AlterTSDictionaryStmt *stmt)
Definition: tsearchcmds.c:493
ObjectAddress DefineTSParser(List *names, List *parameters)
Definition: tsearchcmds.c:184
ObjectAddress AlterDomainNotNull(List *names, bool notNull)
Definition: typecmds.c:2723
ObjectAddress DefineType(ParseState *pstate, List *names, List *parameters)
Definition: typecmds.c:152
ObjectAddress DefineEnum(CreateEnumStmt *stmt)
Definition: typecmds.c:1165
ObjectAddress AlterDomainDropConstraint(List *names, const char *constrName, DropBehavior behavior, bool missing_ok)
Definition: typecmds.c:2809
ObjectAddress AlterEnum(AlterEnumStmt *stmt)
Definition: typecmds.c:1289
ObjectAddress AlterDomainAddConstraint(List *names, Node *newConstraint, ObjectAddress *constrAddr)
Definition: typecmds.c:2915
ObjectAddress DefineDomain(ParseState *pstate, CreateDomainStmt *stmt)
Definition: typecmds.c:697
ObjectAddress AlterDomainValidateConstraint(List *names, const char *constrName)
Definition: typecmds.c:3055
ObjectAddress AlterDomainDefault(List *names, Node *defaultRaw)
Definition: typecmds.c:2594
ObjectAddress DefineCompositeType(RangeVar *typevar, List *coldeflist)
Definition: typecmds.c:2536
ObjectAddress AlterType(AlterTypeStmt *stmt)
Definition: typecmds.c:4332
ObjectAddress DefineRange(ParseState *pstate, CreateRangeStmt *stmt)
Definition: typecmds.c:1364
void DropOwnedObjects(DropOwnedStmt *stmt)
Definition: user.c:1583
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1995
@ PROCESS_UTILITY_TOPLEVEL
Definition: utility.h:22
ObjectAddress DefineView(ViewStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: view.c:356
void CommandCounterIncrement(void)
Definition: xact.c:1099

References AlterCollation(), AlterDomainAddConstraint(), AlterDomainDefault(), AlterDomainDropConstraint(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEnum(), AlterForeignDataWrapper(), AlterForeignServer(), AlterFunction(), AlterOperator(), AlterOpFamily(), AlterPolicy(), AlterPublication(), AlterSequence(), AlterStatistics(), AlterSubscription(), AlterTable(), AlterTableGetLockLevel(), AlterTableLookupRelation(), AlterTableMoveAll(), AlterTSConfiguration(), AlterTSDictionary(), AlterType(), AlterUserMapping(), Assert, AT_DetachPartition, CreateForeignTableStmt::base, PlannedStmt::canSetTag, CMD_UTILITY, AlterTableStmt::cmds, CommandCounterIncrement(), PlannedStmt::commandType, CommentObject(), context, CreateAccessMethod(), CreateCast(), CreateConversionCommand(), CreateExtension(), CreateForeignDataWrapper(), CreateForeignServer(), CreateForeignTable(), CreateFunction(), CreatePolicy(), CreateProceduralLanguage(), CreatePublication(), CreateSchemaCommand(), CreateStatistics(), CreateSubscription(), CreateTransform(), CreateTrigger(), CreateUserMapping(), AlterTableCmd::def, DefineAggregate(), DefineCollation(), DefineCompositeType(), DefineDomain(), DefineEnum(), DefineIndex(), DefineOpClass(), DefineOperator(), DefineOpFamily(), DefineRange(), DefineRelation(), DefineRule(), DefineSequence(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), DefineType(), DefineView(), DropOwnedObjects(), DropSubscription(), elog, ereport, errcode(), errdetail(), errmsg(), ERROR, EventTriggerAlterTableEnd(), EventTriggerAlterTableRelid(), EventTriggerAlterTableStart(), EventTriggerBeginCompleteQuery(), EventTriggerCollectAlterDefPrivs(), EventTriggerCollectSimpleCommand(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerEndCompleteQuery(), EventTriggerInhibitCommandCollection(), EventTriggerSQLDrop(), EventTriggerUndoInhibitCommandCollection(), ExecAlterDefaultPrivilegesStmt(), ExecAlterExtensionContentsStmt(), ExecAlterExtensionStmt(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecCreateTableAs(), ExecDropStmt(), ExecRefreshMatView(), ExecReindex(), ExecRenameStmt(), ExecSecLabelStmt(), ExecuteGrantStmt(), expandTableLikeClause(), find_all_inheritors(), get_rel_relkind(), HEAP_RELOPT_NAMESPACES, heap_reloptions(), ImportForeignSchema(), InvalidObjectAddress, InvalidOid, IsA, lfirst, lfirst_oid, linitial, list_concat(), list_delete_first(), list_free(), list_length(), makeNode, NewRelationCreateToastTable(), NIL, nodeTag, None_Receiver, NOTICE, OBJECT_AGGREGATE, OBJECT_COLLATION, OBJECT_OPERATOR, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, ObjectAddress::objectId, OidIsValid, CreateStmt::options, AlterTableUtilityContext::params, PG_END_TRY, PG_FINALLY, PG_TRY, PreventInTransactionBlock(), PROCESS_UTILITY_SUBCOMMAND, PROCESS_UTILITY_TOPLEVEL, ProcessUtility(), AlterTableUtilityContext::pstmt, AlterTableUtilityContext::queryEnv, AlterTableUtilityContext::queryString, RangeVarCallbackOwnsRelation(), RangeVarGetRelid, RangeVarGetRelidExtended(), AlterTableStmt::relation, CreateStmt::relation, AlterTableUtilityContext::relid, RangeVar::relname, RemoveUserMapping(), ShareLock, ShareUpdateExclusiveLock, stmt, PlannedStmt::stmt_len, PlannedStmt::stmt_location, AlterTableCmd::subtype, transformCreateStmt(), transformIndexStmt(), transformRelOptions(), transformStatsStmt(), and PlannedStmt::utilityStmt.

Referenced by standard_ProcessUtility().

◆ standard_ProcessUtility()

void standard_ProcessUtility ( PlannedStmt pstmt,
const char *  queryString,
bool  readOnlyTree,
ProcessUtilityContext  context,
ParamListInfo  params,
QueryEnvironment queryEnv,
DestReceiver dest,
QueryCompletion qc 
)

Definition at line 543 of file utility.c.

551{
552 Node *parsetree;
553 bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
555 ParseState *pstate;
556 int readonly_flags;
557
558 /* This can recurse, so check for excessive recursion */
560
561 /*
562 * If the given node tree is read-only, make a copy to ensure that parse
563 * transformations don't damage the original tree. This could be
564 * refactored to avoid making unnecessary copies in more cases, but it's
565 * not clear that it's worth a great deal of trouble over. Statements
566 * that are complex enough to be expensive to copy are exactly the ones
567 * we'd need to copy, so that only marginal savings seem possible.
568 */
569 if (readOnlyTree)
570 pstmt = copyObject(pstmt);
571 parsetree = pstmt->utilityStmt;
572
573 /* Prohibit read/write commands in read-only states. */
574 readonly_flags = ClassifyUtilityCommandAsReadOnly(parsetree);
575 if (readonly_flags != COMMAND_IS_STRICTLY_READ_ONLY &&
577 {
578 CommandTag commandtag = CreateCommandTag(parsetree);
579
580 if ((readonly_flags & COMMAND_OK_IN_READ_ONLY_TXN) == 0)
582 if ((readonly_flags & COMMAND_OK_IN_PARALLEL_MODE) == 0)
584 if ((readonly_flags & COMMAND_OK_IN_RECOVERY) == 0)
586 }
587
588 pstate = make_parsestate(NULL);
589 pstate->p_sourcetext = queryString;
590 pstate->p_queryEnv = queryEnv;
591
592 switch (nodeTag(parsetree))
593 {
594 /*
595 * ******************** transactions ********************
596 */
597 case T_TransactionStmt:
598 {
599 TransactionStmt *stmt = (TransactionStmt *) parsetree;
600
601 switch (stmt->kind)
602 {
603 /*
604 * START TRANSACTION, as defined by SQL99: Identical
605 * to BEGIN. Same code for both.
606 */
607 case TRANS_STMT_BEGIN:
608 case TRANS_STMT_START:
609 {
610 ListCell *lc;
611
613 foreach(lc, stmt->options)
614 {
615 DefElem *item = (DefElem *) lfirst(lc);
616
617 if (strcmp(item->defname, "transaction_isolation") == 0)
618 SetPGVariable("transaction_isolation",
619 list_make1(item->arg),
620 true);
621 else if (strcmp(item->defname, "transaction_read_only") == 0)
622 SetPGVariable("transaction_read_only",
623 list_make1(item->arg),
624 true);
625 else if (strcmp(item->defname, "transaction_deferrable") == 0)
626 SetPGVariable("transaction_deferrable",
627 list_make1(item->arg),
628 true);
629 }
630 }
631 break;
632
634 if (!EndTransactionBlock(stmt->chain))
635 {
636 /* report unsuccessful commit in qc */
637 if (qc)
638 SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
639 }
640 break;
641
643 if (!PrepareTransactionBlock(stmt->gid))
644 {
645 /* report unsuccessful commit in qc */
646 if (qc)
647 SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
648 }
649 break;
650
652 PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
654 break;
655
657 PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
658 FinishPreparedTransaction(stmt->gid, false);
659 break;
660
663 break;
664
666 RequireTransactionBlock(isTopLevel, "SAVEPOINT");
667 DefineSavepoint(stmt->savepoint_name);
668 break;
669
671 RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
672 ReleaseSavepoint(stmt->savepoint_name);
673 break;
674
676 RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
677 RollbackToSavepoint(stmt->savepoint_name);
678
679 /*
680 * CommitTransactionCommand is in charge of
681 * re-defining the savepoint again
682 */
683 break;
684 }
685 }
686 break;
687
688 /*
689 * Portal (cursor) manipulation
690 */
691 case T_DeclareCursorStmt:
692 PerformCursorOpen(pstate, (DeclareCursorStmt *) parsetree, params,
693 isTopLevel);
694 break;
695
696 case T_ClosePortalStmt:
697 {
698 ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
699
701 PerformPortalClose(stmt->portalname);
702 }
703 break;
704
705 case T_FetchStmt:
706 PerformPortalFetch((FetchStmt *) parsetree, dest, qc);
707 break;
708
709 case T_DoStmt:
710 ExecuteDoStmt(pstate, (DoStmt *) parsetree, isAtomicContext);
711 break;
712
713 case T_CreateTableSpaceStmt:
714 /* no event triggers for global objects */
715 PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
717 break;
718
719 case T_DropTableSpaceStmt:
720 /* no event triggers for global objects */
721 PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
722 DropTableSpace((DropTableSpaceStmt *) parsetree);
723 break;
724
725 case T_AlterTableSpaceOptionsStmt:
726 /* no event triggers for global objects */
728 break;
729
730 case T_TruncateStmt:
731 ExecuteTruncate((TruncateStmt *) parsetree);
732 break;
733
734 case T_CopyStmt:
735 {
736 uint64 processed;
737
738 DoCopy(pstate, (CopyStmt *) parsetree,
739 pstmt->stmt_location, pstmt->stmt_len,
740 &processed);
741 if (qc)
742 SetQueryCompletion(qc, CMDTAG_COPY, processed);
743 }
744 break;
745
746 case T_PrepareStmt:
747 CheckRestrictedOperation("PREPARE");
748 PrepareQuery(pstate, (PrepareStmt *) parsetree,
749 pstmt->stmt_location, pstmt->stmt_len);
750 break;
751
752 case T_ExecuteStmt:
753 ExecuteQuery(pstate,
754 (ExecuteStmt *) parsetree, NULL,
755 params,
756 dest, qc);
757 break;
758
759 case T_DeallocateStmt:
760 CheckRestrictedOperation("DEALLOCATE");
761 DeallocateQuery((DeallocateStmt *) parsetree);
762 break;
763
764 case T_GrantRoleStmt:
765 /* no event triggers for global objects */
766 GrantRole(pstate, (GrantRoleStmt *) parsetree);
767 break;
768
769 case T_CreatedbStmt:
770 /* no event triggers for global objects */
771 PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
772 createdb(pstate, (CreatedbStmt *) parsetree);
773 break;
774
775 case T_AlterDatabaseStmt:
776 /* no event triggers for global objects */
777 AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
778 break;
779
780 case T_AlterDatabaseRefreshCollStmt:
781 /* no event triggers for global objects */
783 break;
784
785 case T_AlterDatabaseSetStmt:
786 /* no event triggers for global objects */
788 break;
789
790 case T_DropdbStmt:
791 /* no event triggers for global objects */
792 PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
793 DropDatabase(pstate, (DropdbStmt *) parsetree);
794 break;
795
796 /* Query-level asynchronous notification */
797 case T_NotifyStmt:
798 {
799 NotifyStmt *stmt = (NotifyStmt *) parsetree;
800
801 Async_Notify(stmt->conditionname, stmt->payload);
802 }
803 break;
804
805 case T_ListenStmt:
806 {
807 ListenStmt *stmt = (ListenStmt *) parsetree;
808
809 CheckRestrictedOperation("LISTEN");
810
811 /*
812 * We don't allow LISTEN in background processes, as there is
813 * no mechanism for them to collect NOTIFY messages, so they'd
814 * just block cleanout of the async SLRU indefinitely.
815 * (Authors of custom background workers could bypass this
816 * restriction by calling Async_Listen directly, but then it's
817 * on them to provide some mechanism to process the message
818 * queue.) Note there seems no reason to forbid UNLISTEN.
819 */
822 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
823 /* translator: %s is name of a SQL command, eg LISTEN */
824 errmsg("cannot execute %s within a background process",
825 "LISTEN")));
826
827 Async_Listen(stmt->conditionname);
828 }
829 break;
830
831 case T_UnlistenStmt:
832 {
833 UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
834
835 CheckRestrictedOperation("UNLISTEN");
836 if (stmt->conditionname)
837 Async_Unlisten(stmt->conditionname);
838 else
840 }
841 break;
842
843 case T_LoadStmt:
844 {
845 LoadStmt *stmt = (LoadStmt *) parsetree;
846
847 closeAllVfds(); /* probably not necessary... */
848 /* Allowed names are restricted if you're not superuser */
849 load_file(stmt->filename, !superuser());
850 }
851 break;
852
853 case T_CallStmt:
854 ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
855 break;
856
857 case T_ClusterStmt:
858 cluster(pstate, (ClusterStmt *) parsetree, isTopLevel);
859 break;
860
861 case T_VacuumStmt:
862 ExecVacuum(pstate, (VacuumStmt *) parsetree, isTopLevel);
863 break;
864
865 case T_ExplainStmt:
866 ExplainQuery(pstate, (ExplainStmt *) parsetree, params, dest);
867 break;
868
869 case T_AlterSystemStmt:
870 PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
872 break;
873
874 case T_VariableSetStmt:
875 ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
876 break;
877
878 case T_VariableShowStmt:
879 {
880 VariableShowStmt *n = (VariableShowStmt *) parsetree;
881
883 }
884 break;
885
886 case T_DiscardStmt:
887 /* should we allow DISCARD PLANS? */
888 CheckRestrictedOperation("DISCARD");
889 DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
890 break;
891
892 case T_CreateEventTrigStmt:
893 /* no event triggers on event triggers */
895 break;
896
897 case T_AlterEventTrigStmt:
898 /* no event triggers on event triggers */
900 break;
901
902 /*
903 * ******************************** ROLE statements ****
904 */
905 case T_CreateRoleStmt:
906 /* no event triggers for global objects */
907 CreateRole(pstate, (CreateRoleStmt *) parsetree);
908 break;
909
910 case T_AlterRoleStmt:
911 /* no event triggers for global objects */
912 AlterRole(pstate, (AlterRoleStmt *) parsetree);
913 break;
914
915 case T_AlterRoleSetStmt:
916 /* no event triggers for global objects */
917 AlterRoleSet((AlterRoleSetStmt *) parsetree);
918 break;
919
920 case T_DropRoleStmt:
921 /* no event triggers for global objects */
922 DropRole((DropRoleStmt *) parsetree);
923 break;
924
925 case T_ReassignOwnedStmt:
926 /* no event triggers for global objects */
928 break;
929
930 case T_LockStmt:
931
932 /*
933 * Since the lock would just get dropped immediately, LOCK TABLE
934 * outside a transaction block is presumed to be user error.
935 */
936 RequireTransactionBlock(isTopLevel, "LOCK TABLE");
937 LockTableCommand((LockStmt *) parsetree);
938 break;
939
940 case T_ConstraintsSetStmt:
941 WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
943 break;
944
945 case T_CheckPointStmt:
946 if (!has_privs_of_role(GetUserId(), ROLE_PG_CHECKPOINT))
948 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
949 /* translator: %s is name of a SQL command, eg CHECKPOINT */
950 errmsg("permission denied to execute %s command",
951 "CHECKPOINT"),
952 errdetail("Only roles with privileges of the \"%s\" role may execute this command.",
953 "pg_checkpoint")));
954
957 break;
958
959 /*
960 * The following statements are supported by Event Triggers only
961 * in some cases, so we "fast path" them in the other cases.
962 */
963
964 case T_GrantStmt:
965 {
966 GrantStmt *stmt = (GrantStmt *) parsetree;
967
969 ProcessUtilitySlow(pstate, pstmt, queryString,
970 context, params, queryEnv,
971 dest, qc);
972 else
974 }
975 break;
976
977 case T_DropStmt:
978 {
979 DropStmt *stmt = (DropStmt *) parsetree;
980
981 if (EventTriggerSupportsObjectType(stmt->removeType))
982 ProcessUtilitySlow(pstate, pstmt, queryString,
983 context, params, queryEnv,
984 dest, qc);
985 else
986 ExecDropStmt(stmt, isTopLevel);
987 }
988 break;
989
990 case T_RenameStmt:
991 {
992 RenameStmt *stmt = (RenameStmt *) parsetree;
993
994 if (EventTriggerSupportsObjectType(stmt->renameType))
995 ProcessUtilitySlow(pstate, pstmt, queryString,
996 context, params, queryEnv,
997 dest, qc);
998 else
1000 }
1001 break;
1002
1003 case T_AlterObjectDependsStmt:
1004 {
1006
1007 if (EventTriggerSupportsObjectType(stmt->objectType))
1008 ProcessUtilitySlow(pstate, pstmt, queryString,
1009 context, params, queryEnv,
1010 dest, qc);
1011 else
1013 }
1014 break;
1015
1016 case T_AlterObjectSchemaStmt:
1017 {
1019
1020 if (EventTriggerSupportsObjectType(stmt->objectType))
1021 ProcessUtilitySlow(pstate, pstmt, queryString,
1022 context, params, queryEnv,
1023 dest, qc);
1024 else
1026 }
1027 break;
1028
1029 case T_AlterOwnerStmt:
1030 {
1031 AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
1032
1033 if (EventTriggerSupportsObjectType(stmt->objectType))
1034 ProcessUtilitySlow(pstate, pstmt, queryString,
1035 context, params, queryEnv,
1036 dest, qc);
1037 else
1039 }
1040 break;
1041
1042 case T_CommentStmt:
1043 {
1044 CommentStmt *stmt = (CommentStmt *) parsetree;
1045
1047 ProcessUtilitySlow(pstate, pstmt, queryString,
1048 context, params, queryEnv,
1049 dest, qc);
1050 else
1052 break;
1053 }
1054
1055 case T_SecLabelStmt:
1056 {
1057 SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
1058
1060 ProcessUtilitySlow(pstate, pstmt, queryString,
1061 context, params, queryEnv,
1062 dest, qc);
1063 else
1065 break;
1066 }
1067
1068 default:
1069 /* All other statement types have event trigger support */
1070 ProcessUtilitySlow(pstate, pstmt, queryString,
1071 context, params, queryEnv,
1072 dest, qc);
1073 break;
1074 }
1075
1076 free_parsestate(pstate);
1077
1078 /*
1079 * Make effects of commands visible, for instance so that
1080 * PreCommit_on_commit_actions() can see them (see for example bug
1081 * #15631).
1082 */
1084}
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:5268
void Async_UnlistenAll(void)
Definition: async.c:770
void Async_Unlisten(const char *channel)
Definition: async.c:752
void Async_Listen(const char *channel)
Definition: async.c:738
void Async_Notify(const char *channel, const char *payload)
Definition: async.c:591
void DoCopy(ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
Definition: copy.c:62
void PrepareQuery(ParseState *pstate, PrepareStmt *stmt, int stmt_location, int stmt_len)
Definition: prepare.c:56
void ExecuteQuery(ParseState *pstate, ExecuteStmt *stmt, IntoClause *intoClause, ParamListInfo params, DestReceiver *dest, QueryCompletion *qc)
Definition: prepare.c:147
void DeallocateQuery(DeallocateStmt *stmt)
Definition: prepare.c:502
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:1015
void DropTableSpace(DropTableSpaceStmt *stmt)
Definition: tablespace.c:395
Oid CreateTableSpace(CreateTableSpaceStmt *stmt)
Definition: tablespace.c:208
uint64_t uint64
Definition: c.h:486
void RequestCheckpoint(int flags)
Definition: checkpointer.c:952
void cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:107
const char * GetCommandTagName(CommandTag commandTag)
Definition: cmdtag.c:47
static void SetQueryCompletion(QueryCompletion *qc, CommandTag commandTag, uint64 nprocessed)
Definition: cmdtag.h:37
ObjectAddress AlterDatabaseRefreshColl(AlterDatabaseRefreshCollStmt *stmt)
Definition: dbcommands.c:2514
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
Definition: dbcommands.c:683
Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
Definition: dbcommands.c:2341
void DropDatabase(ParseState *pstate, DropdbStmt *stmt)
Definition: dbcommands.c:2316
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:2611
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:134
void DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
Definition: discard.c:31
bool EventTriggerSupportsObjectType(ObjectType obtype)
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
Oid AlterEventTrigger(AlterEventTrigStmt *stmt)
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest)
Definition: explain.c:191
void closeAllVfds(void)
Definition: fd.c:3042
void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest)
void ExecuteDoStmt(ParseState *pstate, DoStmt *stmt, bool atomic)
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:4607
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc_funcs.c:382
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc_funcs.c:315
void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
Definition: guc_funcs.c:43
void LockTableCommand(LockStmt *lockstmt)
Definition: lockcmds.c:41
@ B_BACKEND
Definition: miscadmin.h:341
Oid GetUserId(void)
Definition: miscinit.c:517
BackendType MyBackendType
Definition: miscinit.c:64
#define copyObject(obj)
Definition: nodes.h:224
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:72
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:39
#define list_make1(x1)
Definition: pg_list.h:212
void PerformCursorOpen(ParseState *pstate, DeclareCursorStmt *cstmt, ParamListInfo params, bool isTopLevel)
Definition: portalcmds.c:45
void PerformPortalClose(const char *name)
Definition: portalcmds.c:224
void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest, QueryCompletion *qc)
Definition: portalcmds.c:177
void check_stack_depth(void)
Definition: stack_depth.c:95
Node * arg
Definition: parsenodes.h:818
QueryEnvironment * p_queryEnv
Definition: parse_node.h:239
const char * p_sourcetext
Definition: parse_node.h:209
bool superuser(void)
Definition: superuser.c:46
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1811
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:5665
void FinishPreparedTransaction(const char *gid, bool isCommit)
Definition: twophase.c:1491
void ReassignOwnedObjects(ReassignOwnedStmt *stmt)
Definition: user.c:1611
Oid AlterRole(ParseState *pstate, AlterRoleStmt *stmt)
Definition: user.c:619
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:1000
void DropRole(DropRoleStmt *stmt)
Definition: user.c:1090
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Definition: user.c:132
void GrantRole(ParseState *pstate, GrantRoleStmt *stmt)
Definition: user.c:1480
static int ClassifyUtilityCommandAsReadOnly(Node *parsetree)
Definition: utility.c:128
void PreventCommandIfReadOnly(const char *cmdname)
Definition: utility.c:404
void PreventCommandIfParallelMode(const char *cmdname)
Definition: utility.c:422
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:459
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:441
static void ProcessUtilitySlow(ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:1092
#define COMMAND_OK_IN_PARALLEL_MODE
Definition: utility.h:57
@ PROCESS_UTILITY_QUERY_NONATOMIC
Definition: utility.h:24
void ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
Definition: vacuum.c:147
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3702
void UserAbortTransactionBlock(bool chain)
Definition: xact.c:4196
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3984
void RequireTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3708
void DefineSavepoint(const char *name)
Definition: xact.c:4365
void ReleaseSavepoint(const char *name)
Definition: xact.c:4450
bool IsTransactionBlock(void)
Definition: xact.c:4963
void BeginTransactionBlock(void)
Definition: xact.c:3916
void RollbackToSavepoint(const char *name)
Definition: xact.c:4559
bool EndTransactionBlock(bool chain)
Definition: xact.c:4036
#define CHECKPOINT_FORCE
Definition: xlog.h:142
#define CHECKPOINT_WAIT
Definition: xlog.h:145
#define CHECKPOINT_IMMEDIATE
Definition: xlog.h:141

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseRefreshColl(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterSystemSetConfigFile(), AlterTableSpaceOptions(), DefElem::arg, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), B_BACKEND, BeginTransactionBlock(), castNode, check_stack_depth(), CHECKPOINT_FORCE, CHECKPOINT_IMMEDIATE, CHECKPOINT_WAIT, CheckRestrictedOperation(), ClassifyUtilityCommandAsReadOnly(), closeAllVfds(), cluster(), COMMAND_IS_STRICTLY_READ_ONLY, COMMAND_OK_IN_PARALLEL_MODE, COMMAND_OK_IN_READ_ONLY_TXN, COMMAND_OK_IN_RECOVERY, CommandCounterIncrement(), CommentObject(), context, copyObject, CreateCommandTag(), createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DeallocateQuery(), DefineSavepoint(), DefElem::defname, generate_unaccent_rules::dest, DiscardCommand(), DoCopy(), DropDatabase(), DropRole(), DropTableSpace(), EndTransactionBlock(), ereport, errcode(), errdetail(), errmsg(), ERROR, EventTriggerSupportsObjectType(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteCallStmt(), ExecuteDoStmt(), ExecuteGrantStmt(), ExecuteQuery(), ExecuteTruncate(), ExecVacuum(), ExplainQuery(), FinishPreparedTransaction(), free_parsestate(), GetCommandTagName(), GetPGVariable(), GetUserId(), GrantRole(), has_privs_of_role(), IsInParallelMode(), IsTransactionBlock(), lfirst, list_make1, load_file(), LockTableCommand(), make_parsestate(), MyBackendType, VariableShowStmt::name, nodeTag, ParseState::p_queryEnv, ParseState::p_sourcetext, PerformCursorOpen(), PerformPortalClose(), PerformPortalFetch(), PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventCommandIfParallelMode(), PreventCommandIfReadOnly(), PreventInTransactionBlock(), PROCESS_UTILITY_QUERY_NONATOMIC, PROCESS_UTILITY_TOPLEVEL, ProcessUtilitySlow(), ReassignOwnedObjects(), RecoveryInProgress(), ReleaseSavepoint(), RequestCheckpoint(), RequireTransactionBlock(), RollbackToSavepoint(), SetPGVariable(), SetQueryCompletion(), stmt, PlannedStmt::stmt_len, PlannedStmt::stmt_location, superuser(), TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, UserAbortTransactionBlock(), PlannedStmt::utilityStmt, WarnNoTransactionBlock(), and XactReadOnly.

Referenced by pgss_ProcessUtility(), ProcessUtility(), REGRESS_utility_command(), and sepgsql_utility_command().

◆ UtilityContainsQuery()

Query * UtilityContainsQuery ( Node parsetree)

Definition at line 2179 of file utility.c.

2180{
2181 Query *qry;
2182
2183 switch (nodeTag(parsetree))
2184 {
2185 case T_DeclareCursorStmt:
2186 qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
2187 if (qry->commandType == CMD_UTILITY)
2188 return UtilityContainsQuery(qry->utilityStmt);
2189 return qry;
2190
2191 case T_ExplainStmt:
2192 qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
2193 if (qry->commandType == CMD_UTILITY)
2194 return UtilityContainsQuery(qry->utilityStmt);
2195 return qry;
2196
2197 case T_CreateTableAsStmt:
2198 qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
2199 if (qry->commandType == CMD_UTILITY)
2200 return UtilityContainsQuery(qry->utilityStmt);
2201 return qry;
2202
2203 default:
2204 return NULL;
2205 }
2206}
CmdType commandType
Definition: parsenodes.h:121
Node * utilityStmt
Definition: parsenodes.h:136
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:2179

References castNode, CMD_UTILITY, Query::commandType, nodeTag, UtilityContainsQuery(), and Query::utilityStmt.

Referenced by AcquireExecutorLocks(), AcquirePlannerLocks(), extract_query_dependencies_walker(), and UtilityContainsQuery().

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

Definition at line 2028 of file utility.c.

2029{
2030 switch (nodeTag(parsetree))
2031 {
2032 case T_CallStmt:
2033 {
2034 CallStmt *stmt = (CallStmt *) parsetree;
2035
2036 return (stmt->funcexpr->funcresulttype == RECORDOID);
2037 }
2038 case T_FetchStmt:
2039 {
2040 FetchStmt *stmt = (FetchStmt *) parsetree;
2041 Portal portal;
2042
2043 if (stmt->ismove)
2044 return false;
2045 portal = GetPortalByName(stmt->portalname);
2046 if (!PortalIsValid(portal))
2047 return false; /* not our business to raise error */
2048 return portal->tupDesc ? true : false;
2049 }
2050
2051 case T_ExecuteStmt:
2052 {
2053 ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2054 PreparedStatement *entry;
2055
2056 entry = FetchPreparedStatement(stmt->name, false);
2057 if (!entry)
2058 return false; /* not our business to raise error */
2059 if (entry->plansource->resultDesc)
2060 return true;
2061 return false;
2062 }
2063
2064 case T_ExplainStmt:
2065 return true;
2066
2067 case T_VariableShowStmt:
2068 return true;
2069
2070 default:
2071 return false;
2072 }
2073}
return true
Definition: isn.c:125
#define PortalIsValid(p)
Definition: portal.h:211
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
TupleDesc resultDesc
Definition: plancache.h:108
TupleDesc tupDesc
Definition: portal.h:159
CachedPlanSource * plansource
Definition: prepare.h:31

References FetchPreparedStatement(), GetPortalByName(), nodeTag, PreparedStatement::plansource, PortalIsValid, CachedPlanSource::resultDesc, stmt, true, and PortalData::tupDesc.

Referenced by ChoosePortalStrategy().

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

Definition at line 2084 of file utility.c.

2085{
2086 switch (nodeTag(parsetree))
2087 {
2088 case T_CallStmt:
2089 return CallStmtResultDesc((CallStmt *) parsetree);
2090
2091 case T_FetchStmt:
2092 {
2093 FetchStmt *stmt = (FetchStmt *) parsetree;
2094 Portal portal;
2095
2096 if (stmt->ismove)
2097 return NULL;
2098 portal = GetPortalByName(stmt->portalname);
2099 if (!PortalIsValid(portal))
2100 return NULL; /* not our business to raise error */
2101 return CreateTupleDescCopy(portal->tupDesc);
2102 }
2103
2104 case T_ExecuteStmt:
2105 {
2106 ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2107 PreparedStatement *entry;
2108
2109 entry = FetchPreparedStatement(stmt->name, false);
2110 if (!entry)
2111 return NULL; /* not our business to raise error */
2113 }
2114
2115 case T_ExplainStmt:
2116 return ExplainResultDesc((ExplainStmt *) parsetree);
2117
2118 case T_VariableShowStmt:
2119 {
2120 VariableShowStmt *n = (VariableShowStmt *) parsetree;
2121
2122 return GetPGVariableResultDesc(n->name);
2123 }
2124
2125 default:
2126 return NULL;
2127 }
2128}
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:463
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:404
TupleDesc CallStmtResultDesc(CallStmt *stmt)
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc_funcs.c:394
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:235

References CallStmtResultDesc(), CreateTupleDescCopy(), ExplainResultDesc(), FetchPreparedStatement(), FetchPreparedStatementResultDesc(), GetPGVariableResultDesc(), GetPortalByName(), VariableShowStmt::name, nodeTag, PortalIsValid, stmt, and PortalData::tupDesc.

Referenced by PlanCacheComputeResultDesc(), and PortalStart().

Variable Documentation

◆ ProcessUtility_hook

ProcessUtility_hook_type ProcessUtility_hook = NULL

Definition at line 70 of file utility.c.

Referenced by _PG_init(), and ProcessUtility().