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