Branch data Line data Source code
1 : : /*-------------------------------------------------------------------------
2 : : *
3 : : * utility.c
4 : : * Contains functions which control the execution of the POSTGRES utility
5 : : * commands. At one time acted as an interface between the Lisp and C
6 : : * systems.
7 : : *
8 : : * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
9 : : * Portions Copyright (c) 1994, Regents of the University of California
10 : : *
11 : : *
12 : : * IDENTIFICATION
13 : : * src/backend/tcop/utility.c
14 : : *
15 : : *-------------------------------------------------------------------------
16 : : */
17 : : #include "postgres.h"
18 : :
19 : : #include "access/reloptions.h"
20 : : #include "access/twophase.h"
21 : : #include "access/xact.h"
22 : : #include "access/xlog.h"
23 : : #include "catalog/namespace.h"
24 : : #include "catalog/pg_authid.h"
25 : : #include "catalog/pg_inherits.h"
26 : : #include "catalog/toasting.h"
27 : : #include "commands/alter.h"
28 : : #include "commands/async.h"
29 : : #include "commands/collationcmds.h"
30 : : #include "commands/comment.h"
31 : : #include "commands/conversioncmds.h"
32 : : #include "commands/copy.h"
33 : : #include "commands/createas.h"
34 : : #include "commands/dbcommands.h"
35 : : #include "commands/defrem.h"
36 : : #include "commands/discard.h"
37 : : #include "commands/event_trigger.h"
38 : : #include "commands/explain.h"
39 : : #include "commands/extension.h"
40 : : #include "commands/lockcmds.h"
41 : : #include "commands/matview.h"
42 : : #include "commands/policy.h"
43 : : #include "commands/portalcmds.h"
44 : : #include "commands/prepare.h"
45 : : #include "commands/proclang.h"
46 : : #include "commands/publicationcmds.h"
47 : : #include "commands/repack.h"
48 : : #include "commands/schemacmds.h"
49 : : #include "commands/seclabel.h"
50 : : #include "commands/sequence.h"
51 : : #include "commands/subscriptioncmds.h"
52 : : #include "commands/tablecmds.h"
53 : : #include "commands/tablespace.h"
54 : : #include "commands/trigger.h"
55 : : #include "commands/typecmds.h"
56 : : #include "commands/user.h"
57 : : #include "commands/vacuum.h"
58 : : #include "commands/view.h"
59 : : #include "commands/wait.h"
60 : : #include "miscadmin.h"
61 : : #include "parser/parse_utilcmd.h"
62 : : #include "postmaster/bgwriter.h"
63 : : #include "rewrite/rewriteDefine.h"
64 : : #include "storage/fd.h"
65 : : #include "tcop/utility.h"
66 : : #include "utils/acl.h"
67 : : #include "utils/guc.h"
68 : : #include "utils/lsyscache.h"
69 : :
70 : : /* Hook for plugins to get control in ProcessUtility() */
71 : : ProcessUtility_hook_type ProcessUtility_hook = NULL;
72 : :
73 : : /* local function declarations */
74 : : static int ClassifyUtilityCommandAsReadOnly(Node *parsetree);
75 : : static void ProcessUtilitySlow(ParseState *pstate,
76 : : PlannedStmt *pstmt,
77 : : const char *queryString,
78 : : ProcessUtilityContext context,
79 : : ParamListInfo params,
80 : : QueryEnvironment *queryEnv,
81 : : DestReceiver *dest,
82 : : QueryCompletion *qc);
83 : : static void ExecDropStmt(DropStmt *stmt, bool isTopLevel);
84 : :
85 : : /*
86 : : * CommandIsReadOnly: is an executable query read-only?
87 : : *
88 : : * This is a much stricter test than we apply for XactReadOnly mode;
89 : : * the query must be *in truth* read-only, because the caller wishes
90 : : * not to do CommandCounterIncrement for it.
91 : : *
92 : : * Note: currently no need to support raw or analyzed queries here
93 : : */
94 : : bool
95 : 12224 : CommandIsReadOnly(PlannedStmt *pstmt)
96 : : {
97 : : Assert(IsA(pstmt, PlannedStmt));
98 [ + - - - ]: 12224 : switch (pstmt->commandType)
99 : : {
100 : 12224 : case CMD_SELECT:
101 [ - + ]: 12224 : if (pstmt->rowMarks != NIL)
102 : 0 : return false; /* SELECT FOR [KEY] UPDATE/SHARE */
103 [ - + ]: 12224 : else if (pstmt->hasModifyingCTE)
104 : 0 : return false; /* data-modifying CTE */
105 : : else
106 : 12224 : return true;
107 : 0 : case CMD_UPDATE:
108 : : case CMD_INSERT:
109 : : case CMD_DELETE:
110 : : case CMD_MERGE:
111 : 0 : return false;
112 : 0 : case CMD_UTILITY:
113 : : /* For now, treat all utility commands as read/write */
114 : 0 : return false;
115 : 0 : default:
116 [ # # ]: 0 : elog(WARNING, "unrecognized commandType: %d",
117 : : (int) pstmt->commandType);
118 : 0 : break;
119 : : }
120 : 0 : return false;
121 : : }
122 : :
123 : : /*
124 : : * Determine the degree to which a utility command is read only.
125 : : *
126 : : * Note the definitions of the relevant flags in src/include/tcop/utility.h.
127 : : */
128 : : static int
129 : 262328 : ClassifyUtilityCommandAsReadOnly(Node *parsetree)
130 : : {
131 [ + + + + : 262328 : switch (nodeTag(parsetree))
+ + + + +
+ + - ]
132 : : {
133 : 153234 : case T_AlterCollationStmt:
134 : : case T_AlterDatabaseRefreshCollStmt:
135 : : case T_AlterDatabaseSetStmt:
136 : : case T_AlterDatabaseStmt:
137 : : case T_AlterDefaultPrivilegesStmt:
138 : : case T_AlterDomainStmt:
139 : : case T_AlterEnumStmt:
140 : : case T_AlterEventTrigStmt:
141 : : case T_AlterExtensionContentsStmt:
142 : : case T_AlterExtensionStmt:
143 : : case T_AlterFdwStmt:
144 : : case T_AlterForeignServerStmt:
145 : : case T_AlterFunctionStmt:
146 : : case T_AlterObjectDependsStmt:
147 : : case T_AlterObjectSchemaStmt:
148 : : case T_AlterOpFamilyStmt:
149 : : case T_AlterOperatorStmt:
150 : : case T_AlterOwnerStmt:
151 : : case T_AlterPolicyStmt:
152 : : case T_AlterPublicationStmt:
153 : : case T_AlterRoleSetStmt:
154 : : case T_AlterRoleStmt:
155 : : case T_AlterSeqStmt:
156 : : case T_AlterStatsStmt:
157 : : case T_AlterSubscriptionStmt:
158 : : case T_AlterTSConfigurationStmt:
159 : : case T_AlterTSDictionaryStmt:
160 : : case T_AlterTableMoveAllStmt:
161 : : case T_AlterTableSpaceOptionsStmt:
162 : : case T_AlterTableStmt:
163 : : case T_AlterTypeStmt:
164 : : case T_AlterUserMappingStmt:
165 : : case T_CommentStmt:
166 : : case T_CompositeTypeStmt:
167 : : case T_CreateAmStmt:
168 : : case T_CreateCastStmt:
169 : : case T_CreateConversionStmt:
170 : : case T_CreateDomainStmt:
171 : : case T_CreateEnumStmt:
172 : : case T_CreateEventTrigStmt:
173 : : case T_CreateExtensionStmt:
174 : : case T_CreateFdwStmt:
175 : : case T_CreateForeignServerStmt:
176 : : case T_CreateForeignTableStmt:
177 : : case T_CreateFunctionStmt:
178 : : case T_CreateOpClassStmt:
179 : : case T_CreateOpFamilyStmt:
180 : : case T_CreatePLangStmt:
181 : : case T_CreatePolicyStmt:
182 : : case T_CreatePublicationStmt:
183 : : case T_CreateRangeStmt:
184 : : case T_CreateRoleStmt:
185 : : case T_CreateSchemaStmt:
186 : : case T_CreateSeqStmt:
187 : : case T_CreateStatsStmt:
188 : : case T_CreateStmt:
189 : : case T_CreateSubscriptionStmt:
190 : : case T_CreateTableAsStmt:
191 : : case T_CreateTableSpaceStmt:
192 : : case T_CreateTransformStmt:
193 : : case T_CreateTrigStmt:
194 : : case T_CreateUserMappingStmt:
195 : : case T_CreatedbStmt:
196 : : case T_DefineStmt:
197 : : case T_DropOwnedStmt:
198 : : case T_DropRoleStmt:
199 : : case T_DropStmt:
200 : : case T_DropSubscriptionStmt:
201 : : case T_DropTableSpaceStmt:
202 : : case T_DropUserMappingStmt:
203 : : case T_DropdbStmt:
204 : : case T_GrantRoleStmt:
205 : : case T_GrantStmt:
206 : : case T_ImportForeignSchemaStmt:
207 : : case T_IndexStmt:
208 : : case T_ReassignOwnedStmt:
209 : : case T_RefreshMatViewStmt:
210 : : case T_RenameStmt:
211 : : case T_RuleStmt:
212 : : case T_SecLabelStmt:
213 : : case T_TruncateStmt:
214 : : case T_ViewStmt:
215 : : {
216 : : /* DDL is not read-only, and neither is TRUNCATE. */
217 : 153234 : return COMMAND_IS_NOT_READ_ONLY;
218 : : }
219 : :
220 : 130 : case T_AlterSystemStmt:
221 : : {
222 : : /*
223 : : * Surprisingly, ALTER SYSTEM meets all our definitions of
224 : : * read-only: it changes nothing that affects the output of
225 : : * pg_dump, it doesn't write WAL or imperil the application of
226 : : * future WAL, and it doesn't depend on any state that needs
227 : : * to be synchronized with parallel workers.
228 : : *
229 : : * So, despite the fact that it writes to a file, it's read
230 : : * only!
231 : : */
232 : 130 : return COMMAND_IS_STRICTLY_READ_ONLY;
233 : : }
234 : :
235 : 1221 : case T_CallStmt:
236 : : case T_DoStmt:
237 : : {
238 : : /*
239 : : * Commands inside the DO block or the called procedure might
240 : : * not be read only, but they'll be checked separately when we
241 : : * try to execute them. Here we only need to worry about the
242 : : * DO or CALL command itself.
243 : : */
244 : 1221 : return COMMAND_IS_STRICTLY_READ_ONLY;
245 : : }
246 : :
247 : 478 : case T_CheckPointStmt:
248 : : {
249 : : /*
250 : : * You might think that this should not be permitted in
251 : : * recovery, but we interpret a CHECKPOINT command during
252 : : * recovery as a request for a restartpoint instead. We allow
253 : : * this since it can be a useful way of reducing switchover
254 : : * time when using various forms of replication.
255 : : */
256 : 478 : return COMMAND_IS_STRICTLY_READ_ONLY;
257 : : }
258 : :
259 : 45546 : case T_ClosePortalStmt:
260 : : case T_ConstraintsSetStmt:
261 : : case T_DeallocateStmt:
262 : : case T_DeclareCursorStmt:
263 : : case T_DiscardStmt:
264 : : case T_ExecuteStmt:
265 : : case T_FetchStmt:
266 : : case T_LoadStmt:
267 : : case T_PrepareStmt:
268 : : case T_UnlistenStmt:
269 : : case T_VariableSetStmt:
270 : : case T_WaitStmt:
271 : : {
272 : : /*
273 : : * These modify only backend-local state, so they're OK to run
274 : : * in a read-only transaction or on a standby. However, they
275 : : * are disallowed in parallel mode, because they either rely
276 : : * upon or modify backend-local state that might not be
277 : : * synchronized among cooperating backends.
278 : : */
279 : 45546 : return COMMAND_OK_IN_RECOVERY | COMMAND_OK_IN_READ_ONLY_TXN;
280 : : }
281 : :
282 : 9702 : case T_ReindexStmt:
283 : : case T_VacuumStmt:
284 : : case T_RepackStmt:
285 : : {
286 : : /*
287 : : * These commands write WAL, so they're not strictly
288 : : * read-only, and running them in parallel workers isn't
289 : : * supported.
290 : : *
291 : : * However, they don't change the database state in a way that
292 : : * would affect pg_dump output, so it's fine to run them in a
293 : : * read-only transaction. (REPACK/CLUSTER might change the
294 : : * order of rows on disk, which could affect the ordering of
295 : : * pg_dump output, but that's not semantically significant.)
296 : : */
297 : 9702 : return COMMAND_OK_IN_READ_ONLY_TXN;
298 : : }
299 : :
300 : 6567 : case T_CopyStmt:
301 : : {
302 : 6567 : CopyStmt *stmt = (CopyStmt *) parsetree;
303 : :
304 : : /*
305 : : * You might think that COPY FROM is not at all read only, but
306 : : * it's OK to copy into a temporary table, because that
307 : : * wouldn't change the output of pg_dump. If the target table
308 : : * turns out to be non-temporary, DoCopy itself will call
309 : : * PreventCommandIfReadOnly.
310 : : */
311 [ + + ]: 6567 : if (stmt->is_from)
312 : 1252 : return COMMAND_OK_IN_READ_ONLY_TXN;
313 : : else
314 : 5315 : return COMMAND_IS_STRICTLY_READ_ONLY;
315 : : }
316 : :
317 : 17654 : case T_ExplainStmt:
318 : : case T_VariableShowStmt:
319 : : {
320 : : /*
321 : : * These commands don't modify any data and are safe to run in
322 : : * a parallel worker.
323 : : */
324 : 17654 : return COMMAND_IS_STRICTLY_READ_ONLY;
325 : : }
326 : :
327 : 114 : case T_ListenStmt:
328 : : case T_NotifyStmt:
329 : : {
330 : : /*
331 : : * NOTIFY requires an XID assignment, so it can't be permitted
332 : : * on a standby. Perhaps LISTEN could, since without NOTIFY it
333 : : * would be OK to just do nothing, at least until promotion,
334 : : * but we currently prohibit it lest the user get the wrong
335 : : * idea.
336 : : *
337 : : * (We do allow T_UnlistenStmt on a standby, though, because
338 : : * it's a no-op.)
339 : : */
340 : 114 : return COMMAND_OK_IN_READ_ONLY_TXN;
341 : : }
342 : :
343 : 600 : case T_LockStmt:
344 : : {
345 : 600 : LockStmt *stmt = (LockStmt *) parsetree;
346 : :
347 : : /*
348 : : * Only weaker locker modes are allowed during recovery. The
349 : : * restrictions here must match those in
350 : : * LockAcquireExtended().
351 : : */
352 [ + + ]: 600 : if (stmt->mode > RowExclusiveLock)
353 : 298 : return COMMAND_OK_IN_READ_ONLY_TXN;
354 : : else
355 : 302 : return COMMAND_IS_STRICTLY_READ_ONLY;
356 : : }
357 : :
358 : 27082 : case T_TransactionStmt:
359 : : {
360 : 27082 : TransactionStmt *stmt = (TransactionStmt *) parsetree;
361 : :
362 : : /*
363 : : * PREPARE, COMMIT PREPARED, and ROLLBACK PREPARED all write
364 : : * WAL, so they're not read-only in the strict sense; but the
365 : : * first and third do not change pg_dump output, so they're OK
366 : : * in a read-only transactions.
367 : : *
368 : : * We also consider COMMIT PREPARED to be OK in a read-only
369 : : * transaction environment, by way of exception.
370 : : */
371 [ + + - ]: 27082 : switch (stmt->kind)
372 : : {
373 : 26397 : case TRANS_STMT_BEGIN:
374 : : case TRANS_STMT_START:
375 : : case TRANS_STMT_COMMIT:
376 : : case TRANS_STMT_ROLLBACK:
377 : : case TRANS_STMT_SAVEPOINT:
378 : : case TRANS_STMT_RELEASE:
379 : : case TRANS_STMT_ROLLBACK_TO:
380 : 26397 : return COMMAND_IS_STRICTLY_READ_ONLY;
381 : :
382 : 685 : case TRANS_STMT_PREPARE:
383 : : case TRANS_STMT_COMMIT_PREPARED:
384 : : case TRANS_STMT_ROLLBACK_PREPARED:
385 : 685 : return COMMAND_OK_IN_READ_ONLY_TXN;
386 : : }
387 [ # # ]: 0 : elog(ERROR, "unrecognized TransactionStmtKind: %d",
388 : : (int) stmt->kind);
389 : : return 0; /* silence stupider compilers */
390 : : }
391 : :
392 : 0 : default:
393 [ # # ]: 0 : elog(ERROR, "unrecognized node type: %d",
394 : : (int) nodeTag(parsetree));
395 : : return 0; /* silence stupider compilers */
396 : : }
397 : : }
398 : :
399 : : /*
400 : : * PreventCommandIfReadOnly: throw error if XactReadOnly
401 : : *
402 : : * This is useful partly to ensure consistency of the error message wording;
403 : : * some callers have checked XactReadOnly for themselves.
404 : : */
405 : : void
406 : 193757 : PreventCommandIfReadOnly(const char *cmdname)
407 : : {
408 [ + + ]: 193757 : if (XactReadOnly)
409 [ + - ]: 74 : ereport(ERROR,
410 : : (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
411 : : /* translator: %s is name of a SQL command, eg CREATE */
412 : : errmsg("cannot execute %s in a read-only transaction",
413 : : cmdname)));
414 : 193683 : }
415 : :
416 : : /*
417 : : * PreventCommandIfParallelMode: throw error if current (sub)transaction is
418 : : * in parallel mode.
419 : : *
420 : : * This is useful partly to ensure consistency of the error message wording;
421 : : * some callers have checked IsInParallelMode() for themselves.
422 : : */
423 : : void
424 : 283282 : PreventCommandIfParallelMode(const char *cmdname)
425 : : {
426 [ - + ]: 283282 : if (IsInParallelMode())
427 [ # # ]: 0 : ereport(ERROR,
428 : : (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
429 : : /* translator: %s is name of a SQL command, eg CREATE */
430 : : errmsg("cannot execute %s during a parallel operation",
431 : : cmdname)));
432 : 283282 : }
433 : :
434 : : /*
435 : : * PreventCommandDuringRecovery: throw error if RecoveryInProgress
436 : : *
437 : : * The majority of operations that are unsafe in a Hot Standby
438 : : * will be rejected by XactReadOnly tests. However there are a few
439 : : * commands that are allowed in "read-only" xacts but cannot be allowed
440 : : * in Hot Standby mode. Those commands should call this function.
441 : : */
442 : : void
443 : 4313 : PreventCommandDuringRecovery(const char *cmdname)
444 : : {
445 [ - + ]: 4313 : if (RecoveryInProgress())
446 [ # # ]: 0 : ereport(ERROR,
447 : : (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
448 : : /* translator: %s is name of a SQL command, eg CREATE */
449 : : errmsg("cannot execute %s during recovery",
450 : : cmdname)));
451 : 4313 : }
452 : :
453 : : /*
454 : : * CheckRestrictedOperation: throw error for hazardous command if we're
455 : : * inside a security restriction context.
456 : : *
457 : : * This is needed to protect session-local state for which there is not any
458 : : * better-defined protection mechanism, such as ownership.
459 : : */
460 : : static void
461 : 4589 : CheckRestrictedOperation(const char *cmdname)
462 : : {
463 [ - + ]: 4589 : if (InSecurityRestrictedOperation())
464 [ # # ]: 0 : ereport(ERROR,
465 : : (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
466 : : /* translator: %s is name of a SQL command, eg PREPARE */
467 : : errmsg("cannot execute %s within security-restricted operation",
468 : : cmdname)));
469 : 4589 : }
470 : :
471 : : /*
472 : : * ProcessUtility
473 : : * general utility function invoker
474 : : *
475 : : * pstmt: PlannedStmt wrapper for the utility statement
476 : : * queryString: original source text of command
477 : : * readOnlyTree: if true, pstmt's node tree must not be modified
478 : : * context: identifies source of statement (toplevel client command,
479 : : * non-toplevel client command, subcommand of a larger utility command)
480 : : * params: parameters to use during execution
481 : : * queryEnv: environment for parse through execution (e.g., ephemeral named
482 : : * tables like trigger transition tables). May be NULL.
483 : : * dest: where to send results
484 : : * qc: where to store command completion status data. May be NULL,
485 : : * but if not, then caller must have initialized it.
486 : : *
487 : : * Caller MUST supply a queryString; it is not allowed (anymore) to pass NULL.
488 : : * If you really don't have source text, you can pass a constant string,
489 : : * perhaps "(query not available)".
490 : : *
491 : : * Note for users of ProcessUtility_hook: the same queryString may be passed
492 : : * to multiple invocations of ProcessUtility when processing a query string
493 : : * containing multiple semicolon-separated statements. One should use
494 : : * pstmt->stmt_location and pstmt->stmt_len to identify the substring
495 : : * containing the current statement. Keep in mind also that some utility
496 : : * statements (e.g., CREATE SCHEMA) will recurse to ProcessUtility to process
497 : : * sub-statements, often passing down the same queryString, stmt_location,
498 : : * and stmt_len that were given for the whole statement.
499 : : */
500 : : void
501 : 262328 : ProcessUtility(PlannedStmt *pstmt,
502 : : const char *queryString,
503 : : bool readOnlyTree,
504 : : ProcessUtilityContext context,
505 : : ParamListInfo params,
506 : : QueryEnvironment *queryEnv,
507 : : DestReceiver *dest,
508 : : QueryCompletion *qc)
509 : : {
510 : : Assert(IsA(pstmt, PlannedStmt));
511 : : Assert(pstmt->commandType == CMD_UTILITY);
512 : : Assert(queryString != NULL); /* required as of 8.4 */
513 : : Assert(qc == NULL || qc->commandTag == CMDTAG_UNKNOWN);
514 : :
515 : : /*
516 : : * We provide a function hook variable that lets loadable plugins get
517 : : * control when ProcessUtility is called. Such a plugin would normally
518 : : * call standard_ProcessUtility().
519 : : */
520 [ + + ]: 262328 : if (ProcessUtility_hook)
521 : 37349 : (*ProcessUtility_hook) (pstmt, queryString, readOnlyTree,
522 : : context, params, queryEnv,
523 : : dest, qc);
524 : : else
525 : 224979 : standard_ProcessUtility(pstmt, queryString, readOnlyTree,
526 : : context, params, queryEnv,
527 : : dest, qc);
528 : 250499 : }
529 : :
530 : : /*
531 : : * standard_ProcessUtility itself deals only with utility commands for
532 : : * which we do not provide event trigger support. Commands that do have
533 : : * such support are passed down to ProcessUtilitySlow, which contains the
534 : : * necessary infrastructure for such triggers.
535 : : *
536 : : * This division is not just for performance: it's critical that the
537 : : * event trigger code not be invoked when doing START TRANSACTION for
538 : : * example, because we might need to refresh the event trigger cache,
539 : : * which requires being in a valid transaction.
540 : : *
541 : : * When adding or moving utility commands, check that the documentation in
542 : : * event-trigger.sgml is kept up to date.
543 : : */
544 : : void
545 : 262328 : standard_ProcessUtility(PlannedStmt *pstmt,
546 : : const char *queryString,
547 : : bool readOnlyTree,
548 : : ProcessUtilityContext context,
549 : : ParamListInfo params,
550 : : QueryEnvironment *queryEnv,
551 : : DestReceiver *dest,
552 : : QueryCompletion *qc)
553 : : {
554 : : Node *parsetree;
555 : 262328 : bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
556 [ + + + + : 262328 : bool isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
+ + ]
557 : : ParseState *pstate;
558 : : int readonly_flags;
559 : :
560 : : /* This can recurse, so check for excessive recursion */
561 : 262328 : check_stack_depth();
562 : :
563 : : /*
564 : : * If the given node tree is read-only, make a copy to ensure that parse
565 : : * transformations don't damage the original tree. This could be
566 : : * refactored to avoid making unnecessary copies in more cases, but it's
567 : : * not clear that it's worth a great deal of trouble over. Statements
568 : : * that are complex enough to be expensive to copy are exactly the ones
569 : : * we'd need to copy, so that only marginal savings seem possible.
570 : : */
571 [ + + ]: 262328 : if (readOnlyTree)
572 : 19717 : pstmt = copyObject(pstmt);
573 : 262328 : parsetree = pstmt->utilityStmt;
574 : :
575 : : /* Prohibit read/write commands in read-only states. */
576 : 262328 : readonly_flags = ClassifyUtilityCommandAsReadOnly(parsetree);
577 [ + + ]: 262328 : if (readonly_flags != COMMAND_IS_STRICTLY_READ_ONLY &&
578 [ + + - + ]: 210831 : (XactReadOnly || IsInParallelMode()))
579 : : {
580 : 9145 : CommandTag commandtag = CreateCommandTag(parsetree);
581 : :
582 [ + + ]: 9145 : if ((readonly_flags & COMMAND_OK_IN_READ_ONLY_TXN) == 0)
583 : 8 : PreventCommandIfReadOnly(GetCommandTagName(commandtag));
584 [ + - ]: 9137 : if ((readonly_flags & COMMAND_OK_IN_PARALLEL_MODE) == 0)
585 : 9137 : PreventCommandIfParallelMode(GetCommandTagName(commandtag));
586 [ - + ]: 9137 : if ((readonly_flags & COMMAND_OK_IN_RECOVERY) == 0)
587 : 0 : PreventCommandDuringRecovery(GetCommandTagName(commandtag));
588 : : }
589 : :
590 : 262320 : pstate = make_parsestate(NULL);
591 : 262320 : pstate->p_sourcetext = queryString;
592 : 262320 : pstate->p_queryEnv = queryEnv;
593 : :
594 [ + + + + : 262320 : switch (nodeTag(parsetree))
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + ]
595 : : {
596 : : /*
597 : : * ******************** transactions ********************
598 : : */
599 : 27082 : case T_TransactionStmt:
600 : : {
601 : 27082 : TransactionStmt *stmt = (TransactionStmt *) parsetree;
602 : :
603 [ + + + + : 27082 : switch (stmt->kind)
+ + + + +
- ]
604 : : {
605 : : /*
606 : : * START TRANSACTION, as defined by SQL99: Identical
607 : : * to BEGIN. Same code for both.
608 : : */
609 : 12544 : case TRANS_STMT_BEGIN:
610 : : case TRANS_STMT_START:
611 : : {
612 : : ListCell *lc;
613 : :
614 : 12544 : BeginTransactionBlock();
615 [ + + + + : 16543 : foreach(lc, stmt->options)
+ + ]
616 : : {
617 : 3999 : DefElem *item = (DefElem *) lfirst(lc);
618 : :
619 [ + + ]: 3999 : if (strcmp(item->defname, "transaction_isolation") == 0)
620 : 3444 : SetPGVariable("transaction_isolation",
621 : 3444 : list_make1(item->arg),
622 : : true);
623 [ + + ]: 555 : else if (strcmp(item->defname, "transaction_read_only") == 0)
624 : 521 : SetPGVariable("transaction_read_only",
625 : 521 : list_make1(item->arg),
626 : : true);
627 [ + - ]: 34 : else if (strcmp(item->defname, "transaction_deferrable") == 0)
628 : 34 : SetPGVariable("transaction_deferrable",
629 : 34 : list_make1(item->arg),
630 : : true);
631 : : }
632 : : }
633 : 12544 : break;
634 : :
635 : 9703 : case TRANS_STMT_COMMIT:
636 [ + + ]: 9703 : if (!EndTransactionBlock(stmt->chain))
637 : : {
638 : : /* report unsuccessful commit in qc */
639 [ + - ]: 479 : if (qc)
640 : 479 : SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
641 : : }
642 : 9683 : break;
643 : :
644 : 368 : case TRANS_STMT_PREPARE:
645 [ + + ]: 368 : if (!PrepareTransactionBlock(stmt->gid))
646 : : {
647 : : /* report unsuccessful commit in qc */
648 [ + - ]: 2 : if (qc)
649 : 2 : SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
650 : : }
651 : 368 : break;
652 : :
653 : 266 : case TRANS_STMT_COMMIT_PREPARED:
654 : 266 : PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
655 : 266 : FinishPreparedTransaction(stmt->gid, true);
656 : 256 : break;
657 : :
658 : 51 : case TRANS_STMT_ROLLBACK_PREPARED:
659 : 51 : PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
660 : 51 : FinishPreparedTransaction(stmt->gid, false);
661 : 47 : break;
662 : :
663 : 2273 : case TRANS_STMT_ROLLBACK:
664 : 2273 : UserAbortTransactionBlock(stmt->chain);
665 : 2253 : break;
666 : :
667 : 1181 : case TRANS_STMT_SAVEPOINT:
668 : 1181 : RequireTransactionBlock(isTopLevel, "SAVEPOINT");
669 : 1172 : DefineSavepoint(stmt->savepoint_name);
670 : 1164 : break;
671 : :
672 : 190 : case TRANS_STMT_RELEASE:
673 : 190 : RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
674 : 186 : ReleaseSavepoint(stmt->savepoint_name);
675 : 182 : break;
676 : :
677 : 506 : case TRANS_STMT_ROLLBACK_TO:
678 : 506 : RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
679 : 502 : RollbackToSavepoint(stmt->savepoint_name);
680 : :
681 : : /*
682 : : * CommitTransactionCommand is in charge of
683 : : * re-defining the savepoint again
684 : : */
685 : 494 : break;
686 : : }
687 : : }
688 : 26991 : break;
689 : :
690 : : /*
691 : : * Portal (cursor) manipulation
692 : : */
693 : 2720 : case T_DeclareCursorStmt:
694 : 2720 : PerformCursorOpen(pstate, (DeclareCursorStmt *) parsetree, params,
695 : : isTopLevel);
696 : 2711 : break;
697 : :
698 : 1238 : case T_ClosePortalStmt:
699 : : {
700 : 1238 : ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
701 : :
702 : 1238 : CheckRestrictedOperation("CLOSE");
703 : 1238 : PerformPortalClose(stmt->portalname);
704 : : }
705 : 1236 : break;
706 : :
707 : 4503 : case T_FetchStmt:
708 : 4503 : PerformPortalFetch((FetchStmt *) parsetree, dest, qc);
709 : 4429 : break;
710 : :
711 : 932 : case T_DoStmt:
712 : 932 : ExecuteDoStmt(pstate, (DoStmt *) parsetree, isAtomicContext);
713 : 688 : break;
714 : :
715 : 82 : case T_CreateTableSpaceStmt:
716 : : /* no event triggers for global objects */
717 : 82 : PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
718 : 82 : CreateTableSpace((CreateTableSpaceStmt *) parsetree);
719 : 62 : break;
720 : :
721 : 49 : case T_DropTableSpaceStmt:
722 : : /* no event triggers for global objects */
723 : 49 : PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
724 : 49 : DropTableSpace((DropTableSpaceStmt *) parsetree);
725 : 35 : break;
726 : :
727 : 19 : case T_AlterTableSpaceOptionsStmt:
728 : : /* no event triggers for global objects */
729 : 19 : AlterTableSpaceOptions((AlterTableSpaceOptionsStmt *) parsetree);
730 : 11 : break;
731 : :
732 : 1182 : case T_TruncateStmt:
733 : 1182 : ExecuteTruncate((TruncateStmt *) parsetree);
734 : 1093 : break;
735 : :
736 : 6567 : case T_CopyStmt:
737 : : {
738 : : uint64 processed;
739 : :
740 : 6567 : DoCopy(pstate, (CopyStmt *) parsetree,
741 : : pstmt->stmt_location, pstmt->stmt_len,
742 : : &processed);
743 [ + - ]: 5818 : if (qc)
744 : 5818 : SetQueryCompletion(qc, CMDTAG_COPY, processed);
745 : : }
746 : 5818 : break;
747 : :
748 : 1124 : case T_PrepareStmt:
749 : 1124 : CheckRestrictedOperation("PREPARE");
750 : 1124 : PrepareQuery(pstate, (PrepareStmt *) parsetree,
751 : : pstmt->stmt_location, pstmt->stmt_len);
752 : 1116 : break;
753 : :
754 : 8441 : case T_ExecuteStmt:
755 : 8441 : ExecuteQuery(pstate,
756 : : (ExecuteStmt *) parsetree, NULL,
757 : : params,
758 : : dest, qc);
759 : 8372 : break;
760 : :
761 : 2089 : case T_DeallocateStmt:
762 : 2089 : CheckRestrictedOperation("DEALLOCATE");
763 : 2089 : DeallocateQuery((DeallocateStmt *) parsetree);
764 : 2089 : break;
765 : :
766 : 434 : case T_GrantRoleStmt:
767 : : /* no event triggers for global objects */
768 : 434 : GrantRole(pstate, (GrantRoleStmt *) parsetree);
769 : 344 : break;
770 : :
771 : 459 : case T_CreatedbStmt:
772 : : /* no event triggers for global objects */
773 : 459 : PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
774 : 459 : createdb(pstate, (CreatedbStmt *) parsetree);
775 : 433 : break;
776 : :
777 : 53 : case T_AlterDatabaseStmt:
778 : : /* no event triggers for global objects */
779 : 53 : AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
780 : 52 : break;
781 : :
782 : 4 : case T_AlterDatabaseRefreshCollStmt:
783 : : /* no event triggers for global objects */
784 : 4 : AlterDatabaseRefreshColl((AlterDatabaseRefreshCollStmt *) parsetree);
785 : 4 : break;
786 : :
787 : 688 : case T_AlterDatabaseSetStmt:
788 : : /* no event triggers for global objects */
789 : 688 : AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
790 : 686 : break;
791 : :
792 : 82 : case T_DropdbStmt:
793 : : /* no event triggers for global objects */
794 : 82 : PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
795 : 82 : DropDatabase(pstate, (DropdbStmt *) parsetree);
796 : 69 : break;
797 : :
798 : : /* Query-level asynchronous notification */
799 : 62 : case T_NotifyStmt:
800 : : {
801 : 62 : NotifyStmt *stmt = (NotifyStmt *) parsetree;
802 : :
803 : 62 : Async_Notify(stmt->conditionname, stmt->payload);
804 : : }
805 : 62 : break;
806 : :
807 : 52 : case T_ListenStmt:
808 : : {
809 : 52 : ListenStmt *stmt = (ListenStmt *) parsetree;
810 : :
811 : 52 : CheckRestrictedOperation("LISTEN");
812 : :
813 : : /*
814 : : * We don't allow LISTEN in background processes, as there is
815 : : * no mechanism for them to collect NOTIFY messages, so they'd
816 : : * just block cleanout of the async SLRU indefinitely.
817 : : * (Authors of custom background workers could bypass this
818 : : * restriction by calling Async_Listen directly, but then it's
819 : : * on them to provide some mechanism to process the message
820 : : * queue.) Note there seems no reason to forbid UNLISTEN.
821 : : */
822 [ - + ]: 52 : if (MyBackendType != B_BACKEND)
823 [ # # ]: 0 : ereport(ERROR,
824 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
825 : : /* translator: %s is name of a SQL command, eg LISTEN */
826 : : errmsg("cannot execute %s within a background process",
827 : : "LISTEN")));
828 : :
829 : 52 : Async_Listen(stmt->conditionname);
830 : : }
831 : 52 : break;
832 : :
833 : 62 : case T_UnlistenStmt:
834 : : {
835 : 62 : UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
836 : :
837 : 62 : CheckRestrictedOperation("UNLISTEN");
838 [ + + ]: 62 : if (stmt->conditionname)
839 : 4 : Async_Unlisten(stmt->conditionname);
840 : : else
841 : 58 : Async_UnlistenAll();
842 : : }
843 : 62 : break;
844 : :
845 : 50 : case T_LoadStmt:
846 : : {
847 : 50 : LoadStmt *stmt = (LoadStmt *) parsetree;
848 : :
849 : 50 : closeAllVfds(); /* probably not necessary... */
850 : : /* Allowed names are restricted if you're not superuser */
851 : 50 : load_file(stmt->filename, !superuser());
852 : : }
853 : 50 : break;
854 : :
855 : 289 : case T_CallStmt:
856 : 289 : ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
857 : 264 : break;
858 : :
859 : 8724 : case T_VacuumStmt:
860 : 8724 : ExecVacuum(pstate, (VacuumStmt *) parsetree, isTopLevel);
861 : 8590 : break;
862 : :
863 : 269 : case T_RepackStmt:
864 : 269 : ExecRepack(pstate, (RepackStmt *) parsetree, isTopLevel);
865 : 198 : break;
866 : :
867 : 17091 : case T_ExplainStmt:
868 : 17091 : ExplainQuery(pstate, (ExplainStmt *) parsetree, params, dest);
869 : 17005 : break;
870 : :
871 : 130 : case T_AlterSystemStmt:
872 : 130 : PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
873 : 130 : AlterSystemSetConfigFile((AlterSystemStmt *) parsetree);
874 : 96 : break;
875 : :
876 : 24933 : case T_VariableSetStmt:
877 : 24933 : ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
878 : 24731 : break;
879 : :
880 : 563 : case T_VariableShowStmt:
881 : : {
882 : 563 : VariableShowStmt *n = (VariableShowStmt *) parsetree;
883 : :
884 : 563 : GetPGVariable(n->name, dest);
885 : : }
886 : 563 : break;
887 : :
888 : 24 : case T_DiscardStmt:
889 : : /* should we allow DISCARD PLANS? */
890 : 24 : CheckRestrictedOperation("DISCARD");
891 : 24 : DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
892 : 24 : break;
893 : :
894 : 129 : case T_CreateEventTrigStmt:
895 : : /* no event triggers on event triggers */
896 : 129 : CreateEventTrigger((CreateEventTrigStmt *) parsetree);
897 : 85 : break;
898 : :
899 : 32 : case T_AlterEventTrigStmt:
900 : : /* no event triggers on event triggers */
901 : 32 : AlterEventTrigger((AlterEventTrigStmt *) parsetree);
902 : 32 : break;
903 : :
904 : : /*
905 : : * ******************************** ROLE statements ****
906 : : */
907 : 1291 : case T_CreateRoleStmt:
908 : : /* no event triggers for global objects */
909 : 1291 : CreateRole(pstate, (CreateRoleStmt *) parsetree);
910 : 1201 : break;
911 : :
912 : 294 : case T_AlterRoleStmt:
913 : : /* no event triggers for global objects */
914 : 294 : AlterRole(pstate, (AlterRoleStmt *) parsetree);
915 : 234 : break;
916 : :
917 : 52 : case T_AlterRoleSetStmt:
918 : : /* no event triggers for global objects */
919 : 52 : AlterRoleSet((AlterRoleSetStmt *) parsetree);
920 : 46 : break;
921 : :
922 : 1203 : case T_DropRoleStmt:
923 : : /* no event triggers for global objects */
924 : 1203 : DropRole((DropRoleStmt *) parsetree);
925 : 1048 : break;
926 : :
927 : 39 : case T_ReassignOwnedStmt:
928 : : /* no event triggers for global objects */
929 : 39 : ReassignOwnedObjects((ReassignOwnedStmt *) parsetree);
930 : 27 : break;
931 : :
932 : 600 : case T_LockStmt:
933 : :
934 : : /*
935 : : * Since the lock would just get dropped immediately, LOCK TABLE
936 : : * outside a transaction block is presumed to be user error.
937 : : */
938 : 600 : RequireTransactionBlock(isTopLevel, "LOCK TABLE");
939 : 595 : LockTableCommand((LockStmt *) parsetree);
940 : 548 : break;
941 : :
942 : 71 : case T_ConstraintsSetStmt:
943 : 71 : WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
944 : 71 : AfterTriggerSetState((ConstraintsSetStmt *) parsetree);
945 : 61 : break;
946 : :
947 : 478 : case T_CheckPointStmt:
948 : 478 : ExecCheckpoint(pstate, (CheckPointStmt *) parsetree);
949 : 470 : break;
950 : :
951 : : /*
952 : : * The following statements are supported by Event Triggers only
953 : : * in some cases, so we "fast path" them in the other cases.
954 : : */
955 : :
956 : 12404 : case T_GrantStmt:
957 : : {
958 : 12404 : GrantStmt *stmt = (GrantStmt *) parsetree;
959 : :
960 [ + + ]: 12404 : if (EventTriggerSupportsObjectType(stmt->objtype))
961 : 12139 : ProcessUtilitySlow(pstate, pstmt, queryString,
962 : : context, params, queryEnv,
963 : : dest, qc);
964 : : else
965 : 265 : ExecuteGrantStmt(stmt);
966 : : }
967 : 12312 : break;
968 : :
969 : 17701 : case T_DropStmt:
970 : : {
971 : 17701 : DropStmt *stmt = (DropStmt *) parsetree;
972 : :
973 [ + + ]: 17701 : if (EventTriggerSupportsObjectType(stmt->removeType))
974 : 17620 : ProcessUtilitySlow(pstate, pstmt, queryString,
975 : : context, params, queryEnv,
976 : : dest, qc);
977 : : else
978 : 81 : ExecDropStmt(stmt, isTopLevel);
979 : : }
980 : 17016 : break;
981 : :
982 : 1017 : case T_RenameStmt:
983 : : {
984 : 1017 : RenameStmt *stmt = (RenameStmt *) parsetree;
985 : :
986 [ + + ]: 1017 : if (EventTriggerSupportsObjectType(stmt->renameType))
987 : 971 : ProcessUtilitySlow(pstate, pstmt, queryString,
988 : : context, params, queryEnv,
989 : : dest, qc);
990 : : else
991 : 46 : ExecRenameStmt(stmt);
992 : : }
993 : 734 : break;
994 : :
995 : 23 : case T_AlterObjectDependsStmt:
996 : : {
997 : 23 : AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
998 : :
999 [ + - ]: 23 : if (EventTriggerSupportsObjectType(stmt->objectType))
1000 : 23 : ProcessUtilitySlow(pstate, pstmt, queryString,
1001 : : context, params, queryEnv,
1002 : : dest, qc);
1003 : : else
1004 : 0 : ExecAlterObjectDependsStmt(stmt, NULL);
1005 : : }
1006 : 23 : break;
1007 : :
1008 : 271 : case T_AlterObjectSchemaStmt:
1009 : : {
1010 : 271 : AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
1011 : :
1012 [ + - ]: 271 : if (EventTriggerSupportsObjectType(stmt->objectType))
1013 : 271 : ProcessUtilitySlow(pstate, pstmt, queryString,
1014 : : context, params, queryEnv,
1015 : : dest, qc);
1016 : : else
1017 : 0 : ExecAlterObjectSchemaStmt(stmt, NULL);
1018 : : }
1019 : 175 : break;
1020 : :
1021 : 974 : case T_AlterOwnerStmt:
1022 : : {
1023 : 974 : AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
1024 : :
1025 [ + + ]: 974 : if (EventTriggerSupportsObjectType(stmt->objectType))
1026 : 912 : ProcessUtilitySlow(pstate, pstmt, queryString,
1027 : : context, params, queryEnv,
1028 : : dest, qc);
1029 : : else
1030 : 62 : ExecAlterOwnerStmt(stmt);
1031 : : }
1032 : 806 : break;
1033 : :
1034 : 4560 : case T_CommentStmt:
1035 : : {
1036 : 4560 : CommentStmt *stmt = (CommentStmt *) parsetree;
1037 : :
1038 [ + + ]: 4560 : if (EventTriggerSupportsObjectType(stmt->objtype))
1039 : 4393 : ProcessUtilitySlow(pstate, pstmt, queryString,
1040 : : context, params, queryEnv,
1041 : : dest, qc);
1042 : : else
1043 : 167 : CommentObject(stmt);
1044 : 4455 : break;
1045 : : }
1046 : :
1047 : 67 : case T_SecLabelStmt:
1048 : : {
1049 : 67 : SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
1050 : :
1051 [ + + ]: 67 : if (EventTriggerSupportsObjectType(stmt->objtype))
1052 : 44 : ProcessUtilitySlow(pstate, pstmt, queryString,
1053 : : context, params, queryEnv,
1054 : : dest, qc);
1055 : : else
1056 : 23 : ExecSecLabelStmt(stmt);
1057 : 23 : break;
1058 : : }
1059 : :
1060 : 291 : case T_WaitStmt:
1061 : : {
1062 : 291 : ExecWaitStmt(pstate, (WaitStmt *) parsetree, isTopLevel,
1063 : : dest);
1064 : : }
1065 : 267 : break;
1066 : :
1067 : 110826 : default:
1068 : : /* All other statement types have event trigger support */
1069 : 110826 : ProcessUtilitySlow(pstate, pstmt, queryString,
1070 : : context, params, queryEnv,
1071 : : dest, qc);
1072 : 103000 : break;
1073 : : }
1074 : :
1075 : 250499 : free_parsestate(pstate);
1076 : :
1077 : : /*
1078 : : * Make effects of commands visible, for instance so that
1079 : : * PreCommit_on_commit_actions() can see them (see for example bug
1080 : : * #15631).
1081 : : */
1082 : 250499 : CommandCounterIncrement();
1083 : 250499 : }
1084 : :
1085 : : /*
1086 : : * The "Slow" variant of ProcessUtility should only receive statements
1087 : : * supported by the event triggers facility. Therefore, we always
1088 : : * perform the trigger support calls if the context allows it.
1089 : : */
1090 : : static void
1091 : 147199 : ProcessUtilitySlow(ParseState *pstate,
1092 : : PlannedStmt *pstmt,
1093 : : const char *queryString,
1094 : : ProcessUtilityContext context,
1095 : : ParamListInfo params,
1096 : : QueryEnvironment *queryEnv,
1097 : : DestReceiver *dest,
1098 : : QueryCompletion *qc)
1099 : : {
1100 : 147199 : Node *parsetree = pstmt->utilityStmt;
1101 : 147199 : bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
1102 : 147199 : bool isCompleteQuery = (context != PROCESS_UTILITY_SUBCOMMAND);
1103 : : bool needCleanup;
1104 : 147199 : bool commandCollected = false;
1105 : : ObjectAddress address;
1106 : 147199 : ObjectAddress secondaryObject = InvalidObjectAddress;
1107 : :
1108 : : /* All event trigger calls are done only when isCompleteQuery is true */
1109 [ + + + + ]: 147199 : needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
1110 : :
1111 : : /* PG_TRY block is to ensure we call EventTriggerEndCompleteQuery */
1112 [ + + ]: 147199 : PG_TRY();
1113 : : {
1114 [ + + ]: 147199 : if (isCompleteQuery)
1115 : 138940 : EventTriggerDDLCommandStart(parsetree);
1116 : :
1117 [ + + + + : 147199 : switch (nodeTag(parsetree))
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ - ]
1118 : : {
1119 : : /*
1120 : : * relation and attribute manipulation
1121 : : */
1122 : 735 : case T_CreateSchemaStmt:
1123 : 735 : CreateSchemaCommand(pstate,
1124 : : (CreateSchemaStmt *) parsetree,
1125 : : pstmt->stmt_location,
1126 : : pstmt->stmt_len);
1127 : :
1128 : : /*
1129 : : * EventTriggerCollectSimpleCommand called by
1130 : : * CreateSchemaCommand
1131 : : */
1132 : 651 : commandCollected = true;
1133 : 651 : break;
1134 : :
1135 : 25958 : case T_CreateStmt:
1136 : : case T_CreateForeignTableStmt:
1137 : : {
1138 : : List *stmts;
1139 : 25958 : RangeVar *table_rv = NULL;
1140 : :
1141 : : /* Run parse analysis ... */
1142 : 25958 : stmts = transformCreateStmt((CreateStmt *) parsetree,
1143 : : queryString);
1144 : :
1145 : : /*
1146 : : * ... and do it. We can't use foreach() because we may
1147 : : * modify the list midway through, so pick off the
1148 : : * elements one at a time, the hard way.
1149 : : */
1150 [ + + ]: 57769 : while (stmts != NIL)
1151 : : {
1152 : 33298 : Node *stmt = (Node *) linitial(stmts);
1153 : :
1154 : 33298 : stmts = list_delete_first(stmts);
1155 : :
1156 [ + + ]: 33298 : if (IsA(stmt, CreateStmt))
1157 : : {
1158 : 25439 : CreateStmt *cstmt = (CreateStmt *) stmt;
1159 : : Datum toast_options;
1160 : 25439 : const char *const validnsps[] = HEAP_RELOPT_NAMESPACES;
1161 : :
1162 : : /* Remember transformed RangeVar for LIKE */
1163 : 25439 : table_rv = cstmt->relation;
1164 : :
1165 : : /* Create the table itself */
1166 : 25439 : address = DefineRelation(cstmt,
1167 : : RELKIND_RELATION,
1168 : : InvalidOid, NULL,
1169 : : queryString);
1170 : 24536 : EventTriggerCollectSimpleCommand(address,
1171 : : secondaryObject,
1172 : : stmt);
1173 : :
1174 : : /*
1175 : : * Let NewRelationCreateToastTable decide if this
1176 : : * one needs a secondary relation too.
1177 : : */
1178 : 24536 : CommandCounterIncrement();
1179 : :
1180 : : /*
1181 : : * parse and validate reloptions for the toast
1182 : : * table
1183 : : */
1184 : 24536 : toast_options = transformRelOptions((Datum) 0,
1185 : : cstmt->options,
1186 : : "toast",
1187 : : validnsps,
1188 : : true,
1189 : : false);
1190 : 24536 : (void) heap_reloptions(RELKIND_TOASTVALUE,
1191 : : toast_options,
1192 : : true);
1193 : :
1194 : 24528 : NewRelationCreateToastTable(address.objectId,
1195 : : toast_options);
1196 : : }
1197 [ + + ]: 7859 : else if (IsA(stmt, CreateForeignTableStmt))
1198 : : {
1199 : 292 : CreateForeignTableStmt *cstmt = (CreateForeignTableStmt *) stmt;
1200 : :
1201 : : /* Remember transformed RangeVar for LIKE */
1202 : 292 : table_rv = cstmt->base.relation;
1203 : :
1204 : : /* Create the table itself */
1205 : 292 : address = DefineRelation(&cstmt->base,
1206 : : RELKIND_FOREIGN_TABLE,
1207 : : InvalidOid, NULL,
1208 : : queryString);
1209 : 275 : CreateForeignTable(cstmt,
1210 : : address.objectId);
1211 : 236 : EventTriggerCollectSimpleCommand(address,
1212 : : secondaryObject,
1213 : : stmt);
1214 : : }
1215 [ + + ]: 7567 : else if (IsA(stmt, TableLikeClause))
1216 : : {
1217 : : /*
1218 : : * Do delayed processing of LIKE options. This
1219 : : * will result in additional sub-statements for us
1220 : : * to process. Those should get done before any
1221 : : * remaining actions, so prepend them to "stmts".
1222 : : */
1223 : 145 : TableLikeClause *like = (TableLikeClause *) stmt;
1224 : : List *morestmts;
1225 : :
1226 : : Assert(table_rv != NULL);
1227 : :
1228 : 145 : morestmts = expandTableLikeClause(table_rv, like);
1229 : 141 : stmts = list_concat(morestmts, stmts);
1230 : : }
1231 : : else
1232 : : {
1233 : : /*
1234 : : * Recurse for anything else. Note the recursive
1235 : : * call will stash the objects so created into our
1236 : : * event trigger context.
1237 : : */
1238 : : PlannedStmt *wrapper;
1239 : :
1240 : 7422 : wrapper = makeNode(PlannedStmt);
1241 : 7422 : wrapper->commandType = CMD_UTILITY;
1242 : 7422 : wrapper->canSetTag = false;
1243 : 7422 : wrapper->utilityStmt = stmt;
1244 : 7422 : wrapper->stmt_location = pstmt->stmt_location;
1245 : 7422 : wrapper->stmt_len = pstmt->stmt_len;
1246 : 7422 : wrapper->planOrigin = PLAN_STMT_INTERNAL;
1247 : :
1248 : 7422 : ProcessUtility(wrapper,
1249 : : queryString,
1250 : : false,
1251 : : PROCESS_UTILITY_SUBCOMMAND,
1252 : : params,
1253 : : NULL,
1254 : : None_Receiver,
1255 : : NULL);
1256 : : }
1257 : :
1258 : : /* Need CCI between commands */
1259 [ + + ]: 32029 : if (stmts != NIL)
1260 : 7563 : CommandCounterIncrement();
1261 : : }
1262 : :
1263 : : /*
1264 : : * The multiple commands generated here are stashed
1265 : : * individually, so disable collection below.
1266 : : */
1267 : 24471 : commandCollected = true;
1268 : : }
1269 : 24471 : break;
1270 : :
1271 : 21028 : case T_AlterTableStmt:
1272 : : {
1273 : 21028 : 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 [ + - + + : 42874 : foreach(cell, atstmt->cmds)
+ + ]
1284 : : {
1285 : 21850 : AlterTableCmd *cmd = (AlterTableCmd *) lfirst(cell);
1286 : :
1287 : : /* Disallow DETACH CONCURRENTLY in a transaction block */
1288 [ + + ]: 21850 : if (cmd->subtype == AT_DetachPartition)
1289 : : {
1290 [ + + ]: 378 : if (((PartitionCmd *) cmd->def)->concurrent)
1291 : 92 : 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 : 21024 : lockmode = AlterTableGetLockLevel(atstmt->cmds);
1303 : 21024 : relid = AlterTableLookupRelation(atstmt, lockmode);
1304 : :
1305 [ + + ]: 20958 : if (OidIsValid(relid))
1306 : : {
1307 : : AlterTableUtilityContext atcontext;
1308 : :
1309 : : /* Set up info needed for recursive callbacks ... */
1310 : 20850 : atcontext.pstmt = pstmt;
1311 : 20850 : atcontext.queryString = queryString;
1312 : 20850 : atcontext.relid = relid;
1313 : 20850 : atcontext.params = params;
1314 : 20850 : atcontext.queryEnv = queryEnv;
1315 : :
1316 : : /* ... ensure we have an event trigger context ... */
1317 : 20850 : EventTriggerAlterTableStart(parsetree);
1318 : 20850 : EventTriggerAlterTableRelid(relid);
1319 : :
1320 : : /* ... and do it */
1321 : 20850 : AlterTable(atstmt, lockmode, &atcontext);
1322 : :
1323 : : /* done */
1324 : 18112 : EventTriggerAlterTableEnd();
1325 : : }
1326 : : else
1327 [ + - ]: 108 : ereport(NOTICE,
1328 : : (errmsg("relation \"%s\" does not exist, skipping",
1329 : : atstmt->relation->relname)));
1330 : : }
1331 : :
1332 : : /* ALTER TABLE stashes commands internally */
1333 : 18220 : commandCollected = true;
1334 : 18220 : break;
1335 : :
1336 : 194 : case T_AlterDomainStmt:
1337 : : {
1338 : 194 : 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 [ + + + + : 194 : switch (stmt->subtype)
+ + - ]
1345 : : {
1346 : 9 : case AD_AlterDefault:
1347 : :
1348 : : /*
1349 : : * Recursively alter column default for table and,
1350 : : * if requested, for descendants
1351 : : */
1352 : : address =
1353 : 9 : AlterDomainDefault(stmt->typeName,
1354 : : stmt->def);
1355 : 9 : break;
1356 : 8 : case AD_DropNotNull:
1357 : : address =
1358 : 8 : AlterDomainNotNull(stmt->typeName,
1359 : : false);
1360 : 8 : break;
1361 : 16 : case AD_SetNotNull:
1362 : : address =
1363 : 16 : AlterDomainNotNull(stmt->typeName,
1364 : : true);
1365 : 8 : break;
1366 : 112 : case AD_AddConstraint:
1367 : : address =
1368 : 112 : AlterDomainAddConstraint(stmt->typeName,
1369 : : stmt->def,
1370 : : &secondaryObject,
1371 : : false);
1372 : 64 : break;
1373 : 40 : case AD_DropConstraint:
1374 : : address =
1375 : 40 : AlterDomainDropConstraint(stmt->typeName,
1376 : 40 : stmt->name,
1377 : : stmt->behavior,
1378 : 40 : stmt->missing_ok);
1379 : 36 : break;
1380 : 9 : case AD_ValidateConstraint:
1381 : : address =
1382 : 9 : AlterDomainValidateConstraint(stmt->typeName,
1383 : 9 : stmt->name);
1384 : 4 : break;
1385 : 0 : default: /* oops */
1386 [ # # ]: 0 : elog(ERROR, "unrecognized alter domain type: %d",
1387 : : (int) stmt->subtype);
1388 : : break;
1389 : : }
1390 : : }
1391 : 129 : break;
1392 : :
1393 : : /*
1394 : : * ************* object creation / destruction **************
1395 : : */
1396 : 5751 : case T_DefineStmt:
1397 : : {
1398 : 5751 : DefineStmt *stmt = (DefineStmt *) parsetree;
1399 : :
1400 [ + + + + : 5751 : switch (stmt->kind)
+ + + +
- ]
1401 : : {
1402 : 581 : case OBJECT_AGGREGATE:
1403 : : address =
1404 : 581 : DefineAggregate(pstate, stmt->defnames, stmt->args,
1405 : 581 : stmt->oldstyle,
1406 : : stmt->definition,
1407 : 581 : stmt->replace);
1408 : 361 : break;
1409 : 893 : case OBJECT_OPERATOR:
1410 : : Assert(stmt->args == NIL);
1411 : 893 : address = DefineOperator(stmt->defnames,
1412 : : stmt->definition);
1413 : 828 : break;
1414 : 242 : case OBJECT_TYPE:
1415 : : Assert(stmt->args == NIL);
1416 : 242 : address = DefineType(pstate,
1417 : : stmt->defnames,
1418 : : stmt->definition);
1419 : 218 : break;
1420 : 26 : case OBJECT_TSPARSER:
1421 : : Assert(stmt->args == NIL);
1422 : 26 : address = DefineTSParser(stmt->defnames,
1423 : : stmt->definition);
1424 : 22 : break;
1425 : 1860 : case OBJECT_TSDICTIONARY:
1426 : : Assert(stmt->args == NIL);
1427 : 1860 : address = DefineTSDictionary(stmt->defnames,
1428 : : stmt->definition);
1429 : 1844 : break;
1430 : 85 : case OBJECT_TSTEMPLATE:
1431 : : Assert(stmt->args == NIL);
1432 : 85 : address = DefineTSTemplate(stmt->defnames,
1433 : : stmt->definition);
1434 : 81 : break;
1435 : 1824 : case OBJECT_TSCONFIGURATION:
1436 : : Assert(stmt->args == NIL);
1437 : 1824 : address = DefineTSConfiguration(stmt->defnames,
1438 : : stmt->definition,
1439 : : &secondaryObject);
1440 : 1824 : break;
1441 : 240 : case OBJECT_COLLATION:
1442 : : Assert(stmt->args == NIL);
1443 : 240 : address = DefineCollation(pstate,
1444 : : stmt->defnames,
1445 : : stmt->definition,
1446 : 240 : stmt->if_not_exists);
1447 : 143 : break;
1448 : 0 : default:
1449 [ # # ]: 0 : elog(ERROR, "unrecognized define stmt type: %d",
1450 : : (int) stmt->kind);
1451 : : break;
1452 : : }
1453 : : }
1454 : 5321 : break;
1455 : :
1456 : 9208 : case T_IndexStmt: /* CREATE INDEX */
1457 : : {
1458 : 9208 : IndexStmt *stmt = (IndexStmt *) parsetree;
1459 : : Oid relid;
1460 : : LOCKMODE lockmode;
1461 : 9208 : int nparts = -1;
1462 : : bool is_alter_table;
1463 : :
1464 [ + + ]: 9208 : if (stmt->concurrent)
1465 : 148 : PreventInTransactionBlock(isTopLevel,
1466 : : "CREATE INDEX CONCURRENTLY");
1467 : :
1468 : : /*
1469 : : * Look up the relation OID just once, right here at the
1470 : : * beginning, so that we don't end up repeating the name
1471 : : * lookup later and latching onto a different relation
1472 : : * partway through. To avoid lock upgrade hazards, it's
1473 : : * important that we take the strongest lock that will
1474 : : * eventually be needed here, so the lockmode calculation
1475 : : * needs to match what DefineIndex() does.
1476 : : */
1477 : 18400 : lockmode = stmt->concurrent ? ShareUpdateExclusiveLock
1478 [ + + ]: 9200 : : ShareLock;
1479 : : relid =
1480 : 9200 : RangeVarGetRelidExtended(stmt->relation, lockmode,
1481 : : 0,
1482 : : RangeVarCallbackOwnsRelation,
1483 : : NULL);
1484 : :
1485 : : /*
1486 : : * CREATE INDEX on partitioned tables (but not regular
1487 : : * inherited tables) recurses to partitions, so we must
1488 : : * acquire locks early to avoid deadlocks.
1489 : : *
1490 : : * We also take the opportunity to verify that all
1491 : : * partitions are something we can put an index on, to
1492 : : * avoid building some indexes only to fail later. While
1493 : : * at it, also count the partitions, so that DefineIndex
1494 : : * needn't do a duplicative find_all_inheritors search.
1495 : : */
1496 [ + + ]: 9195 : if (stmt->relation->inh &&
1497 [ + + ]: 9044 : get_rel_relkind(relid) == RELKIND_PARTITIONED_TABLE)
1498 : : {
1499 : : ListCell *lc;
1500 : 894 : List *inheritors = NIL;
1501 : :
1502 : 894 : inheritors = find_all_inheritors(relid, lockmode, NULL);
1503 [ + - + + : 2320 : foreach(lc, inheritors)
+ + ]
1504 : : {
1505 : 1434 : Oid partrelid = lfirst_oid(lc);
1506 : 1434 : char relkind = get_rel_relkind(partrelid);
1507 : :
1508 [ + + + - ]: 1434 : if (relkind != RELKIND_RELATION &&
1509 [ + + ]: 980 : relkind != RELKIND_MATVIEW &&
1510 [ - + ]: 12 : relkind != RELKIND_PARTITIONED_TABLE &&
1511 : : relkind != RELKIND_FOREIGN_TABLE)
1512 [ # # ]: 0 : elog(ERROR, "unexpected relkind \"%c\" on partition \"%s\"",
1513 : : relkind, stmt->relation->relname);
1514 : :
1515 [ + + ]: 1434 : if (relkind == RELKIND_FOREIGN_TABLE &&
1516 [ + + - + ]: 12 : (stmt->unique || stmt->primary))
1517 [ + - ]: 8 : ereport(ERROR,
1518 : : (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1519 : : errmsg("cannot create unique index on partitioned table \"%s\"",
1520 : : stmt->relation->relname),
1521 : : errdetail("Table \"%s\" contains partitions that are foreign tables.",
1522 : : stmt->relation->relname)));
1523 : : }
1524 : : /* count direct and indirect children, but not rel */
1525 : 886 : nparts = list_length(inheritors) - 1;
1526 : 886 : list_free(inheritors);
1527 : : }
1528 : :
1529 : : /*
1530 : : * If the IndexStmt is already transformed, it must have
1531 : : * come from generateClonedIndexStmt, which in current
1532 : : * usage means it came from expandTableLikeClause rather
1533 : : * than from original parse analysis. And that means we
1534 : : * must treat it like ALTER TABLE ADD INDEX, not CREATE.
1535 : : * (This is a bit grotty, but currently it doesn't seem
1536 : : * worth adding a separate bool field for the purpose.)
1537 : : */
1538 : 9187 : is_alter_table = stmt->transformed;
1539 : :
1540 : : /* Run parse analysis ... */
1541 : 9187 : stmt = transformIndexStmt(relid, stmt, queryString);
1542 : :
1543 : : /* ... and do it */
1544 : 9163 : EventTriggerAlterTableStart(parsetree);
1545 : : address =
1546 : 9163 : DefineIndex(pstate,
1547 : : relid, /* OID of heap relation */
1548 : : stmt,
1549 : : InvalidOid, /* no predefined OID */
1550 : : InvalidOid, /* no parent index */
1551 : : InvalidOid, /* no parent constraint */
1552 : : nparts, /* # of partitions, or -1 */
1553 : : is_alter_table,
1554 : : true, /* check_rights */
1555 : : true, /* check_not_in_use */
1556 : : false, /* skip_build */
1557 : : false); /* quiet */
1558 : :
1559 : : /*
1560 : : * Add the CREATE INDEX node itself to stash right away;
1561 : : * if there were any commands stashed in the ALTER TABLE
1562 : : * code, we need them to appear after this one.
1563 : : */
1564 : 8679 : EventTriggerCollectSimpleCommand(address, secondaryObject,
1565 : : parsetree);
1566 : 8679 : commandCollected = true;
1567 : 8679 : EventTriggerAlterTableEnd();
1568 : : }
1569 : 8679 : break;
1570 : :
1571 : 709 : case T_ReindexStmt:
1572 : 709 : ExecReindex(pstate, (ReindexStmt *) parsetree, isTopLevel);
1573 : :
1574 : : /* EventTriggerCollectSimpleCommand is called directly */
1575 : 501 : commandCollected = true;
1576 : 501 : break;
1577 : :
1578 : 358 : case T_CreateExtensionStmt:
1579 : 358 : address = CreateExtension(pstate, (CreateExtensionStmt *) parsetree);
1580 : 335 : break;
1581 : :
1582 : 19 : case T_AlterExtensionStmt:
1583 : 19 : address = ExecAlterExtensionStmt(pstate, (AlterExtensionStmt *) parsetree);
1584 : 17 : break;
1585 : :
1586 : 146 : case T_AlterExtensionContentsStmt:
1587 : 146 : address = ExecAlterExtensionContentsStmt((AlterExtensionContentsStmt *) parsetree,
1588 : : &secondaryObject);
1589 : 145 : break;
1590 : :
1591 : 152 : case T_CreateFdwStmt:
1592 : 152 : address = CreateForeignDataWrapper(pstate, (CreateFdwStmt *) parsetree);
1593 : 119 : break;
1594 : :
1595 : 103 : case T_AlterFdwStmt:
1596 : 103 : address = AlterForeignDataWrapper(pstate, (AlterFdwStmt *) parsetree);
1597 : 54 : break;
1598 : :
1599 : 194 : case T_CreateForeignServerStmt:
1600 : 194 : address = CreateForeignServer((CreateForeignServerStmt *) parsetree);
1601 : 161 : break;
1602 : :
1603 : 129 : case T_AlterForeignServerStmt:
1604 : 129 : address = AlterForeignServer((AlterForeignServerStmt *) parsetree);
1605 : 96 : break;
1606 : :
1607 : 167 : case T_CreateUserMappingStmt:
1608 : 167 : address = CreateUserMapping((CreateUserMappingStmt *) parsetree);
1609 : 124 : break;
1610 : :
1611 : 73 : case T_AlterUserMappingStmt:
1612 : 73 : address = AlterUserMapping((AlterUserMappingStmt *) parsetree);
1613 : 36 : break;
1614 : :
1615 : 79 : case T_DropUserMappingStmt:
1616 : 79 : RemoveUserMapping((DropUserMappingStmt *) parsetree);
1617 : : /* no commands stashed for DROP */
1618 : 54 : commandCollected = true;
1619 : 54 : break;
1620 : :
1621 : 28 : case T_ImportForeignSchemaStmt:
1622 : 28 : ImportForeignSchema((ImportForeignSchemaStmt *) parsetree);
1623 : : /* commands are stashed inside ImportForeignSchema */
1624 : 7 : commandCollected = true;
1625 : 7 : break;
1626 : :
1627 : 2387 : case T_CompositeTypeStmt: /* CREATE TYPE (composite) */
1628 : : {
1629 : 2387 : CompositeTypeStmt *stmt = (CompositeTypeStmt *) parsetree;
1630 : :
1631 : 2387 : address = DefineCompositeType(stmt->typevar,
1632 : : stmt->coldeflist);
1633 : : }
1634 : 2379 : break;
1635 : :
1636 : 284 : case T_CreateEnumStmt: /* CREATE TYPE AS ENUM */
1637 : 284 : address = DefineEnum((CreateEnumStmt *) parsetree);
1638 : 279 : break;
1639 : :
1640 : 148 : case T_CreateRangeStmt: /* CREATE TYPE AS RANGE */
1641 : 148 : address = DefineRange(pstate, (CreateRangeStmt *) parsetree);
1642 : 124 : break;
1643 : :
1644 : 246 : case T_AlterEnumStmt: /* ALTER TYPE (enum) */
1645 : 246 : address = AlterEnum((AlterEnumStmt *) parsetree);
1646 : 226 : break;
1647 : :
1648 : 10710 : case T_ViewStmt: /* CREATE VIEW */
1649 : 10710 : EventTriggerAlterTableStart(parsetree);
1650 : 10710 : address = DefineView((ViewStmt *) parsetree, queryString,
1651 : : pstmt->stmt_location, pstmt->stmt_len);
1652 : 10653 : EventTriggerCollectSimpleCommand(address, secondaryObject,
1653 : : parsetree);
1654 : : /* stashed internally */
1655 : 10653 : commandCollected = true;
1656 : 10653 : EventTriggerAlterTableEnd();
1657 : 10653 : break;
1658 : :
1659 : 13536 : case T_CreateFunctionStmt: /* CREATE FUNCTION */
1660 : 13536 : address = CreateFunction(pstate, (CreateFunctionStmt *) parsetree);
1661 : 13172 : break;
1662 : :
1663 : 221 : case T_AlterFunctionStmt: /* ALTER FUNCTION */
1664 : 221 : address = AlterFunction(pstate, (AlterFunctionStmt *) parsetree);
1665 : 201 : break;
1666 : :
1667 : 734 : case T_RuleStmt: /* CREATE RULE */
1668 : 734 : address = DefineRule((RuleStmt *) parsetree, queryString);
1669 : 701 : break;
1670 : :
1671 : 1276 : case T_CreateSeqStmt:
1672 : 1276 : address = DefineSequence(pstate, (CreateSeqStmt *) parsetree);
1673 : 1211 : break;
1674 : :
1675 : 995 : case T_AlterSeqStmt:
1676 : 995 : address = AlterSequence(pstate, (AlterSeqStmt *) parsetree);
1677 : 963 : break;
1678 : :
1679 : 1187 : case T_CreateTableAsStmt:
1680 : 1187 : address = ExecCreateTableAs(pstate, (CreateTableAsStmt *) parsetree,
1681 : : params, queryEnv, qc);
1682 : 1117 : break;
1683 : :
1684 : 174 : case T_RefreshMatViewStmt:
1685 : :
1686 : : /*
1687 : : * REFRESH CONCURRENTLY executes some DDL commands internally.
1688 : : * Inhibit DDL command collection here to avoid those commands
1689 : : * from showing up in the deparsed command queue. The refresh
1690 : : * command itself is queued, which is enough.
1691 : : */
1692 : 174 : EventTriggerInhibitCommandCollection();
1693 [ + + ]: 174 : PG_TRY(2);
1694 : : {
1695 : 174 : address = ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
1696 : : queryString, qc);
1697 : : }
1698 : 48 : PG_FINALLY(2);
1699 : : {
1700 : 174 : EventTriggerUndoInhibitCommandCollection();
1701 : : }
1702 [ + + ]: 174 : PG_END_TRY(2);
1703 : 126 : break;
1704 : :
1705 : 2038 : case T_CreateTrigStmt:
1706 : 2038 : address = CreateTrigger((CreateTrigStmt *) parsetree,
1707 : : queryString, InvalidOid, InvalidOid,
1708 : : InvalidOid, InvalidOid, InvalidOid,
1709 : : InvalidOid, NULL, false, false);
1710 : 1885 : break;
1711 : :
1712 : 82 : case T_CreatePLangStmt:
1713 : 82 : address = CreateProceduralLanguage((CreatePLangStmt *) parsetree);
1714 : 82 : break;
1715 : :
1716 : 1032 : case T_CreateDomainStmt:
1717 : 1032 : address = DefineDomain(pstate, (CreateDomainStmt *) parsetree);
1718 : 947 : break;
1719 : :
1720 : 42 : case T_CreateConversionStmt:
1721 : 42 : address = CreateConversionCommand((CreateConversionStmt *) parsetree);
1722 : 34 : break;
1723 : :
1724 : 192 : case T_CreateCastStmt:
1725 : 192 : address = CreateCast((CreateCastStmt *) parsetree);
1726 : 188 : break;
1727 : :
1728 : 303 : case T_CreateOpClassStmt:
1729 : 303 : DefineOpClass((CreateOpClassStmt *) parsetree);
1730 : : /* command is stashed in DefineOpClass */
1731 : 303 : commandCollected = true;
1732 : 303 : break;
1733 : :
1734 : 99 : case T_CreateOpFamilyStmt:
1735 : 99 : address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1736 : :
1737 : : /*
1738 : : * DefineOpFamily calls EventTriggerCollectSimpleCommand
1739 : : * directly.
1740 : : */
1741 : 99 : commandCollected = true;
1742 : 99 : break;
1743 : :
1744 : 26 : case T_CreateTransformStmt:
1745 : 26 : address = CreateTransform((CreateTransformStmt *) parsetree);
1746 : 21 : break;
1747 : :
1748 : 288 : case T_AlterOpFamilyStmt:
1749 : 288 : AlterOpFamily((AlterOpFamilyStmt *) parsetree);
1750 : : /* commands are stashed in AlterOpFamily */
1751 : 180 : commandCollected = true;
1752 : 180 : break;
1753 : :
1754 : 23 : case T_AlterTSDictionaryStmt:
1755 : 23 : address = AlterTSDictionary((AlterTSDictionaryStmt *) parsetree);
1756 : 18 : break;
1757 : :
1758 : 5436 : case T_AlterTSConfigurationStmt:
1759 : 5436 : AlterTSConfiguration((AlterTSConfigurationStmt *) parsetree);
1760 : :
1761 : : /*
1762 : : * Commands are stashed in MakeConfigurationMapping and
1763 : : * DropConfigurationMapping, which are called from
1764 : : * AlterTSConfiguration
1765 : : */
1766 : 5420 : commandCollected = true;
1767 : 5420 : break;
1768 : :
1769 : 16 : case T_AlterTableMoveAllStmt:
1770 : 16 : AlterTableMoveAll((AlterTableMoveAllStmt *) parsetree);
1771 : : /* commands are stashed in AlterTableMoveAll */
1772 : 16 : commandCollected = true;
1773 : 16 : break;
1774 : :
1775 : 17620 : case T_DropStmt:
1776 : 17620 : ExecDropStmt((DropStmt *) parsetree, isTopLevel);
1777 : : /* no commands stashed for DROP */
1778 : 16951 : commandCollected = true;
1779 : 16951 : break;
1780 : :
1781 : 971 : case T_RenameStmt:
1782 : 971 : address = ExecRenameStmt((RenameStmt *) parsetree);
1783 : 699 : break;
1784 : :
1785 : 23 : case T_AlterObjectDependsStmt:
1786 : : address =
1787 : 23 : ExecAlterObjectDependsStmt((AlterObjectDependsStmt *) parsetree,
1788 : : &secondaryObject);
1789 : 23 : break;
1790 : :
1791 : 271 : case T_AlterObjectSchemaStmt:
1792 : : address =
1793 : 271 : ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree,
1794 : : &secondaryObject);
1795 : 175 : break;
1796 : :
1797 : 912 : case T_AlterOwnerStmt:
1798 : 912 : address = ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
1799 : 748 : break;
1800 : :
1801 : 332 : case T_AlterOperatorStmt:
1802 : 332 : address = AlterOperator((AlterOperatorStmt *) parsetree);
1803 : 288 : break;
1804 : :
1805 : 36 : case T_AlterTypeStmt:
1806 : 36 : address = AlterType((AlterTypeStmt *) parsetree);
1807 : 28 : break;
1808 : :
1809 : 4393 : case T_CommentStmt:
1810 : 4393 : address = CommentObject((CommentStmt *) parsetree);
1811 : 4292 : break;
1812 : :
1813 : 12139 : case T_GrantStmt:
1814 : 12139 : ExecuteGrantStmt((GrantStmt *) parsetree);
1815 : : /* commands are stashed in ExecGrantStmt_oids */
1816 : 12048 : commandCollected = true;
1817 : 12048 : break;
1818 : :
1819 : 103 : case T_DropOwnedStmt:
1820 : 103 : DropOwnedObjects((DropOwnedStmt *) parsetree);
1821 : : /* no commands stashed for DROP */
1822 : 91 : commandCollected = true;
1823 : 91 : break;
1824 : :
1825 : 135 : case T_AlterDefaultPrivilegesStmt:
1826 : 135 : ExecAlterDefaultPrivilegesStmt(pstate, (AlterDefaultPrivilegesStmt *) parsetree);
1827 : 127 : EventTriggerCollectAlterDefPrivs((AlterDefaultPrivilegesStmt *) parsetree);
1828 : 127 : commandCollected = true;
1829 : 127 : break;
1830 : :
1831 : 539 : case T_CreatePolicyStmt: /* CREATE POLICY */
1832 : 539 : address = CreatePolicy((CreatePolicyStmt *) parsetree);
1833 : 522 : break;
1834 : :
1835 : 56 : case T_AlterPolicyStmt: /* ALTER POLICY */
1836 : 56 : address = AlterPolicy((AlterPolicyStmt *) parsetree);
1837 : 48 : break;
1838 : :
1839 : 44 : case T_SecLabelStmt:
1840 : 44 : address = ExecSecLabelStmt((SecLabelStmt *) parsetree);
1841 : 21 : break;
1842 : :
1843 : 38 : case T_CreateAmStmt:
1844 : 38 : address = CreateAccessMethod((CreateAmStmt *) parsetree);
1845 : 22 : break;
1846 : :
1847 : 658 : case T_CreatePublicationStmt:
1848 : 658 : address = CreatePublication(pstate, (CreatePublicationStmt *) parsetree);
1849 : 536 : break;
1850 : :
1851 : 784 : case T_AlterPublicationStmt:
1852 : 784 : AlterPublication(pstate, (AlterPublicationStmt *) parsetree);
1853 : :
1854 : : /*
1855 : : * AlterPublication calls EventTriggerCollectSimpleCommand
1856 : : * directly
1857 : : */
1858 : 600 : commandCollected = true;
1859 : 600 : break;
1860 : :
1861 : 339 : case T_CreateSubscriptionStmt:
1862 : 339 : address = CreateSubscription(pstate,
1863 : : (CreateSubscriptionStmt *) parsetree,
1864 : : isTopLevel);
1865 : 217 : break;
1866 : :
1867 : 447 : case T_AlterSubscriptionStmt:
1868 : 447 : address = AlterSubscription(pstate,
1869 : : (AlterSubscriptionStmt *) parsetree,
1870 : : isTopLevel);
1871 : 360 : break;
1872 : :
1873 : 184 : case T_DropSubscriptionStmt:
1874 : 184 : DropSubscription((DropSubscriptionStmt *) parsetree, isTopLevel);
1875 : : /* no commands stashed for DROP */
1876 : 167 : commandCollected = true;
1877 : 167 : break;
1878 : :
1879 : 648 : case T_CreateStatsStmt:
1880 : : {
1881 : : Oid relid;
1882 : 648 : CreateStatsStmt *stmt = (CreateStatsStmt *) parsetree;
1883 : : RangeVar *rel;
1884 : :
1885 : : /*
1886 : : * Examine the FROM clause. Currently, we only allow it
1887 : : * to be a single simple table, but later we'll probably
1888 : : * allow multiple tables and JOIN syntax. The grammar is
1889 : : * already prepared for that, so we have to check here
1890 : : * that what we got is what we can support.
1891 : : */
1892 [ + + ]: 648 : if (list_length(stmt->relations) != 1)
1893 [ + - ]: 8 : ereport(ERROR,
1894 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1895 : : errmsg("only a single relation is allowed in CREATE STATISTICS")));
1896 : :
1897 : 640 : rel = (RangeVar *) linitial(stmt->relations);
1898 : :
1899 [ + + ]: 640 : if (!IsA(rel, RangeVar))
1900 [ + - ]: 28 : ereport(ERROR,
1901 : : (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1902 : : errmsg("CREATE STATISTICS only supports relation names in the FROM clause")));
1903 : :
1904 : : /*
1905 : : * CREATE STATISTICS will influence future execution plans
1906 : : * but does not interfere with currently executing plans.
1907 : : * So it should be enough to take ShareUpdateExclusiveLock
1908 : : * on relation, conflicting with ANALYZE and other DDL
1909 : : * that sets statistical information, but not with normal
1910 : : * queries.
1911 : : *
1912 : : * XXX RangeVarCallbackOwnsRelation not needed here, to
1913 : : * keep the same behavior as before.
1914 : : */
1915 : 612 : relid = RangeVarGetRelid(rel, ShareUpdateExclusiveLock, false);
1916 : :
1917 : : /* Run parse analysis ... */
1918 : 608 : stmt = transformStatsStmt(relid, stmt, queryString);
1919 : :
1920 : 608 : address = CreateStatistics(list_make1_oid(relid), stmt,
1921 : : true);
1922 : : }
1923 : 512 : break;
1924 : :
1925 : 17 : case T_AlterStatsStmt:
1926 : 17 : address = AlterStatistics((AlterStatsStmt *) parsetree);
1927 : 13 : break;
1928 : :
1929 : 4 : case T_AlterCollationStmt:
1930 : 4 : address = AlterCollation((AlterCollationStmt *) parsetree);
1931 : 4 : break;
1932 : :
1933 : 0 : default:
1934 [ # # ]: 0 : elog(ERROR, "unrecognized node type: %d",
1935 : : (int) nodeTag(parsetree));
1936 : : break;
1937 : : }
1938 : :
1939 : : /*
1940 : : * Remember the object so that ddl_command_end event triggers have
1941 : : * access to it.
1942 : : */
1943 [ + + ]: 137957 : if (!commandCollected)
1944 : 38719 : EventTriggerCollectSimpleCommand(address, secondaryObject,
1945 : : parsetree);
1946 : :
1947 [ + + ]: 137957 : if (isCompleteQuery)
1948 : : {
1949 : 130010 : EventTriggerSQLDrop(parsetree);
1950 : 129998 : EventTriggerDDLCommandEnd(parsetree);
1951 : : }
1952 : : }
1953 : 9254 : PG_FINALLY();
1954 : : {
1955 [ + + ]: 147199 : if (needCleanup)
1956 : 1905 : EventTriggerEndCompleteQuery();
1957 : : }
1958 [ + + ]: 147199 : PG_END_TRY();
1959 : 137945 : }
1960 : :
1961 : : /*
1962 : : * ProcessUtilityForAlterTable
1963 : : * Recursive entry from ALTER TABLE
1964 : : *
1965 : : * ALTER TABLE sometimes generates subcommands such as CREATE INDEX.
1966 : : * It calls this, not the main entry point ProcessUtility, to execute
1967 : : * such subcommands.
1968 : : *
1969 : : * stmt: the utility command to execute
1970 : : * context: opaque passthrough struct with the info we need
1971 : : *
1972 : : * It's caller's responsibility to do CommandCounterIncrement after
1973 : : * calling this, if needed.
1974 : : */
1975 : : void
1976 : 371 : ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
1977 : : {
1978 : : PlannedStmt *wrapper;
1979 : :
1980 : : /*
1981 : : * For event triggers, we must "close" the current complex-command set,
1982 : : * and start a new one afterwards; this is needed to ensure the ordering
1983 : : * of command events is consistent with the way they were executed.
1984 : : */
1985 : 371 : EventTriggerAlterTableEnd();
1986 : :
1987 : : /* Create a suitable wrapper */
1988 : 371 : wrapper = makeNode(PlannedStmt);
1989 : 371 : wrapper->commandType = CMD_UTILITY;
1990 : 371 : wrapper->canSetTag = false;
1991 : 371 : wrapper->utilityStmt = stmt;
1992 : 371 : wrapper->stmt_location = context->pstmt->stmt_location;
1993 : 371 : wrapper->stmt_len = context->pstmt->stmt_len;
1994 : 371 : wrapper->planOrigin = PLAN_STMT_INTERNAL;
1995 : :
1996 : 371 : ProcessUtility(wrapper,
1997 : : context->queryString,
1998 : : false,
1999 : : PROCESS_UTILITY_SUBCOMMAND,
2000 : : context->params,
2001 : : context->queryEnv,
2002 : : None_Receiver,
2003 : : NULL);
2004 : :
2005 : 363 : EventTriggerAlterTableStart(context->pstmt->utilityStmt);
2006 : 363 : EventTriggerAlterTableRelid(context->relid);
2007 : 363 : }
2008 : :
2009 : : /*
2010 : : * Dispatch function for DropStmt
2011 : : */
2012 : : static void
2013 : 17701 : ExecDropStmt(DropStmt *stmt, bool isTopLevel)
2014 : : {
2015 [ + + + ]: 17701 : switch (stmt->removeType)
2016 : : {
2017 : 548 : case OBJECT_INDEX:
2018 [ + + ]: 548 : if (stmt->concurrent)
2019 : 97 : PreventInTransactionBlock(isTopLevel,
2020 : : "DROP INDEX CONCURRENTLY");
2021 : : pg_fallthrough;
2022 : :
2023 : : case OBJECT_TABLE:
2024 : : case OBJECT_SEQUENCE:
2025 : : case OBJECT_VIEW:
2026 : : case OBJECT_MATVIEW:
2027 : : case OBJECT_FOREIGN_TABLE:
2028 : 11462 : RemoveRelations(stmt);
2029 : 11256 : break;
2030 : 6235 : default:
2031 : 6235 : RemoveObjects(stmt);
2032 : 5772 : break;
2033 : : }
2034 : 17028 : }
2035 : :
2036 : :
2037 : : /*
2038 : : * UtilityReturnsTuples
2039 : : * Return "true" if this utility statement will send output to the
2040 : : * destination.
2041 : : *
2042 : : * Generally, there should be a case here for each case in ProcessUtility
2043 : : * where "dest" is passed on.
2044 : : */
2045 : : bool
2046 : 242251 : UtilityReturnsTuples(Node *parsetree)
2047 : : {
2048 [ + + + + : 242251 : switch (nodeTag(parsetree))
+ + + ]
2049 : : {
2050 : 284 : case T_CallStmt:
2051 : : {
2052 : 284 : CallStmt *stmt = (CallStmt *) parsetree;
2053 : :
2054 : 284 : return (stmt->funcexpr->funcresulttype == RECORDOID);
2055 : : }
2056 : 4504 : case T_FetchStmt:
2057 : : {
2058 : 4504 : FetchStmt *stmt = (FetchStmt *) parsetree;
2059 : : Portal portal;
2060 : :
2061 [ + + ]: 4504 : if (stmt->ismove)
2062 : 58 : return false;
2063 : 4446 : portal = GetPortalByName(stmt->portalname);
2064 [ + + ]: 4446 : if (!PortalIsValid(portal))
2065 : 19 : return false; /* not our business to raise error */
2066 : 4427 : return portal->tupDesc ? true : false;
2067 : : }
2068 : :
2069 : 8445 : case T_ExecuteStmt:
2070 : : {
2071 : 8445 : ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2072 : : PreparedStatement *entry;
2073 : :
2074 : 8445 : entry = FetchPreparedStatement(stmt->name, false);
2075 [ - + ]: 8445 : if (!entry)
2076 : 0 : return false; /* not our business to raise error */
2077 [ + + ]: 8445 : if (entry->plansource->resultDesc)
2078 : 8374 : return true;
2079 : 71 : return false;
2080 : : }
2081 : :
2082 : 22534 : case T_ExplainStmt:
2083 : 22534 : return true;
2084 : :
2085 : 590 : case T_VariableShowStmt:
2086 : 590 : return true;
2087 : :
2088 : 291 : case T_WaitStmt:
2089 : 291 : return true;
2090 : :
2091 : 205603 : default:
2092 : 205603 : return false;
2093 : : }
2094 : : }
2095 : :
2096 : : /*
2097 : : * UtilityTupleDescriptor
2098 : : * Fetch the actual output tuple descriptor for a utility statement
2099 : : * for which UtilityReturnsTuples() previously returned "true".
2100 : : *
2101 : : * The returned descriptor is created in (or copied into) the current memory
2102 : : * context.
2103 : : */
2104 : : TupleDesc
2105 : 36333 : UtilityTupleDescriptor(Node *parsetree)
2106 : : {
2107 [ + + + + : 36333 : switch (nodeTag(parsetree))
+ + - ]
2108 : : {
2109 : 117 : case T_CallStmt:
2110 : 117 : return CallStmtResultDesc((CallStmt *) parsetree);
2111 : :
2112 : 4427 : case T_FetchStmt:
2113 : : {
2114 : 4427 : FetchStmt *stmt = (FetchStmt *) parsetree;
2115 : : Portal portal;
2116 : :
2117 [ - + ]: 4427 : if (stmt->ismove)
2118 : 0 : return NULL;
2119 : 4427 : portal = GetPortalByName(stmt->portalname);
2120 [ - + ]: 4427 : if (!PortalIsValid(portal))
2121 : 0 : return NULL; /* not our business to raise error */
2122 : 4427 : return CreateTupleDescCopy(portal->tupDesc);
2123 : : }
2124 : :
2125 : 8374 : case T_ExecuteStmt:
2126 : : {
2127 : 8374 : ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2128 : : PreparedStatement *entry;
2129 : :
2130 : 8374 : entry = FetchPreparedStatement(stmt->name, false);
2131 [ - + ]: 8374 : if (!entry)
2132 : 0 : return NULL; /* not our business to raise error */
2133 : 8374 : return FetchPreparedStatementResultDesc(entry);
2134 : : }
2135 : :
2136 : 22534 : case T_ExplainStmt:
2137 : 22534 : return ExplainResultDesc((ExplainStmt *) parsetree);
2138 : :
2139 : 590 : case T_VariableShowStmt:
2140 : : {
2141 : 590 : VariableShowStmt *n = (VariableShowStmt *) parsetree;
2142 : :
2143 : 590 : return GetPGVariableResultDesc(n->name);
2144 : : }
2145 : :
2146 : 291 : case T_WaitStmt:
2147 : 291 : return WaitStmtResultDesc((WaitStmt *) parsetree);
2148 : :
2149 : 0 : default:
2150 : 0 : return NULL;
2151 : : }
2152 : : }
2153 : :
2154 : :
2155 : : /*
2156 : : * QueryReturnsTuples
2157 : : * Return "true" if this Query will send output to the destination.
2158 : : */
2159 : : #ifdef NOT_USED
2160 : : bool
2161 : : QueryReturnsTuples(Query *parsetree)
2162 : : {
2163 : : switch (parsetree->commandType)
2164 : : {
2165 : : case CMD_SELECT:
2166 : : /* returns tuples */
2167 : : return true;
2168 : : case CMD_INSERT:
2169 : : case CMD_UPDATE:
2170 : : case CMD_DELETE:
2171 : : case CMD_MERGE:
2172 : : /* the forms with RETURNING return tuples */
2173 : : if (parsetree->returningList)
2174 : : return true;
2175 : : break;
2176 : : case CMD_UTILITY:
2177 : : return UtilityReturnsTuples(parsetree->utilityStmt);
2178 : : case CMD_UNKNOWN:
2179 : : case CMD_NOTHING:
2180 : : /* probably shouldn't get here */
2181 : : break;
2182 : : }
2183 : : return false; /* default */
2184 : : }
2185 : : #endif
2186 : :
2187 : :
2188 : : /*
2189 : : * UtilityContainsQuery
2190 : : * Return the contained Query, or NULL if there is none
2191 : : *
2192 : : * Certain utility statements, such as EXPLAIN, contain a plannable Query.
2193 : : * This function encapsulates knowledge of exactly which ones do.
2194 : : * We assume it is invoked only on already-parse-analyzed statements
2195 : : * (else the contained parsetree isn't a Query yet).
2196 : : *
2197 : : * In some cases (currently, only EXPLAIN of CREATE TABLE AS/SELECT INTO and
2198 : : * CREATE MATERIALIZED VIEW), potentially Query-containing utility statements
2199 : : * can be nested. This function will drill down to a non-utility Query, or
2200 : : * return NULL if none.
2201 : : */
2202 : : Query *
2203 : 25270 : UtilityContainsQuery(Node *parsetree)
2204 : : {
2205 : : Query *qry;
2206 : :
2207 [ + + + + ]: 25270 : switch (nodeTag(parsetree))
2208 : : {
2209 : 1876 : case T_DeclareCursorStmt:
2210 : 1876 : qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
2211 [ - + ]: 1876 : if (qry->commandType == CMD_UTILITY)
2212 : 0 : return UtilityContainsQuery(qry->utilityStmt);
2213 : 1876 : return qry;
2214 : :
2215 : 10886 : case T_ExplainStmt:
2216 : 10886 : qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
2217 [ + + ]: 10886 : if (qry->commandType == CMD_UTILITY)
2218 : 72 : return UtilityContainsQuery(qry->utilityStmt);
2219 : 10814 : return qry;
2220 : :
2221 : 60 : case T_CreateTableAsStmt:
2222 : 60 : qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
2223 [ - + ]: 60 : if (qry->commandType == CMD_UTILITY)
2224 : 0 : return UtilityContainsQuery(qry->utilityStmt);
2225 : 60 : return qry;
2226 : :
2227 : 12448 : default:
2228 : 12448 : return NULL;
2229 : : }
2230 : : }
2231 : :
2232 : :
2233 : : /*
2234 : : * AlterObjectTypeCommandTag
2235 : : * helper function for CreateCommandTag
2236 : : *
2237 : : * This covers most cases where ALTER is used with an ObjectType enum.
2238 : : */
2239 : : static CommandTag
2240 : 22318 : AlterObjectTypeCommandTag(ObjectType objtype)
2241 : : {
2242 : : CommandTag tag;
2243 : :
2244 [ + + - + : 22318 : switch (objtype)
- + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ - ]
2245 : : {
2246 : 120 : case OBJECT_AGGREGATE:
2247 : 120 : tag = CMDTAG_ALTER_AGGREGATE;
2248 : 120 : break;
2249 : 16 : case OBJECT_ATTRIBUTE:
2250 : 16 : tag = CMDTAG_ALTER_TYPE;
2251 : 16 : break;
2252 : 0 : case OBJECT_CAST:
2253 : 0 : tag = CMDTAG_ALTER_CAST;
2254 : 0 : break;
2255 : 27 : case OBJECT_COLLATION:
2256 : 27 : tag = CMDTAG_ALTER_COLLATION;
2257 : 27 : break;
2258 : 0 : case OBJECT_COLUMN:
2259 : 0 : tag = CMDTAG_ALTER_TABLE;
2260 : 0 : break;
2261 : 48 : case OBJECT_CONVERSION:
2262 : 48 : tag = CMDTAG_ALTER_CONVERSION;
2263 : 48 : break;
2264 : 59 : case OBJECT_DATABASE:
2265 : 59 : tag = CMDTAG_ALTER_DATABASE;
2266 : 59 : break;
2267 : 38 : case OBJECT_DOMAIN:
2268 : : case OBJECT_DOMCONSTRAINT:
2269 : 38 : tag = CMDTAG_ALTER_DOMAIN;
2270 : 38 : break;
2271 : 6 : case OBJECT_EXTENSION:
2272 : 6 : tag = CMDTAG_ALTER_EXTENSION;
2273 : 6 : break;
2274 : 29 : case OBJECT_FDW:
2275 : 29 : tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
2276 : 29 : break;
2277 : 61 : case OBJECT_FOREIGN_SERVER:
2278 : 61 : tag = CMDTAG_ALTER_SERVER;
2279 : 61 : break;
2280 : 363 : case OBJECT_FOREIGN_TABLE:
2281 : 363 : tag = CMDTAG_ALTER_FOREIGN_TABLE;
2282 : 363 : break;
2283 : 368 : case OBJECT_FUNCTION:
2284 : 368 : tag = CMDTAG_ALTER_FUNCTION;
2285 : 368 : break;
2286 : 568 : case OBJECT_INDEX:
2287 : 568 : tag = CMDTAG_ALTER_INDEX;
2288 : 568 : break;
2289 : 32 : case OBJECT_LANGUAGE:
2290 : 32 : tag = CMDTAG_ALTER_LANGUAGE;
2291 : 32 : break;
2292 : 9 : case OBJECT_LARGEOBJECT:
2293 : 9 : tag = CMDTAG_ALTER_LARGE_OBJECT;
2294 : 9 : break;
2295 : 67 : case OBJECT_OPCLASS:
2296 : 67 : tag = CMDTAG_ALTER_OPERATOR_CLASS;
2297 : 67 : break;
2298 : 39 : case OBJECT_OPERATOR:
2299 : 39 : tag = CMDTAG_ALTER_OPERATOR;
2300 : 39 : break;
2301 : 71 : case OBJECT_OPFAMILY:
2302 : 71 : tag = CMDTAG_ALTER_OPERATOR_FAMILY;
2303 : 71 : break;
2304 : 20 : case OBJECT_POLICY:
2305 : 20 : tag = CMDTAG_ALTER_POLICY;
2306 : 20 : break;
2307 : 12 : case OBJECT_PROCEDURE:
2308 : 12 : tag = CMDTAG_ALTER_PROCEDURE;
2309 : 12 : break;
2310 : 20 : case OBJECT_ROLE:
2311 : 20 : tag = CMDTAG_ALTER_ROLE;
2312 : 20 : break;
2313 : 16 : case OBJECT_ROUTINE:
2314 : 16 : tag = CMDTAG_ALTER_ROUTINE;
2315 : 16 : break;
2316 : 30 : case OBJECT_RULE:
2317 : 30 : tag = CMDTAG_ALTER_RULE;
2318 : 30 : break;
2319 : 50 : case OBJECT_SCHEMA:
2320 : 50 : tag = CMDTAG_ALTER_SCHEMA;
2321 : 50 : break;
2322 : 63 : case OBJECT_SEQUENCE:
2323 : 63 : tag = CMDTAG_ALTER_SEQUENCE;
2324 : 63 : break;
2325 : 19366 : case OBJECT_TABLE:
2326 : : case OBJECT_TABCONSTRAINT:
2327 : 19366 : tag = CMDTAG_ALTER_TABLE;
2328 : 19366 : break;
2329 : 12 : case OBJECT_TABLESPACE:
2330 : 12 : tag = CMDTAG_ALTER_TABLESPACE;
2331 : 12 : break;
2332 : 43 : case OBJECT_TRIGGER:
2333 : 43 : tag = CMDTAG_ALTER_TRIGGER;
2334 : 43 : break;
2335 : 17 : case OBJECT_EVENT_TRIGGER:
2336 : 17 : tag = CMDTAG_ALTER_EVENT_TRIGGER;
2337 : 17 : break;
2338 : 52 : case OBJECT_TSCONFIGURATION:
2339 : 52 : tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
2340 : 52 : break;
2341 : 57 : case OBJECT_TSDICTIONARY:
2342 : 57 : tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
2343 : 57 : break;
2344 : 20 : case OBJECT_TSPARSER:
2345 : 20 : tag = CMDTAG_ALTER_TEXT_SEARCH_PARSER;
2346 : 20 : break;
2347 : 20 : case OBJECT_TSTEMPLATE:
2348 : 20 : tag = CMDTAG_ALTER_TEXT_SEARCH_TEMPLATE;
2349 : 20 : break;
2350 : 226 : case OBJECT_TYPE:
2351 : 226 : tag = CMDTAG_ALTER_TYPE;
2352 : 226 : break;
2353 : 167 : case OBJECT_VIEW:
2354 : 167 : tag = CMDTAG_ALTER_VIEW;
2355 : 167 : break;
2356 : 48 : case OBJECT_MATVIEW:
2357 : 48 : tag = CMDTAG_ALTER_MATERIALIZED_VIEW;
2358 : 48 : break;
2359 : 50 : case OBJECT_PUBLICATION:
2360 : 50 : tag = CMDTAG_ALTER_PUBLICATION;
2361 : 50 : break;
2362 : 52 : case OBJECT_SUBSCRIPTION:
2363 : 52 : tag = CMDTAG_ALTER_SUBSCRIPTION;
2364 : 52 : break;
2365 : 56 : case OBJECT_STATISTIC_EXT:
2366 : 56 : tag = CMDTAG_ALTER_STATISTICS;
2367 : 56 : break;
2368 : 0 : default:
2369 : 0 : tag = CMDTAG_UNKNOWN;
2370 : 0 : break;
2371 : : }
2372 : :
2373 : 22318 : return tag;
2374 : : }
2375 : :
2376 : : /*
2377 : : * CreateCommandTag
2378 : : * utility to get a CommandTag for the command operation,
2379 : : * given either a raw (un-analyzed) parsetree, an analyzed Query,
2380 : : * or a PlannedStmt.
2381 : : *
2382 : : * This must handle all command types, but since the vast majority
2383 : : * of 'em are utility commands, it seems sensible to keep it here.
2384 : : */
2385 : : CommandTag
2386 : 506106 : CreateCommandTag(Node *parsetree)
2387 : : {
2388 : : CommandTag tag;
2389 : :
2390 [ - + + + : 506106 : switch (nodeTag(parsetree))
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ - ]
2391 : : {
2392 : : /* recurse if we're given a RawStmt */
2393 : 0 : case T_RawStmt:
2394 : 0 : tag = CreateCommandTag(((RawStmt *) parsetree)->stmt);
2395 : 0 : break;
2396 : :
2397 : : /* raw plannable queries */
2398 : 44531 : case T_InsertStmt:
2399 : 44531 : tag = CMDTAG_INSERT;
2400 : 44531 : break;
2401 : :
2402 : 2648 : case T_DeleteStmt:
2403 : 2648 : tag = CMDTAG_DELETE;
2404 : 2648 : break;
2405 : :
2406 : 8171 : case T_UpdateStmt:
2407 : 8171 : tag = CMDTAG_UPDATE;
2408 : 8171 : break;
2409 : :
2410 : 1215 : case T_MergeStmt:
2411 : 1215 : tag = CMDTAG_MERGE;
2412 : 1215 : break;
2413 : :
2414 : 200807 : case T_SelectStmt:
2415 : 200807 : tag = CMDTAG_SELECT;
2416 : 200807 : break;
2417 : :
2418 : 2310 : case T_PLAssignStmt:
2419 : 2310 : tag = CMDTAG_SELECT;
2420 : 2310 : break;
2421 : :
2422 : : /* utility statements --- same whether raw or cooked */
2423 : 26895 : case T_TransactionStmt:
2424 : : {
2425 : 26895 : TransactionStmt *stmt = (TransactionStmt *) parsetree;
2426 : :
2427 [ + + + + : 26895 : switch (stmt->kind)
+ + + + +
- ]
2428 : : {
2429 : 11542 : case TRANS_STMT_BEGIN:
2430 : 11542 : tag = CMDTAG_BEGIN;
2431 : 11542 : break;
2432 : :
2433 : 902 : case TRANS_STMT_START:
2434 : 902 : tag = CMDTAG_START_TRANSACTION;
2435 : 902 : break;
2436 : :
2437 : 9603 : case TRANS_STMT_COMMIT:
2438 : 9603 : tag = CMDTAG_COMMIT;
2439 : 9603 : break;
2440 : :
2441 : 2781 : case TRANS_STMT_ROLLBACK:
2442 : : case TRANS_STMT_ROLLBACK_TO:
2443 : 2781 : tag = CMDTAG_ROLLBACK;
2444 : 2781 : break;
2445 : :
2446 : 1188 : case TRANS_STMT_SAVEPOINT:
2447 : 1188 : tag = CMDTAG_SAVEPOINT;
2448 : 1188 : break;
2449 : :
2450 : 194 : case TRANS_STMT_RELEASE:
2451 : 194 : tag = CMDTAG_RELEASE;
2452 : 194 : break;
2453 : :
2454 : 368 : case TRANS_STMT_PREPARE:
2455 : 368 : tag = CMDTAG_PREPARE_TRANSACTION;
2456 : 368 : break;
2457 : :
2458 : 266 : case TRANS_STMT_COMMIT_PREPARED:
2459 : 266 : tag = CMDTAG_COMMIT_PREPARED;
2460 : 266 : break;
2461 : :
2462 : 51 : case TRANS_STMT_ROLLBACK_PREPARED:
2463 : 51 : tag = CMDTAG_ROLLBACK_PREPARED;
2464 : 51 : break;
2465 : :
2466 : 0 : default:
2467 : 0 : tag = CMDTAG_UNKNOWN;
2468 : 0 : break;
2469 : : }
2470 : : }
2471 : 26895 : break;
2472 : :
2473 : 2837 : case T_DeclareCursorStmt:
2474 : 2837 : tag = CMDTAG_DECLARE_CURSOR;
2475 : 2837 : break;
2476 : :
2477 : 1329 : case T_ClosePortalStmt:
2478 : : {
2479 : 1329 : ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
2480 : :
2481 [ + + ]: 1329 : if (stmt->portalname == NULL)
2482 : 8 : tag = CMDTAG_CLOSE_CURSOR_ALL;
2483 : : else
2484 : 1321 : tag = CMDTAG_CLOSE_CURSOR;
2485 : : }
2486 : 1329 : break;
2487 : :
2488 : 4659 : case T_FetchStmt:
2489 : : {
2490 : 4659 : FetchStmt *stmt = (FetchStmt *) parsetree;
2491 : :
2492 [ + + ]: 4659 : tag = (stmt->ismove) ? CMDTAG_MOVE : CMDTAG_FETCH;
2493 : : }
2494 : 4659 : break;
2495 : :
2496 : 1037 : case T_CreateDomainStmt:
2497 : 1037 : tag = CMDTAG_CREATE_DOMAIN;
2498 : 1037 : break;
2499 : :
2500 : 755 : case T_CreateSchemaStmt:
2501 : 755 : tag = CMDTAG_CREATE_SCHEMA;
2502 : 755 : break;
2503 : :
2504 : 25555 : case T_CreateStmt:
2505 : 25555 : tag = CMDTAG_CREATE_TABLE;
2506 : 25555 : break;
2507 : :
2508 : 82 : case T_CreateTableSpaceStmt:
2509 : 82 : tag = CMDTAG_CREATE_TABLESPACE;
2510 : 82 : break;
2511 : :
2512 : 49 : case T_DropTableSpaceStmt:
2513 : 49 : tag = CMDTAG_DROP_TABLESPACE;
2514 : 49 : break;
2515 : :
2516 : 19 : case T_AlterTableSpaceOptionsStmt:
2517 : 19 : tag = CMDTAG_ALTER_TABLESPACE;
2518 : 19 : break;
2519 : :
2520 : 361 : case T_CreateExtensionStmt:
2521 : 361 : tag = CMDTAG_CREATE_EXTENSION;
2522 : 361 : break;
2523 : :
2524 : 19 : case T_AlterExtensionStmt:
2525 : 19 : tag = CMDTAG_ALTER_EXTENSION;
2526 : 19 : break;
2527 : :
2528 : 95 : case T_AlterExtensionContentsStmt:
2529 : 95 : tag = CMDTAG_ALTER_EXTENSION;
2530 : 95 : break;
2531 : :
2532 : 146 : case T_CreateFdwStmt:
2533 : 146 : tag = CMDTAG_CREATE_FOREIGN_DATA_WRAPPER;
2534 : 146 : break;
2535 : :
2536 : 97 : case T_AlterFdwStmt:
2537 : 97 : tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
2538 : 97 : break;
2539 : :
2540 : 196 : case T_CreateForeignServerStmt:
2541 : 196 : tag = CMDTAG_CREATE_SERVER;
2542 : 196 : break;
2543 : :
2544 : 129 : case T_AlterForeignServerStmt:
2545 : 129 : tag = CMDTAG_ALTER_SERVER;
2546 : 129 : break;
2547 : :
2548 : 176 : case T_CreateUserMappingStmt:
2549 : 176 : tag = CMDTAG_CREATE_USER_MAPPING;
2550 : 176 : break;
2551 : :
2552 : 73 : case T_AlterUserMappingStmt:
2553 : 73 : tag = CMDTAG_ALTER_USER_MAPPING;
2554 : 73 : break;
2555 : :
2556 : 79 : case T_DropUserMappingStmt:
2557 : 79 : tag = CMDTAG_DROP_USER_MAPPING;
2558 : 79 : break;
2559 : :
2560 : 274 : case T_CreateForeignTableStmt:
2561 : 274 : tag = CMDTAG_CREATE_FOREIGN_TABLE;
2562 : 274 : break;
2563 : :
2564 : 28 : case T_ImportForeignSchemaStmt:
2565 : 28 : tag = CMDTAG_IMPORT_FOREIGN_SCHEMA;
2566 : 28 : break;
2567 : :
2568 : 17714 : case T_DropStmt:
2569 [ + + + + : 17714 : switch (((DropStmt *) parsetree)->removeType)
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ - ]
2570 : : {
2571 : 10115 : case OBJECT_TABLE:
2572 : 10115 : tag = CMDTAG_DROP_TABLE;
2573 : 10115 : break;
2574 : 123 : case OBJECT_SEQUENCE:
2575 : 123 : tag = CMDTAG_DROP_SEQUENCE;
2576 : 123 : break;
2577 : 649 : case OBJECT_VIEW:
2578 : 649 : tag = CMDTAG_DROP_VIEW;
2579 : 649 : break;
2580 : 84 : case OBJECT_MATVIEW:
2581 : 84 : tag = CMDTAG_DROP_MATERIALIZED_VIEW;
2582 : 84 : break;
2583 : 566 : case OBJECT_INDEX:
2584 : 566 : tag = CMDTAG_DROP_INDEX;
2585 : 566 : break;
2586 : 470 : case OBJECT_TYPE:
2587 : 470 : tag = CMDTAG_DROP_TYPE;
2588 : 470 : break;
2589 : 416 : case OBJECT_DOMAIN:
2590 : 416 : tag = CMDTAG_DROP_DOMAIN;
2591 : 416 : break;
2592 : 58 : case OBJECT_COLLATION:
2593 : 58 : tag = CMDTAG_DROP_COLLATION;
2594 : 58 : break;
2595 : 24 : case OBJECT_CONVERSION:
2596 : 24 : tag = CMDTAG_DROP_CONVERSION;
2597 : 24 : break;
2598 : 429 : case OBJECT_SCHEMA:
2599 : 429 : tag = CMDTAG_DROP_SCHEMA;
2600 : 429 : break;
2601 : 12 : case OBJECT_TSPARSER:
2602 : 12 : tag = CMDTAG_DROP_TEXT_SEARCH_PARSER;
2603 : 12 : break;
2604 : 16 : case OBJECT_TSDICTIONARY:
2605 : 16 : tag = CMDTAG_DROP_TEXT_SEARCH_DICTIONARY;
2606 : 16 : break;
2607 : 12 : case OBJECT_TSTEMPLATE:
2608 : 12 : tag = CMDTAG_DROP_TEXT_SEARCH_TEMPLATE;
2609 : 12 : break;
2610 : 20 : case OBJECT_TSCONFIGURATION:
2611 : 20 : tag = CMDTAG_DROP_TEXT_SEARCH_CONFIGURATION;
2612 : 20 : break;
2613 : 114 : case OBJECT_FOREIGN_TABLE:
2614 : 114 : tag = CMDTAG_DROP_FOREIGN_TABLE;
2615 : 114 : break;
2616 : 124 : case OBJECT_EXTENSION:
2617 : 124 : tag = CMDTAG_DROP_EXTENSION;
2618 : 124 : break;
2619 : 2366 : case OBJECT_FUNCTION:
2620 : 2366 : tag = CMDTAG_DROP_FUNCTION;
2621 : 2366 : break;
2622 : 98 : case OBJECT_PROCEDURE:
2623 : 98 : tag = CMDTAG_DROP_PROCEDURE;
2624 : 98 : break;
2625 : 20 : case OBJECT_ROUTINE:
2626 : 20 : tag = CMDTAG_DROP_ROUTINE;
2627 : 20 : break;
2628 : 69 : case OBJECT_AGGREGATE:
2629 : 69 : tag = CMDTAG_DROP_AGGREGATE;
2630 : 69 : break;
2631 : 120 : case OBJECT_OPERATOR:
2632 : 120 : tag = CMDTAG_DROP_OPERATOR;
2633 : 120 : break;
2634 : 17 : case OBJECT_LANGUAGE:
2635 : 17 : tag = CMDTAG_DROP_LANGUAGE;
2636 : 17 : break;
2637 : 54 : case OBJECT_CAST:
2638 : 54 : tag = CMDTAG_DROP_CAST;
2639 : 54 : break;
2640 : 502 : case OBJECT_TRIGGER:
2641 : 502 : tag = CMDTAG_DROP_TRIGGER;
2642 : 502 : break;
2643 : 81 : case OBJECT_EVENT_TRIGGER:
2644 : 81 : tag = CMDTAG_DROP_EVENT_TRIGGER;
2645 : 81 : break;
2646 : 176 : case OBJECT_RULE:
2647 : 176 : tag = CMDTAG_DROP_RULE;
2648 : 176 : break;
2649 : 122 : case OBJECT_FDW:
2650 : 122 : tag = CMDTAG_DROP_FOREIGN_DATA_WRAPPER;
2651 : 122 : break;
2652 : 111 : case OBJECT_FOREIGN_SERVER:
2653 : 111 : tag = CMDTAG_DROP_SERVER;
2654 : 111 : break;
2655 : 37 : case OBJECT_OPCLASS:
2656 : 37 : tag = CMDTAG_DROP_OPERATOR_CLASS;
2657 : 37 : break;
2658 : 85 : case OBJECT_OPFAMILY:
2659 : 85 : tag = CMDTAG_DROP_OPERATOR_FAMILY;
2660 : 85 : break;
2661 : 137 : case OBJECT_POLICY:
2662 : 137 : tag = CMDTAG_DROP_POLICY;
2663 : 137 : break;
2664 : 8 : case OBJECT_TRANSFORM:
2665 : 8 : tag = CMDTAG_DROP_TRANSFORM;
2666 : 8 : break;
2667 : 24 : case OBJECT_ACCESS_METHOD:
2668 : 24 : tag = CMDTAG_DROP_ACCESS_METHOD;
2669 : 24 : break;
2670 : 314 : case OBJECT_PUBLICATION:
2671 : 314 : tag = CMDTAG_DROP_PUBLICATION;
2672 : 314 : break;
2673 : 141 : case OBJECT_STATISTIC_EXT:
2674 : 141 : tag = CMDTAG_DROP_STATISTICS;
2675 : 141 : break;
2676 : 0 : default:
2677 : 0 : tag = CMDTAG_UNKNOWN;
2678 : : }
2679 : 17714 : break;
2680 : :
2681 : 1182 : case T_TruncateStmt:
2682 : 1182 : tag = CMDTAG_TRUNCATE_TABLE;
2683 : 1182 : break;
2684 : :
2685 : 4365 : case T_CommentStmt:
2686 : 4365 : tag = CMDTAG_COMMENT;
2687 : 4365 : break;
2688 : :
2689 : 69 : case T_SecLabelStmt:
2690 : 69 : tag = CMDTAG_SECURITY_LABEL;
2691 : 69 : break;
2692 : :
2693 : 6571 : case T_CopyStmt:
2694 : 6571 : tag = CMDTAG_COPY;
2695 : 6571 : break;
2696 : :
2697 : 1031 : case T_RenameStmt:
2698 : :
2699 : : /*
2700 : : * When the column is renamed, the command tag is created from its
2701 : : * relation type
2702 : : */
2703 [ + + ]: 1031 : tag = AlterObjectTypeCommandTag(((RenameStmt *) parsetree)->renameType == OBJECT_COLUMN ?
2704 : : ((RenameStmt *) parsetree)->relationType :
2705 : : ((RenameStmt *) parsetree)->renameType);
2706 : 1031 : break;
2707 : :
2708 : 23 : case T_AlterObjectDependsStmt:
2709 : 23 : tag = AlterObjectTypeCommandTag(((AlterObjectDependsStmt *) parsetree)->objectType);
2710 : 23 : break;
2711 : :
2712 : 277 : case T_AlterObjectSchemaStmt:
2713 : 277 : tag = AlterObjectTypeCommandTag(((AlterObjectSchemaStmt *) parsetree)->objectType);
2714 : 277 : break;
2715 : :
2716 : 909 : case T_AlterOwnerStmt:
2717 : 909 : tag = AlterObjectTypeCommandTag(((AlterOwnerStmt *) parsetree)->objectType);
2718 : 909 : break;
2719 : :
2720 : 16 : case T_AlterTableMoveAllStmt:
2721 : 16 : tag = AlterObjectTypeCommandTag(((AlterTableMoveAllStmt *) parsetree)->objtype);
2722 : 16 : break;
2723 : :
2724 : 20062 : case T_AlterTableStmt:
2725 : 20062 : tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->objtype);
2726 : 20062 : break;
2727 : :
2728 : 197 : case T_AlterDomainStmt:
2729 : 197 : tag = CMDTAG_ALTER_DOMAIN;
2730 : 197 : break;
2731 : :
2732 : 132 : case T_AlterFunctionStmt:
2733 [ + + - - ]: 132 : switch (((AlterFunctionStmt *) parsetree)->objtype)
2734 : : {
2735 : 120 : case OBJECT_FUNCTION:
2736 : 120 : tag = CMDTAG_ALTER_FUNCTION;
2737 : 120 : break;
2738 : 12 : case OBJECT_PROCEDURE:
2739 : 12 : tag = CMDTAG_ALTER_PROCEDURE;
2740 : 12 : break;
2741 : 0 : case OBJECT_ROUTINE:
2742 : 0 : tag = CMDTAG_ALTER_ROUTINE;
2743 : 0 : break;
2744 : 0 : default:
2745 : 0 : tag = CMDTAG_UNKNOWN;
2746 : : }
2747 : 132 : break;
2748 : :
2749 : 7883 : case T_GrantStmt:
2750 : : {
2751 : 7883 : GrantStmt *stmt = (GrantStmt *) parsetree;
2752 : :
2753 [ + + ]: 7883 : tag = (stmt->is_grant) ? CMDTAG_GRANT : CMDTAG_REVOKE;
2754 : : }
2755 : 7883 : break;
2756 : :
2757 : 400 : case T_GrantRoleStmt:
2758 : : {
2759 : 400 : GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;
2760 : :
2761 [ + + ]: 400 : tag = (stmt->is_grant) ? CMDTAG_GRANT_ROLE : CMDTAG_REVOKE_ROLE;
2762 : : }
2763 : 400 : break;
2764 : :
2765 : 148 : case T_AlterDefaultPrivilegesStmt:
2766 : 148 : tag = CMDTAG_ALTER_DEFAULT_PRIVILEGES;
2767 : 148 : break;
2768 : :
2769 : 5066 : case T_DefineStmt:
2770 [ + + + + : 5066 : switch (((DefineStmt *) parsetree)->kind)
+ + + + -
- ]
2771 : : {
2772 : 574 : case OBJECT_AGGREGATE:
2773 : 574 : tag = CMDTAG_CREATE_AGGREGATE;
2774 : 574 : break;
2775 : 279 : case OBJECT_OPERATOR:
2776 : 279 : tag = CMDTAG_CREATE_OPERATOR;
2777 : 279 : break;
2778 : 182 : case OBJECT_TYPE:
2779 : 182 : tag = CMDTAG_CREATE_TYPE;
2780 : 182 : break;
2781 : 26 : case OBJECT_TSPARSER:
2782 : 26 : tag = CMDTAG_CREATE_TEXT_SEARCH_PARSER;
2783 : 26 : break;
2784 : 1858 : case OBJECT_TSDICTIONARY:
2785 : 1858 : tag = CMDTAG_CREATE_TEXT_SEARCH_DICTIONARY;
2786 : 1858 : break;
2787 : 83 : case OBJECT_TSTEMPLATE:
2788 : 83 : tag = CMDTAG_CREATE_TEXT_SEARCH_TEMPLATE;
2789 : 83 : break;
2790 : 1831 : case OBJECT_TSCONFIGURATION:
2791 : 1831 : tag = CMDTAG_CREATE_TEXT_SEARCH_CONFIGURATION;
2792 : 1831 : break;
2793 : 233 : case OBJECT_COLLATION:
2794 : 233 : tag = CMDTAG_CREATE_COLLATION;
2795 : 233 : break;
2796 : 0 : case OBJECT_ACCESS_METHOD:
2797 : 0 : tag = CMDTAG_CREATE_ACCESS_METHOD;
2798 : 0 : break;
2799 : 0 : default:
2800 : 0 : tag = CMDTAG_UNKNOWN;
2801 : : }
2802 : 5066 : break;
2803 : :
2804 : 2387 : case T_CompositeTypeStmt:
2805 : 2387 : tag = CMDTAG_CREATE_TYPE;
2806 : 2387 : break;
2807 : :
2808 : 166 : case T_CreateEnumStmt:
2809 : 166 : tag = CMDTAG_CREATE_TYPE;
2810 : 166 : break;
2811 : :
2812 : 151 : case T_CreateRangeStmt:
2813 : 151 : tag = CMDTAG_CREATE_TYPE;
2814 : 151 : break;
2815 : :
2816 : 252 : case T_AlterEnumStmt:
2817 : 252 : tag = CMDTAG_ALTER_TYPE;
2818 : 252 : break;
2819 : :
2820 : 10695 : case T_ViewStmt:
2821 : 10695 : tag = CMDTAG_CREATE_VIEW;
2822 : 10695 : break;
2823 : :
2824 : 9335 : case T_CreateFunctionStmt:
2825 [ + + ]: 9335 : if (((CreateFunctionStmt *) parsetree)->is_procedure)
2826 : 233 : tag = CMDTAG_CREATE_PROCEDURE;
2827 : : else
2828 : 9102 : tag = CMDTAG_CREATE_FUNCTION;
2829 : 9335 : break;
2830 : :
2831 : 4456 : case T_IndexStmt:
2832 : 4456 : tag = CMDTAG_CREATE_INDEX;
2833 : 4456 : break;
2834 : :
2835 : 747 : case T_RuleStmt:
2836 : 747 : tag = CMDTAG_CREATE_RULE;
2837 : 747 : break;
2838 : :
2839 : 443 : case T_CreateSeqStmt:
2840 : 443 : tag = CMDTAG_CREATE_SEQUENCE;
2841 : 443 : break;
2842 : :
2843 : 164 : case T_AlterSeqStmt:
2844 : 164 : tag = CMDTAG_ALTER_SEQUENCE;
2845 : 164 : break;
2846 : :
2847 : 703 : case T_DoStmt:
2848 : 703 : tag = CMDTAG_DO;
2849 : 703 : break;
2850 : :
2851 : 459 : case T_CreatedbStmt:
2852 : 459 : tag = CMDTAG_CREATE_DATABASE;
2853 : 459 : break;
2854 : :
2855 : 745 : case T_AlterDatabaseStmt:
2856 : : case T_AlterDatabaseRefreshCollStmt:
2857 : : case T_AlterDatabaseSetStmt:
2858 : 745 : tag = CMDTAG_ALTER_DATABASE;
2859 : 745 : break;
2860 : :
2861 : 82 : case T_DropdbStmt:
2862 : 82 : tag = CMDTAG_DROP_DATABASE;
2863 : 82 : break;
2864 : :
2865 : 62 : case T_NotifyStmt:
2866 : 62 : tag = CMDTAG_NOTIFY;
2867 : 62 : break;
2868 : :
2869 : 52 : case T_ListenStmt:
2870 : 52 : tag = CMDTAG_LISTEN;
2871 : 52 : break;
2872 : :
2873 : 62 : case T_UnlistenStmt:
2874 : 62 : tag = CMDTAG_UNLISTEN;
2875 : 62 : break;
2876 : :
2877 : 50 : case T_LoadStmt:
2878 : 50 : tag = CMDTAG_LOAD;
2879 : 50 : break;
2880 : :
2881 : 301 : case T_CallStmt:
2882 : 301 : tag = CMDTAG_CALL;
2883 : 301 : break;
2884 : :
2885 : 8696 : case T_VacuumStmt:
2886 [ + + ]: 8696 : if (((VacuumStmt *) parsetree)->is_vacuumcmd)
2887 : 5549 : tag = CMDTAG_VACUUM;
2888 : : else
2889 : 3147 : tag = CMDTAG_ANALYZE;
2890 : 8696 : break;
2891 : :
2892 : 269 : case T_RepackStmt:
2893 [ + + ]: 269 : if (((RepackStmt *) parsetree)->command == REPACK_COMMAND_CLUSTER)
2894 : 175 : tag = CMDTAG_CLUSTER;
2895 : : else
2896 : 94 : tag = CMDTAG_REPACK;
2897 : 269 : break;
2898 : :
2899 : 17100 : case T_ExplainStmt:
2900 : 17100 : tag = CMDTAG_EXPLAIN;
2901 : 17100 : break;
2902 : :
2903 : 1156 : case T_CreateTableAsStmt:
2904 [ + + - ]: 1156 : switch (((CreateTableAsStmt *) parsetree)->objtype)
2905 : : {
2906 : 840 : case OBJECT_TABLE:
2907 [ - + ]: 840 : if (((CreateTableAsStmt *) parsetree)->is_select_into)
2908 : 0 : tag = CMDTAG_SELECT_INTO;
2909 : : else
2910 : 840 : tag = CMDTAG_CREATE_TABLE_AS;
2911 : 840 : break;
2912 : 316 : case OBJECT_MATVIEW:
2913 : 316 : tag = CMDTAG_CREATE_MATERIALIZED_VIEW;
2914 : 316 : break;
2915 : 0 : default:
2916 : 0 : tag = CMDTAG_UNKNOWN;
2917 : : }
2918 : 1156 : break;
2919 : :
2920 : 177 : case T_RefreshMatViewStmt:
2921 : 177 : tag = CMDTAG_REFRESH_MATERIALIZED_VIEW;
2922 : 177 : break;
2923 : :
2924 : 140 : case T_AlterSystemStmt:
2925 : 140 : tag = CMDTAG_ALTER_SYSTEM;
2926 : 140 : break;
2927 : :
2928 : 18131 : case T_VariableSetStmt:
2929 [ + + - ]: 18131 : switch (((VariableSetStmt *) parsetree)->kind)
2930 : : {
2931 : 14798 : case VAR_SET_VALUE:
2932 : : case VAR_SET_CURRENT:
2933 : : case VAR_SET_DEFAULT:
2934 : : case VAR_SET_MULTI:
2935 : 14798 : tag = CMDTAG_SET;
2936 : 14798 : break;
2937 : 3333 : case VAR_RESET:
2938 : : case VAR_RESET_ALL:
2939 : 3333 : tag = CMDTAG_RESET;
2940 : 3333 : break;
2941 : 0 : default:
2942 : 0 : tag = CMDTAG_UNKNOWN;
2943 : : }
2944 : 18131 : break;
2945 : :
2946 : 578 : case T_VariableShowStmt:
2947 : 578 : tag = CMDTAG_SHOW;
2948 : 578 : break;
2949 : :
2950 : 24 : case T_DiscardStmt:
2951 [ + + + + : 24 : switch (((DiscardStmt *) parsetree)->target)
- ]
2952 : : {
2953 : 4 : case DISCARD_ALL:
2954 : 4 : tag = CMDTAG_DISCARD_ALL;
2955 : 4 : break;
2956 : 3 : case DISCARD_PLANS:
2957 : 3 : tag = CMDTAG_DISCARD_PLANS;
2958 : 3 : break;
2959 : 9 : case DISCARD_TEMP:
2960 : 9 : tag = CMDTAG_DISCARD_TEMP;
2961 : 9 : break;
2962 : 8 : case DISCARD_SEQUENCES:
2963 : 8 : tag = CMDTAG_DISCARD_SEQUENCES;
2964 : 8 : break;
2965 : 0 : default:
2966 : 0 : tag = CMDTAG_UNKNOWN;
2967 : : }
2968 : 24 : break;
2969 : :
2970 : 20 : case T_CreateTransformStmt:
2971 : 20 : tag = CMDTAG_CREATE_TRANSFORM;
2972 : 20 : break;
2973 : :
2974 : 2059 : case T_CreateTrigStmt:
2975 : 2059 : tag = CMDTAG_CREATE_TRIGGER;
2976 : 2059 : break;
2977 : :
2978 : 128 : case T_CreateEventTrigStmt:
2979 : 128 : tag = CMDTAG_CREATE_EVENT_TRIGGER;
2980 : 128 : break;
2981 : :
2982 : 31 : case T_AlterEventTrigStmt:
2983 : 31 : tag = CMDTAG_ALTER_EVENT_TRIGGER;
2984 : 31 : break;
2985 : :
2986 : 9 : case T_CreatePLangStmt:
2987 : 9 : tag = CMDTAG_CREATE_LANGUAGE;
2988 : 9 : break;
2989 : :
2990 : 1292 : case T_CreateRoleStmt:
2991 : 1292 : tag = CMDTAG_CREATE_ROLE;
2992 : 1292 : break;
2993 : :
2994 : 294 : case T_AlterRoleStmt:
2995 : 294 : tag = CMDTAG_ALTER_ROLE;
2996 : 294 : break;
2997 : :
2998 : 52 : case T_AlterRoleSetStmt:
2999 : 52 : tag = CMDTAG_ALTER_ROLE;
3000 : 52 : break;
3001 : :
3002 : 1207 : case T_DropRoleStmt:
3003 : 1207 : tag = CMDTAG_DROP_ROLE;
3004 : 1207 : break;
3005 : :
3006 : 108 : case T_DropOwnedStmt:
3007 : 108 : tag = CMDTAG_DROP_OWNED;
3008 : 108 : break;
3009 : :
3010 : 39 : case T_ReassignOwnedStmt:
3011 : 39 : tag = CMDTAG_REASSIGN_OWNED;
3012 : 39 : break;
3013 : :
3014 : 600 : case T_LockStmt:
3015 : 600 : tag = CMDTAG_LOCK_TABLE;
3016 : 600 : break;
3017 : :
3018 : 71 : case T_ConstraintsSetStmt:
3019 : 71 : tag = CMDTAG_SET_CONSTRAINTS;
3020 : 71 : break;
3021 : :
3022 : 159 : case T_CheckPointStmt:
3023 : 159 : tag = CMDTAG_CHECKPOINT;
3024 : 159 : break;
3025 : :
3026 : 861 : case T_ReindexStmt:
3027 : 861 : tag = CMDTAG_REINDEX;
3028 : 861 : break;
3029 : :
3030 : 46 : case T_CreateConversionStmt:
3031 : 46 : tag = CMDTAG_CREATE_CONVERSION;
3032 : 46 : break;
3033 : :
3034 : 148 : case T_CreateCastStmt:
3035 : 148 : tag = CMDTAG_CREATE_CAST;
3036 : 148 : break;
3037 : :
3038 : 100 : case T_CreateOpClassStmt:
3039 : 100 : tag = CMDTAG_CREATE_OPERATOR_CLASS;
3040 : 100 : break;
3041 : :
3042 : 104 : case T_CreateOpFamilyStmt:
3043 : 104 : tag = CMDTAG_CREATE_OPERATOR_FAMILY;
3044 : 104 : break;
3045 : :
3046 : 209 : case T_AlterOpFamilyStmt:
3047 : 209 : tag = CMDTAG_ALTER_OPERATOR_FAMILY;
3048 : 209 : break;
3049 : :
3050 : 112 : case T_AlterOperatorStmt:
3051 : 112 : tag = CMDTAG_ALTER_OPERATOR;
3052 : 112 : break;
3053 : :
3054 : 20 : case T_AlterTypeStmt:
3055 : 20 : tag = CMDTAG_ALTER_TYPE;
3056 : 20 : break;
3057 : :
3058 : 23 : case T_AlterTSDictionaryStmt:
3059 : 23 : tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
3060 : 23 : break;
3061 : :
3062 : 5442 : case T_AlterTSConfigurationStmt:
3063 : 5442 : tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
3064 : 5442 : break;
3065 : :
3066 : 563 : case T_CreatePolicyStmt:
3067 : 563 : tag = CMDTAG_CREATE_POLICY;
3068 : 563 : break;
3069 : :
3070 : 64 : case T_AlterPolicyStmt:
3071 : 64 : tag = CMDTAG_ALTER_POLICY;
3072 : 64 : break;
3073 : :
3074 : 33 : case T_CreateAmStmt:
3075 : 33 : tag = CMDTAG_CREATE_ACCESS_METHOD;
3076 : 33 : break;
3077 : :
3078 : 668 : case T_CreatePublicationStmt:
3079 : 668 : tag = CMDTAG_CREATE_PUBLICATION;
3080 : 668 : break;
3081 : :
3082 : 793 : case T_AlterPublicationStmt:
3083 : 793 : tag = CMDTAG_ALTER_PUBLICATION;
3084 : 793 : break;
3085 : :
3086 : 342 : case T_CreateSubscriptionStmt:
3087 : 342 : tag = CMDTAG_CREATE_SUBSCRIPTION;
3088 : 342 : break;
3089 : :
3090 : 447 : case T_AlterSubscriptionStmt:
3091 : 447 : tag = CMDTAG_ALTER_SUBSCRIPTION;
3092 : 447 : break;
3093 : :
3094 : 184 : case T_DropSubscriptionStmt:
3095 : 184 : tag = CMDTAG_DROP_SUBSCRIPTION;
3096 : 184 : break;
3097 : :
3098 : 4 : case T_AlterCollationStmt:
3099 : 4 : tag = CMDTAG_ALTER_COLLATION;
3100 : 4 : break;
3101 : :
3102 : 1876 : case T_PrepareStmt:
3103 : 1876 : tag = CMDTAG_PREPARE;
3104 : 1876 : break;
3105 : :
3106 : 15956 : case T_ExecuteStmt:
3107 : 15956 : tag = CMDTAG_EXECUTE;
3108 : 15956 : break;
3109 : :
3110 : 615 : case T_CreateStatsStmt:
3111 : 615 : tag = CMDTAG_CREATE_STATISTICS;
3112 : 615 : break;
3113 : :
3114 : 18 : case T_AlterStatsStmt:
3115 : 18 : tag = CMDTAG_ALTER_STATISTICS;
3116 : 18 : break;
3117 : :
3118 : 2089 : case T_DeallocateStmt:
3119 : : {
3120 : 2089 : DeallocateStmt *stmt = (DeallocateStmt *) parsetree;
3121 : :
3122 [ + + ]: 2089 : if (stmt->name == NULL)
3123 : 37 : tag = CMDTAG_DEALLOCATE_ALL;
3124 : : else
3125 : 2052 : tag = CMDTAG_DEALLOCATE;
3126 : : }
3127 : 2089 : break;
3128 : :
3129 : 566 : case T_WaitStmt:
3130 : 566 : tag = CMDTAG_WAIT;
3131 : 566 : break;
3132 : :
3133 : : /* already-planned queries */
3134 : 26 : case T_PlannedStmt:
3135 : : {
3136 : 26 : PlannedStmt *stmt = (PlannedStmt *) parsetree;
3137 : :
3138 [ - + + + : 26 : switch (stmt->commandType)
- - - ]
3139 : : {
3140 : 0 : case CMD_SELECT:
3141 : :
3142 : : /*
3143 : : * We take a little extra care here so that the result
3144 : : * will be useful for complaints about read-only
3145 : : * statements
3146 : : */
3147 [ # # ]: 0 : if (stmt->rowMarks != NIL)
3148 : : {
3149 : : /* not 100% but probably close enough */
3150 [ # # # # : 0 : switch (((PlanRowMark *) linitial(stmt->rowMarks))->strength)
# ]
3151 : : {
3152 : 0 : case LCS_FORKEYSHARE:
3153 : 0 : tag = CMDTAG_SELECT_FOR_KEY_SHARE;
3154 : 0 : break;
3155 : 0 : case LCS_FORSHARE:
3156 : 0 : tag = CMDTAG_SELECT_FOR_SHARE;
3157 : 0 : break;
3158 : 0 : case LCS_FORNOKEYUPDATE:
3159 : 0 : tag = CMDTAG_SELECT_FOR_NO_KEY_UPDATE;
3160 : 0 : break;
3161 : 0 : case LCS_FORUPDATE:
3162 : 0 : tag = CMDTAG_SELECT_FOR_UPDATE;
3163 : 0 : break;
3164 : 0 : default:
3165 : 0 : tag = CMDTAG_SELECT;
3166 : 0 : break;
3167 : : }
3168 : : }
3169 : : else
3170 : 0 : tag = CMDTAG_SELECT;
3171 : 0 : break;
3172 : 16 : case CMD_UPDATE:
3173 : 16 : tag = CMDTAG_UPDATE;
3174 : 16 : break;
3175 : 6 : case CMD_INSERT:
3176 : 6 : tag = CMDTAG_INSERT;
3177 : 6 : break;
3178 : 4 : case CMD_DELETE:
3179 : 4 : tag = CMDTAG_DELETE;
3180 : 4 : break;
3181 : 0 : case CMD_MERGE:
3182 : 0 : tag = CMDTAG_MERGE;
3183 : 0 : break;
3184 : 0 : case CMD_UTILITY:
3185 : 0 : tag = CreateCommandTag(stmt->utilityStmt);
3186 : 0 : break;
3187 : 0 : default:
3188 [ # # ]: 0 : elog(WARNING, "unrecognized commandType: %d",
3189 : : (int) stmt->commandType);
3190 : 0 : tag = CMDTAG_UNKNOWN;
3191 : 0 : break;
3192 : : }
3193 : : }
3194 : 26 : break;
3195 : :
3196 : : /* parsed-and-rewritten-but-not-planned queries */
3197 : 528 : case T_Query:
3198 : : {
3199 : 528 : Query *stmt = (Query *) parsetree;
3200 : :
3201 [ + - + - : 528 : switch (stmt->commandType)
- - - ]
3202 : : {
3203 : 524 : case CMD_SELECT:
3204 : :
3205 : : /*
3206 : : * We take a little extra care here so that the result
3207 : : * will be useful for complaints about read-only
3208 : : * statements
3209 : : */
3210 [ - + ]: 524 : if (stmt->rowMarks != NIL)
3211 : : {
3212 : : /* not 100% but probably close enough */
3213 [ # # # # : 0 : switch (((RowMarkClause *) linitial(stmt->rowMarks))->strength)
# ]
3214 : : {
3215 : 0 : case LCS_FORKEYSHARE:
3216 : 0 : tag = CMDTAG_SELECT_FOR_KEY_SHARE;
3217 : 0 : break;
3218 : 0 : case LCS_FORSHARE:
3219 : 0 : tag = CMDTAG_SELECT_FOR_SHARE;
3220 : 0 : break;
3221 : 0 : case LCS_FORNOKEYUPDATE:
3222 : 0 : tag = CMDTAG_SELECT_FOR_NO_KEY_UPDATE;
3223 : 0 : break;
3224 : 0 : case LCS_FORUPDATE:
3225 : 0 : tag = CMDTAG_SELECT_FOR_UPDATE;
3226 : 0 : break;
3227 : 0 : default:
3228 : 0 : tag = CMDTAG_UNKNOWN;
3229 : 0 : break;
3230 : : }
3231 : : }
3232 : : else
3233 : 524 : tag = CMDTAG_SELECT;
3234 : 524 : break;
3235 : 0 : case CMD_UPDATE:
3236 : 0 : tag = CMDTAG_UPDATE;
3237 : 0 : break;
3238 : 4 : case CMD_INSERT:
3239 : 4 : tag = CMDTAG_INSERT;
3240 : 4 : break;
3241 : 0 : case CMD_DELETE:
3242 : 0 : tag = CMDTAG_DELETE;
3243 : 0 : break;
3244 : 0 : case CMD_MERGE:
3245 : 0 : tag = CMDTAG_MERGE;
3246 : 0 : break;
3247 : 0 : case CMD_UTILITY:
3248 : 0 : tag = CreateCommandTag(stmt->utilityStmt);
3249 : 0 : break;
3250 : 0 : default:
3251 [ # # ]: 0 : elog(WARNING, "unrecognized commandType: %d",
3252 : : (int) stmt->commandType);
3253 : 0 : tag = CMDTAG_UNKNOWN;
3254 : 0 : break;
3255 : : }
3256 : : }
3257 : 528 : break;
3258 : :
3259 : 0 : default:
3260 [ # # ]: 0 : elog(WARNING, "unrecognized node type: %d",
3261 : : (int) nodeTag(parsetree));
3262 : 0 : tag = CMDTAG_UNKNOWN;
3263 : 0 : break;
3264 : : }
3265 : :
3266 : 506106 : return tag;
3267 : : }
3268 : :
3269 : :
3270 : : /*
3271 : : * GetCommandLogLevel
3272 : : * utility to get the minimum log_statement level for a command,
3273 : : * given either a raw (un-analyzed) parsetree, an analyzed Query,
3274 : : * or a PlannedStmt.
3275 : : *
3276 : : * This must handle all command types, but since the vast majority
3277 : : * of 'em are utility commands, it seems sensible to keep it here.
3278 : : */
3279 : : LogStmtLevel
3280 : 0 : GetCommandLogLevel(Node *parsetree)
3281 : : {
3282 : : LogStmtLevel lev;
3283 : :
3284 [ # # # # : 0 : switch (nodeTag(parsetree))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3285 : : {
3286 : : /* recurse if we're given a RawStmt */
3287 : 0 : case T_RawStmt:
3288 : 0 : lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
3289 : 0 : break;
3290 : :
3291 : : /* raw plannable queries */
3292 : 0 : case T_InsertStmt:
3293 : : case T_DeleteStmt:
3294 : : case T_UpdateStmt:
3295 : : case T_MergeStmt:
3296 : 0 : lev = LOGSTMT_MOD;
3297 : 0 : break;
3298 : :
3299 : 0 : case T_SelectStmt:
3300 [ # # ]: 0 : if (((SelectStmt *) parsetree)->intoClause)
3301 : 0 : lev = LOGSTMT_DDL; /* SELECT INTO */
3302 : : else
3303 : 0 : lev = LOGSTMT_ALL;
3304 : 0 : break;
3305 : :
3306 : 0 : case T_PLAssignStmt:
3307 : 0 : lev = LOGSTMT_ALL;
3308 : 0 : break;
3309 : :
3310 : : /* utility statements --- same whether raw or cooked */
3311 : 0 : case T_TransactionStmt:
3312 : 0 : lev = LOGSTMT_ALL;
3313 : 0 : break;
3314 : :
3315 : 0 : case T_DeclareCursorStmt:
3316 : 0 : lev = LOGSTMT_ALL;
3317 : 0 : break;
3318 : :
3319 : 0 : case T_ClosePortalStmt:
3320 : 0 : lev = LOGSTMT_ALL;
3321 : 0 : break;
3322 : :
3323 : 0 : case T_FetchStmt:
3324 : 0 : lev = LOGSTMT_ALL;
3325 : 0 : break;
3326 : :
3327 : 0 : case T_CreateSchemaStmt:
3328 : 0 : lev = LOGSTMT_DDL;
3329 : 0 : break;
3330 : :
3331 : 0 : case T_CreateStmt:
3332 : : case T_CreateForeignTableStmt:
3333 : 0 : lev = LOGSTMT_DDL;
3334 : 0 : break;
3335 : :
3336 : 0 : case T_CreateTableSpaceStmt:
3337 : : case T_DropTableSpaceStmt:
3338 : : case T_AlterTableSpaceOptionsStmt:
3339 : 0 : lev = LOGSTMT_DDL;
3340 : 0 : break;
3341 : :
3342 : 0 : case T_CreateExtensionStmt:
3343 : : case T_AlterExtensionStmt:
3344 : : case T_AlterExtensionContentsStmt:
3345 : 0 : lev = LOGSTMT_DDL;
3346 : 0 : break;
3347 : :
3348 : 0 : case T_CreateFdwStmt:
3349 : : case T_AlterFdwStmt:
3350 : : case T_CreateForeignServerStmt:
3351 : : case T_AlterForeignServerStmt:
3352 : : case T_CreateUserMappingStmt:
3353 : : case T_AlterUserMappingStmt:
3354 : : case T_DropUserMappingStmt:
3355 : : case T_ImportForeignSchemaStmt:
3356 : 0 : lev = LOGSTMT_DDL;
3357 : 0 : break;
3358 : :
3359 : 0 : case T_DropStmt:
3360 : 0 : lev = LOGSTMT_DDL;
3361 : 0 : break;
3362 : :
3363 : 0 : case T_TruncateStmt:
3364 : 0 : lev = LOGSTMT_MOD;
3365 : 0 : break;
3366 : :
3367 : 0 : case T_CommentStmt:
3368 : 0 : lev = LOGSTMT_DDL;
3369 : 0 : break;
3370 : :
3371 : 0 : case T_SecLabelStmt:
3372 : 0 : lev = LOGSTMT_DDL;
3373 : 0 : break;
3374 : :
3375 : 0 : case T_CopyStmt:
3376 [ # # ]: 0 : if (((CopyStmt *) parsetree)->is_from)
3377 : 0 : lev = LOGSTMT_MOD;
3378 : : else
3379 : 0 : lev = LOGSTMT_ALL;
3380 : 0 : break;
3381 : :
3382 : 0 : case T_PrepareStmt:
3383 : : {
3384 : 0 : PrepareStmt *stmt = (PrepareStmt *) parsetree;
3385 : :
3386 : : /* Look through a PREPARE to the contained stmt */
3387 : 0 : lev = GetCommandLogLevel(stmt->query);
3388 : : }
3389 : 0 : break;
3390 : :
3391 : 0 : case T_ExecuteStmt:
3392 : : {
3393 : 0 : ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
3394 : : PreparedStatement *ps;
3395 : :
3396 : : /* Look through an EXECUTE to the referenced stmt */
3397 : 0 : ps = FetchPreparedStatement(stmt->name, false);
3398 [ # # # # ]: 0 : if (ps && ps->plansource->raw_parse_tree)
3399 : 0 : lev = GetCommandLogLevel(ps->plansource->raw_parse_tree->stmt);
3400 : : else
3401 : 0 : lev = LOGSTMT_ALL;
3402 : : }
3403 : 0 : break;
3404 : :
3405 : 0 : case T_DeallocateStmt:
3406 : 0 : lev = LOGSTMT_ALL;
3407 : 0 : break;
3408 : :
3409 : 0 : case T_RenameStmt:
3410 : 0 : lev = LOGSTMT_DDL;
3411 : 0 : break;
3412 : :
3413 : 0 : case T_AlterObjectDependsStmt:
3414 : 0 : lev = LOGSTMT_DDL;
3415 : 0 : break;
3416 : :
3417 : 0 : case T_AlterObjectSchemaStmt:
3418 : 0 : lev = LOGSTMT_DDL;
3419 : 0 : break;
3420 : :
3421 : 0 : case T_AlterOwnerStmt:
3422 : 0 : lev = LOGSTMT_DDL;
3423 : 0 : break;
3424 : :
3425 : 0 : case T_AlterOperatorStmt:
3426 : 0 : lev = LOGSTMT_DDL;
3427 : 0 : break;
3428 : :
3429 : 0 : case T_AlterTypeStmt:
3430 : 0 : lev = LOGSTMT_DDL;
3431 : 0 : break;
3432 : :
3433 : 0 : case T_AlterTableMoveAllStmt:
3434 : : case T_AlterTableStmt:
3435 : 0 : lev = LOGSTMT_DDL;
3436 : 0 : break;
3437 : :
3438 : 0 : case T_AlterDomainStmt:
3439 : 0 : lev = LOGSTMT_DDL;
3440 : 0 : break;
3441 : :
3442 : 0 : case T_GrantStmt:
3443 : 0 : lev = LOGSTMT_DDL;
3444 : 0 : break;
3445 : :
3446 : 0 : case T_GrantRoleStmt:
3447 : 0 : lev = LOGSTMT_DDL;
3448 : 0 : break;
3449 : :
3450 : 0 : case T_AlterDefaultPrivilegesStmt:
3451 : 0 : lev = LOGSTMT_DDL;
3452 : 0 : break;
3453 : :
3454 : 0 : case T_DefineStmt:
3455 : 0 : lev = LOGSTMT_DDL;
3456 : 0 : break;
3457 : :
3458 : 0 : case T_CompositeTypeStmt:
3459 : 0 : lev = LOGSTMT_DDL;
3460 : 0 : break;
3461 : :
3462 : 0 : case T_CreateEnumStmt:
3463 : 0 : lev = LOGSTMT_DDL;
3464 : 0 : break;
3465 : :
3466 : 0 : case T_CreateRangeStmt:
3467 : 0 : lev = LOGSTMT_DDL;
3468 : 0 : break;
3469 : :
3470 : 0 : case T_AlterEnumStmt:
3471 : 0 : lev = LOGSTMT_DDL;
3472 : 0 : break;
3473 : :
3474 : 0 : case T_ViewStmt:
3475 : 0 : lev = LOGSTMT_DDL;
3476 : 0 : break;
3477 : :
3478 : 0 : case T_CreateFunctionStmt:
3479 : 0 : lev = LOGSTMT_DDL;
3480 : 0 : break;
3481 : :
3482 : 0 : case T_AlterFunctionStmt:
3483 : 0 : lev = LOGSTMT_DDL;
3484 : 0 : break;
3485 : :
3486 : 0 : case T_IndexStmt:
3487 : 0 : lev = LOGSTMT_DDL;
3488 : 0 : break;
3489 : :
3490 : 0 : case T_RuleStmt:
3491 : 0 : lev = LOGSTMT_DDL;
3492 : 0 : break;
3493 : :
3494 : 0 : case T_CreateSeqStmt:
3495 : 0 : lev = LOGSTMT_DDL;
3496 : 0 : break;
3497 : :
3498 : 0 : case T_AlterSeqStmt:
3499 : 0 : lev = LOGSTMT_DDL;
3500 : 0 : break;
3501 : :
3502 : 0 : case T_DoStmt:
3503 : 0 : lev = LOGSTMT_ALL;
3504 : 0 : break;
3505 : :
3506 : 0 : case T_CreatedbStmt:
3507 : 0 : lev = LOGSTMT_DDL;
3508 : 0 : break;
3509 : :
3510 : 0 : case T_AlterDatabaseStmt:
3511 : : case T_AlterDatabaseRefreshCollStmt:
3512 : : case T_AlterDatabaseSetStmt:
3513 : 0 : lev = LOGSTMT_DDL;
3514 : 0 : break;
3515 : :
3516 : 0 : case T_DropdbStmt:
3517 : 0 : lev = LOGSTMT_DDL;
3518 : 0 : break;
3519 : :
3520 : 0 : case T_NotifyStmt:
3521 : 0 : lev = LOGSTMT_ALL;
3522 : 0 : break;
3523 : :
3524 : 0 : case T_ListenStmt:
3525 : 0 : lev = LOGSTMT_ALL;
3526 : 0 : break;
3527 : :
3528 : 0 : case T_UnlistenStmt:
3529 : 0 : lev = LOGSTMT_ALL;
3530 : 0 : break;
3531 : :
3532 : 0 : case T_LoadStmt:
3533 : 0 : lev = LOGSTMT_ALL;
3534 : 0 : break;
3535 : :
3536 : 0 : case T_CallStmt:
3537 : 0 : lev = LOGSTMT_ALL;
3538 : 0 : break;
3539 : :
3540 : 0 : case T_RepackStmt:
3541 : 0 : lev = LOGSTMT_DDL;
3542 : 0 : break;
3543 : :
3544 : 0 : case T_VacuumStmt:
3545 : 0 : lev = LOGSTMT_ALL;
3546 : 0 : break;
3547 : :
3548 : 0 : case T_ExplainStmt:
3549 : : {
3550 : 0 : ExplainStmt *stmt = (ExplainStmt *) parsetree;
3551 : 0 : bool analyze = false;
3552 : : ListCell *lc;
3553 : :
3554 : : /* Look through an EXPLAIN ANALYZE to the contained stmt */
3555 [ # # # # : 0 : foreach(lc, stmt->options)
# # ]
3556 : : {
3557 : 0 : DefElem *opt = (DefElem *) lfirst(lc);
3558 : :
3559 [ # # ]: 0 : if (strcmp(opt->defname, "analyze") == 0)
3560 : 0 : analyze = defGetBoolean(opt);
3561 : : /* don't "break", as explain.c will use the last value */
3562 : : }
3563 [ # # ]: 0 : if (analyze)
3564 : 0 : return GetCommandLogLevel(stmt->query);
3565 : :
3566 : : /* Plain EXPLAIN isn't so interesting */
3567 : 0 : lev = LOGSTMT_ALL;
3568 : : }
3569 : 0 : break;
3570 : :
3571 : 0 : case T_CreateTableAsStmt:
3572 : 0 : lev = LOGSTMT_DDL;
3573 : 0 : break;
3574 : :
3575 : 0 : case T_RefreshMatViewStmt:
3576 : 0 : lev = LOGSTMT_DDL;
3577 : 0 : break;
3578 : :
3579 : 0 : case T_AlterSystemStmt:
3580 : 0 : lev = LOGSTMT_DDL;
3581 : 0 : break;
3582 : :
3583 : 0 : case T_VariableSetStmt:
3584 : 0 : lev = LOGSTMT_ALL;
3585 : 0 : break;
3586 : :
3587 : 0 : case T_VariableShowStmt:
3588 : 0 : lev = LOGSTMT_ALL;
3589 : 0 : break;
3590 : :
3591 : 0 : case T_DiscardStmt:
3592 : 0 : lev = LOGSTMT_ALL;
3593 : 0 : break;
3594 : :
3595 : 0 : case T_CreateTrigStmt:
3596 : 0 : lev = LOGSTMT_DDL;
3597 : 0 : break;
3598 : :
3599 : 0 : case T_CreateEventTrigStmt:
3600 : 0 : lev = LOGSTMT_DDL;
3601 : 0 : break;
3602 : :
3603 : 0 : case T_AlterEventTrigStmt:
3604 : 0 : lev = LOGSTMT_DDL;
3605 : 0 : break;
3606 : :
3607 : 0 : case T_CreatePLangStmt:
3608 : 0 : lev = LOGSTMT_DDL;
3609 : 0 : break;
3610 : :
3611 : 0 : case T_CreateDomainStmt:
3612 : 0 : lev = LOGSTMT_DDL;
3613 : 0 : break;
3614 : :
3615 : 0 : case T_CreateRoleStmt:
3616 : 0 : lev = LOGSTMT_DDL;
3617 : 0 : break;
3618 : :
3619 : 0 : case T_AlterRoleStmt:
3620 : 0 : lev = LOGSTMT_DDL;
3621 : 0 : break;
3622 : :
3623 : 0 : case T_AlterRoleSetStmt:
3624 : 0 : lev = LOGSTMT_DDL;
3625 : 0 : break;
3626 : :
3627 : 0 : case T_DropRoleStmt:
3628 : 0 : lev = LOGSTMT_DDL;
3629 : 0 : break;
3630 : :
3631 : 0 : case T_DropOwnedStmt:
3632 : 0 : lev = LOGSTMT_DDL;
3633 : 0 : break;
3634 : :
3635 : 0 : case T_ReassignOwnedStmt:
3636 : 0 : lev = LOGSTMT_DDL;
3637 : 0 : break;
3638 : :
3639 : 0 : case T_LockStmt:
3640 : 0 : lev = LOGSTMT_ALL;
3641 : 0 : break;
3642 : :
3643 : 0 : case T_ConstraintsSetStmt:
3644 : 0 : lev = LOGSTMT_ALL;
3645 : 0 : break;
3646 : :
3647 : 0 : case T_CheckPointStmt:
3648 : 0 : lev = LOGSTMT_ALL;
3649 : 0 : break;
3650 : :
3651 : 0 : case T_ReindexStmt:
3652 : 0 : lev = LOGSTMT_ALL; /* should this be DDL? */
3653 : 0 : break;
3654 : :
3655 : 0 : case T_CreateConversionStmt:
3656 : 0 : lev = LOGSTMT_DDL;
3657 : 0 : break;
3658 : :
3659 : 0 : case T_CreateCastStmt:
3660 : 0 : lev = LOGSTMT_DDL;
3661 : 0 : break;
3662 : :
3663 : 0 : case T_CreateOpClassStmt:
3664 : 0 : lev = LOGSTMT_DDL;
3665 : 0 : break;
3666 : :
3667 : 0 : case T_CreateOpFamilyStmt:
3668 : 0 : lev = LOGSTMT_DDL;
3669 : 0 : break;
3670 : :
3671 : 0 : case T_CreateTransformStmt:
3672 : 0 : lev = LOGSTMT_DDL;
3673 : 0 : break;
3674 : :
3675 : 0 : case T_AlterOpFamilyStmt:
3676 : 0 : lev = LOGSTMT_DDL;
3677 : 0 : break;
3678 : :
3679 : 0 : case T_CreatePolicyStmt:
3680 : 0 : lev = LOGSTMT_DDL;
3681 : 0 : break;
3682 : :
3683 : 0 : case T_AlterPolicyStmt:
3684 : 0 : lev = LOGSTMT_DDL;
3685 : 0 : break;
3686 : :
3687 : 0 : case T_AlterTSDictionaryStmt:
3688 : 0 : lev = LOGSTMT_DDL;
3689 : 0 : break;
3690 : :
3691 : 0 : case T_AlterTSConfigurationStmt:
3692 : 0 : lev = LOGSTMT_DDL;
3693 : 0 : break;
3694 : :
3695 : 0 : case T_CreateAmStmt:
3696 : 0 : lev = LOGSTMT_DDL;
3697 : 0 : break;
3698 : :
3699 : 0 : case T_CreatePublicationStmt:
3700 : 0 : lev = LOGSTMT_DDL;
3701 : 0 : break;
3702 : :
3703 : 0 : case T_AlterPublicationStmt:
3704 : 0 : lev = LOGSTMT_DDL;
3705 : 0 : break;
3706 : :
3707 : 0 : case T_CreateSubscriptionStmt:
3708 : 0 : lev = LOGSTMT_DDL;
3709 : 0 : break;
3710 : :
3711 : 0 : case T_AlterSubscriptionStmt:
3712 : 0 : lev = LOGSTMT_DDL;
3713 : 0 : break;
3714 : :
3715 : 0 : case T_DropSubscriptionStmt:
3716 : 0 : lev = LOGSTMT_DDL;
3717 : 0 : break;
3718 : :
3719 : 0 : case T_CreateStatsStmt:
3720 : 0 : lev = LOGSTMT_DDL;
3721 : 0 : break;
3722 : :
3723 : 0 : case T_AlterStatsStmt:
3724 : 0 : lev = LOGSTMT_DDL;
3725 : 0 : break;
3726 : :
3727 : 0 : case T_AlterCollationStmt:
3728 : 0 : lev = LOGSTMT_DDL;
3729 : 0 : break;
3730 : :
3731 : 0 : case T_WaitStmt:
3732 : 0 : lev = LOGSTMT_ALL;
3733 : 0 : break;
3734 : :
3735 : : /* already-planned queries */
3736 : 0 : case T_PlannedStmt:
3737 : : {
3738 : 0 : PlannedStmt *stmt = (PlannedStmt *) parsetree;
3739 : :
3740 [ # # # # ]: 0 : switch (stmt->commandType)
3741 : : {
3742 : 0 : case CMD_SELECT:
3743 : 0 : lev = LOGSTMT_ALL;
3744 : 0 : break;
3745 : :
3746 : 0 : case CMD_UPDATE:
3747 : : case CMD_INSERT:
3748 : : case CMD_DELETE:
3749 : : case CMD_MERGE:
3750 : 0 : lev = LOGSTMT_MOD;
3751 : 0 : break;
3752 : :
3753 : 0 : case CMD_UTILITY:
3754 : 0 : lev = GetCommandLogLevel(stmt->utilityStmt);
3755 : 0 : break;
3756 : :
3757 : 0 : default:
3758 [ # # ]: 0 : elog(WARNING, "unrecognized commandType: %d",
3759 : : (int) stmt->commandType);
3760 : 0 : lev = LOGSTMT_ALL;
3761 : 0 : break;
3762 : : }
3763 : : }
3764 : 0 : break;
3765 : :
3766 : : /* parsed-and-rewritten-but-not-planned queries */
3767 : 0 : case T_Query:
3768 : : {
3769 : 0 : Query *stmt = (Query *) parsetree;
3770 : :
3771 [ # # # # ]: 0 : switch (stmt->commandType)
3772 : : {
3773 : 0 : case CMD_SELECT:
3774 : 0 : lev = LOGSTMT_ALL;
3775 : 0 : break;
3776 : :
3777 : 0 : case CMD_UPDATE:
3778 : : case CMD_INSERT:
3779 : : case CMD_DELETE:
3780 : : case CMD_MERGE:
3781 : 0 : lev = LOGSTMT_MOD;
3782 : 0 : break;
3783 : :
3784 : 0 : case CMD_UTILITY:
3785 : 0 : lev = GetCommandLogLevel(stmt->utilityStmt);
3786 : 0 : break;
3787 : :
3788 : 0 : default:
3789 [ # # ]: 0 : elog(WARNING, "unrecognized commandType: %d",
3790 : : (int) stmt->commandType);
3791 : 0 : lev = LOGSTMT_ALL;
3792 : 0 : break;
3793 : : }
3794 : : }
3795 : 0 : break;
3796 : :
3797 : 0 : default:
3798 [ # # ]: 0 : elog(WARNING, "unrecognized node type: %d",
3799 : : (int) nodeTag(parsetree));
3800 : 0 : lev = LOGSTMT_ALL;
3801 : 0 : break;
3802 : : }
3803 : :
3804 : 0 : return lev;
3805 : : }
|