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-2018, 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/namespace.h"
26 #include "catalog/pg_inherits.h"
27 #include "catalog/toasting.h"
28 #include "commands/alter.h"
29 #include "commands/async.h"
30 #include "commands/cluster.h"
31 #include "commands/comment.h"
32 #include "commands/collationcmds.h"
34 #include "commands/copy.h"
35 #include "commands/createas.h"
36 #include "commands/dbcommands.h"
37 #include "commands/defrem.h"
38 #include "commands/discard.h"
39 #include "commands/event_trigger.h"
40 #include "commands/explain.h"
41 #include "commands/extension.h"
42 #include "commands/matview.h"
43 #include "commands/lockcmds.h"
44 #include "commands/policy.h"
45 #include "commands/portalcmds.h"
46 #include "commands/prepare.h"
47 #include "commands/proclang.h"
49 #include "commands/schemacmds.h"
50 #include "commands/seclabel.h"
51 #include "commands/sequence.h"
53 #include "commands/tablecmds.h"
54 #include "commands/tablespace.h"
55 #include "commands/trigger.h"
56 #include "commands/typecmds.h"
57 #include "commands/user.h"
58 #include "commands/vacuum.h"
59 #include "commands/view.h"
60 #include "miscadmin.h"
61 #include "parser/parse_utilcmd.h"
62 #include "postmaster/bgwriter.h"
63 #include "rewrite/rewriteDefine.h"
64 #include "rewrite/rewriteRemove.h"
65 #include "storage/fd.h"
66 #include "tcop/pquery.h"
67 #include "tcop/utility.h"
68 #include "utils/acl.h"
69 #include "utils/guc.h"
70 #include "utils/lsyscache.h"
71 #include "utils/syscache.h"
72 #include "utils/rel.h"
73 
74 
75 /* Hook for plugins to get control in ProcessUtility() */
77 
78 /* local function declarations */
79 static void ProcessUtilitySlow(ParseState *pstate,
80  PlannedStmt *pstmt,
81  const char *queryString,
82  ProcessUtilityContext context,
83  ParamListInfo params,
84  QueryEnvironment *queryEnv,
86  char *completionTag);
87 static void ExecDropStmt(DropStmt *stmt, bool isTopLevel);
88 
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  * check_xact_readonly: is a utility command read-only?
129  *
130  * Here we use the loose rules of XactReadOnly mode: no permanent effects
131  * on the database are allowed.
132  */
133 static void
135 {
136  /* Only perform the check if we have a reason to do so. */
137  if (!XactReadOnly && !IsInParallelMode())
138  return;
139 
140  /*
141  * Note: Commands that need to do more complicated checking are handled
142  * elsewhere, in particular COPY and plannable statements do their own
143  * checking. However they should all call PreventCommandIfReadOnly or
144  * PreventCommandIfParallelMode to actually throw the error.
145  */
146 
147  switch (nodeTag(parsetree))
148  {
149  case T_AlterDatabaseStmt:
151  case T_AlterDomainStmt:
152  case T_AlterFunctionStmt:
153  case T_AlterRoleStmt:
154  case T_AlterRoleSetStmt:
157  case T_AlterOwnerStmt:
158  case T_AlterOperatorStmt:
159  case T_AlterSeqStmt:
161  case T_AlterTableStmt:
162  case T_RenameStmt:
163  case T_CommentStmt:
164  case T_DefineStmt:
165  case T_CreateCastStmt:
169  case T_CreatedbStmt:
170  case T_CreateDomainStmt:
172  case T_CreateRoleStmt:
173  case T_IndexStmt:
174  case T_CreatePLangStmt:
175  case T_CreateOpClassStmt:
177  case T_AlterOpFamilyStmt:
178  case T_RuleStmt:
179  case T_CreateSchemaStmt:
180  case T_CreateSeqStmt:
181  case T_CreateStmt:
182  case T_CreateTableAsStmt:
186  case T_CreateTrigStmt:
187  case T_CompositeTypeStmt:
188  case T_CreateEnumStmt:
189  case T_CreateRangeStmt:
190  case T_AlterEnumStmt:
191  case T_ViewStmt:
192  case T_DropStmt:
193  case T_DropdbStmt:
195  case T_DropRoleStmt:
196  case T_GrantStmt:
197  case T_GrantRoleStmt:
199  case T_TruncateStmt:
200  case T_DropOwnedStmt:
201  case T_ReassignOwnedStmt:
207  case T_CreateFdwStmt:
208  case T_AlterFdwStmt:
217  case T_SecLabelStmt:
225  break;
226  default:
227  /* do nothing */
228  break;
229  }
230 }
231 
232 /*
233  * PreventCommandIfReadOnly: throw error if XactReadOnly
234  *
235  * This is useful mainly to ensure consistency of the error message wording;
236  * most callers have checked XactReadOnly for themselves.
237  */
238 void
239 PreventCommandIfReadOnly(const char *cmdname)
240 {
241  if (XactReadOnly)
242  ereport(ERROR,
243  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
244  /* translator: %s is name of a SQL command, eg CREATE */
245  errmsg("cannot execute %s in a read-only transaction",
246  cmdname)));
247 }
248 
249 /*
250  * PreventCommandIfParallelMode: throw error if current (sub)transaction is
251  * in parallel mode.
252  *
253  * This is useful mainly to ensure consistency of the error message wording;
254  * most callers have checked IsInParallelMode() for themselves.
255  */
256 void
257 PreventCommandIfParallelMode(const char *cmdname)
258 {
259  if (IsInParallelMode())
260  ereport(ERROR,
261  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
262  /* translator: %s is name of a SQL command, eg CREATE */
263  errmsg("cannot execute %s during a parallel operation",
264  cmdname)));
265 }
266 
267 /*
268  * PreventCommandDuringRecovery: throw error if RecoveryInProgress
269  *
270  * The majority of operations that are unsafe in a Hot Standby
271  * will be rejected by XactReadOnly tests. However there are a few
272  * commands that are allowed in "read-only" xacts but cannot be allowed
273  * in Hot Standby mode. Those commands should call this function.
274  */
275 void
276 PreventCommandDuringRecovery(const char *cmdname)
277 {
278  if (RecoveryInProgress())
279  ereport(ERROR,
280  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
281  /* translator: %s is name of a SQL command, eg CREATE */
282  errmsg("cannot execute %s during recovery",
283  cmdname)));
284 }
285 
286 /*
287  * CheckRestrictedOperation: throw error for hazardous command if we're
288  * inside a security restriction context.
289  *
290  * This is needed to protect session-local state for which there is not any
291  * better-defined protection mechanism, such as ownership.
292  */
293 static void
294 CheckRestrictedOperation(const char *cmdname)
295 {
297  ereport(ERROR,
298  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
299  /* translator: %s is name of a SQL command, eg PREPARE */
300  errmsg("cannot execute %s within security-restricted operation",
301  cmdname)));
302 }
303 
304 
305 /*
306  * ProcessUtility
307  * general utility function invoker
308  *
309  * pstmt: PlannedStmt wrapper for the utility statement
310  * queryString: original source text of command
311  * context: identifies source of statement (toplevel client command,
312  * non-toplevel client command, subcommand of a larger utility command)
313  * params: parameters to use during execution
314  * queryEnv: environment for parse through execution (e.g., ephemeral named
315  * tables like trigger transition tables). May be NULL.
316  * dest: where to send results
317  * completionTag: points to a buffer of size COMPLETION_TAG_BUFSIZE
318  * in which to store a command completion status string.
319  *
320  * Caller MUST supply a queryString; it is not allowed (anymore) to pass NULL.
321  * If you really don't have source text, you can pass a constant string,
322  * perhaps "(query not available)".
323  *
324  * completionTag is only set nonempty if we want to return a nondefault status.
325  *
326  * completionTag may be NULL if caller doesn't want a status string.
327  *
328  * Note for users of ProcessUtility_hook: the same queryString may be passed
329  * to multiple invocations of ProcessUtility when processing a query string
330  * containing multiple semicolon-separated statements. One should use
331  * pstmt->stmt_location and pstmt->stmt_len to identify the substring
332  * containing the current statement. Keep in mind also that some utility
333  * statements (e.g., CREATE SCHEMA) will recurse to ProcessUtility to process
334  * sub-statements, often passing down the same queryString, stmt_location,
335  * and stmt_len that were given for the whole statement.
336  */
337 void
339  const char *queryString,
340  ProcessUtilityContext context,
341  ParamListInfo params,
342  QueryEnvironment *queryEnv,
344  char *completionTag)
345 {
346  Assert(IsA(pstmt, PlannedStmt));
347  Assert(pstmt->commandType == CMD_UTILITY);
348  Assert(queryString != NULL); /* required as of 8.4 */
349 
350  /*
351  * We provide a function hook variable that lets loadable plugins get
352  * control when ProcessUtility is called. Such a plugin would normally
353  * call standard_ProcessUtility().
354  */
356  (*ProcessUtility_hook) (pstmt, queryString,
357  context, params, queryEnv,
358  dest, completionTag);
359  else
360  standard_ProcessUtility(pstmt, queryString,
361  context, params, queryEnv,
362  dest, completionTag);
363 }
364 
365 /*
366  * standard_ProcessUtility itself deals only with utility commands for
367  * which we do not provide event trigger support. Commands that do have
368  * such support are passed down to ProcessUtilitySlow, which contains the
369  * necessary infrastructure for such triggers.
370  *
371  * This division is not just for performance: it's critical that the
372  * event trigger code not be invoked when doing START TRANSACTION for
373  * example, because we might need to refresh the event trigger cache,
374  * which requires being in a valid transaction.
375  */
376 void
378  const char *queryString,
379  ProcessUtilityContext context,
380  ParamListInfo params,
381  QueryEnvironment *queryEnv,
383  char *completionTag)
384 {
385  Node *parsetree = pstmt->utilityStmt;
386  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
387  bool isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
388  ParseState *pstate;
389 
390  check_xact_readonly(parsetree);
391 
392  if (completionTag)
393  completionTag[0] = '\0';
394 
395  pstate = make_parsestate(NULL);
396  pstate->p_sourcetext = queryString;
397 
398  switch (nodeTag(parsetree))
399  {
400  /*
401  * ******************** transactions ********************
402  */
403  case T_TransactionStmt:
404  {
405  TransactionStmt *stmt = (TransactionStmt *) parsetree;
406 
407  switch (stmt->kind)
408  {
409  /*
410  * START TRANSACTION, as defined by SQL99: Identical
411  * to BEGIN. Same code for both.
412  */
413  case TRANS_STMT_BEGIN:
414  case TRANS_STMT_START:
415  {
416  ListCell *lc;
417 
419  foreach(lc, stmt->options)
420  {
421  DefElem *item = (DefElem *) lfirst(lc);
422 
423  if (strcmp(item->defname, "transaction_isolation") == 0)
424  SetPGVariable("transaction_isolation",
425  list_make1(item->arg),
426  true);
427  else if (strcmp(item->defname, "transaction_read_only") == 0)
428  SetPGVariable("transaction_read_only",
429  list_make1(item->arg),
430  true);
431  else if (strcmp(item->defname, "transaction_deferrable") == 0)
432  SetPGVariable("transaction_deferrable",
433  list_make1(item->arg),
434  true);
435  }
436  }
437  break;
438 
439  case TRANS_STMT_COMMIT:
440  if (!EndTransactionBlock())
441  {
442  /* report unsuccessful commit in completionTag */
443  if (completionTag)
444  strcpy(completionTag, "ROLLBACK");
445  }
446  break;
447 
448  case TRANS_STMT_PREPARE:
449  PreventCommandDuringRecovery("PREPARE TRANSACTION");
450  if (!PrepareTransactionBlock(stmt->gid))
451  {
452  /* report unsuccessful commit in completionTag */
453  if (completionTag)
454  strcpy(completionTag, "ROLLBACK");
455  }
456  break;
457 
459  PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
460  PreventCommandDuringRecovery("COMMIT PREPARED");
461  FinishPreparedTransaction(stmt->gid, true);
462  break;
463 
465  PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
466  PreventCommandDuringRecovery("ROLLBACK PREPARED");
467  FinishPreparedTransaction(stmt->gid, false);
468  break;
469 
470  case TRANS_STMT_ROLLBACK:
472  break;
473 
475  RequireTransactionBlock(isTopLevel, "SAVEPOINT");
477  break;
478 
479  case TRANS_STMT_RELEASE:
480  RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
482  break;
483 
485  RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
487 
488  /*
489  * CommitTransactionCommand is in charge of
490  * re-defining the savepoint again
491  */
492  break;
493  }
494  }
495  break;
496 
497  /*
498  * Portal (cursor) manipulation
499  */
500  case T_DeclareCursorStmt:
501  PerformCursorOpen((DeclareCursorStmt *) parsetree, params,
502  queryString, isTopLevel);
503  break;
504 
505  case T_ClosePortalStmt:
506  {
507  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
508 
509  CheckRestrictedOperation("CLOSE");
511  }
512  break;
513 
514  case T_FetchStmt:
515  PerformPortalFetch((FetchStmt *) parsetree, dest,
516  completionTag);
517  break;
518 
519  case T_DoStmt:
520  ExecuteDoStmt((DoStmt *) parsetree, isAtomicContext);
521  break;
522 
524  /* no event triggers for global objects */
525  PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
526  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
527  break;
528 
530  /* no event triggers for global objects */
531  PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
532  DropTableSpace((DropTableSpaceStmt *) parsetree);
533  break;
534 
536  /* no event triggers for global objects */
538  break;
539 
540  case T_TruncateStmt:
541  ExecuteTruncate((TruncateStmt *) parsetree);
542  break;
543 
544  case T_CopyStmt:
545  {
546  uint64 processed;
547 
548  DoCopy(pstate, (CopyStmt *) parsetree,
549  pstmt->stmt_location, pstmt->stmt_len,
550  &processed);
551  if (completionTag)
552  snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
553  "COPY " UINT64_FORMAT, processed);
554  }
555  break;
556 
557  case T_PrepareStmt:
558  CheckRestrictedOperation("PREPARE");
559  PrepareQuery((PrepareStmt *) parsetree, queryString,
560  pstmt->stmt_location, pstmt->stmt_len);
561  break;
562 
563  case T_ExecuteStmt:
564  ExecuteQuery((ExecuteStmt *) parsetree, NULL,
565  queryString, params,
566  dest, completionTag);
567  break;
568 
569  case T_DeallocateStmt:
570  CheckRestrictedOperation("DEALLOCATE");
571  DeallocateQuery((DeallocateStmt *) parsetree);
572  break;
573 
574  case T_GrantRoleStmt:
575  /* no event triggers for global objects */
576  GrantRole((GrantRoleStmt *) parsetree);
577  break;
578 
579  case T_CreatedbStmt:
580  /* no event triggers for global objects */
581  PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
582  createdb(pstate, (CreatedbStmt *) parsetree);
583  break;
584 
585  case T_AlterDatabaseStmt:
586  /* no event triggers for global objects */
587  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
588  break;
589 
591  /* no event triggers for global objects */
592  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
593  break;
594 
595  case T_DropdbStmt:
596  {
597  DropdbStmt *stmt = (DropdbStmt *) parsetree;
598 
599  /* no event triggers for global objects */
600  PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
601  dropdb(stmt->dbname, stmt->missing_ok);
602  }
603  break;
604 
605  /* Query-level asynchronous notification */
606  case T_NotifyStmt:
607  {
608  NotifyStmt *stmt = (NotifyStmt *) parsetree;
609 
611  Async_Notify(stmt->conditionname, stmt->payload);
612  }
613  break;
614 
615  case T_ListenStmt:
616  {
617  ListenStmt *stmt = (ListenStmt *) parsetree;
618 
620  CheckRestrictedOperation("LISTEN");
622  }
623  break;
624 
625  case T_UnlistenStmt:
626  {
627  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
628 
629  PreventCommandDuringRecovery("UNLISTEN");
630  CheckRestrictedOperation("UNLISTEN");
631  if (stmt->conditionname)
633  else
635  }
636  break;
637 
638  case T_LoadStmt:
639  {
640  LoadStmt *stmt = (LoadStmt *) parsetree;
641 
642  closeAllVfds(); /* probably not necessary... */
643  /* Allowed names are restricted if you're not superuser */
644  load_file(stmt->filename, !superuser());
645  }
646  break;
647 
648  case T_CallStmt:
649  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
650  break;
651 
652  case T_ClusterStmt:
653  /* we choose to allow this during "read only" transactions */
654  PreventCommandDuringRecovery("CLUSTER");
655  /* forbidden in parallel mode due to CommandIsReadOnly */
656  cluster((ClusterStmt *) parsetree, isTopLevel);
657  break;
658 
659  case T_VacuumStmt:
660  {
661  VacuumStmt *stmt = (VacuumStmt *) parsetree;
662 
663  /* we choose to allow this during "read only" transactions */
665  "VACUUM" : "ANALYZE");
666  /* forbidden in parallel mode due to CommandIsReadOnly */
667  ExecVacuum(stmt, isTopLevel);
668  }
669  break;
670 
671  case T_ExplainStmt:
672  ExplainQuery(pstate, (ExplainStmt *) parsetree, queryString, params,
673  queryEnv, dest);
674  break;
675 
676  case T_AlterSystemStmt:
677  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
679  break;
680 
681  case T_VariableSetStmt:
682  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
683  break;
684 
685  case T_VariableShowStmt:
686  {
687  VariableShowStmt *n = (VariableShowStmt *) parsetree;
688 
689  GetPGVariable(n->name, dest);
690  }
691  break;
692 
693  case T_DiscardStmt:
694  /* should we allow DISCARD PLANS? */
695  CheckRestrictedOperation("DISCARD");
696  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
697  break;
698 
700  /* no event triggers on event triggers */
702  break;
703 
705  /* no event triggers on event triggers */
706  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
707  break;
708 
709  /*
710  * ******************************** ROLE statements ****
711  */
712  case T_CreateRoleStmt:
713  /* no event triggers for global objects */
714  CreateRole(pstate, (CreateRoleStmt *) parsetree);
715  break;
716 
717  case T_AlterRoleStmt:
718  /* no event triggers for global objects */
719  AlterRole((AlterRoleStmt *) parsetree);
720  break;
721 
722  case T_AlterRoleSetStmt:
723  /* no event triggers for global objects */
724  AlterRoleSet((AlterRoleSetStmt *) parsetree);
725  break;
726 
727  case T_DropRoleStmt:
728  /* no event triggers for global objects */
729  DropRole((DropRoleStmt *) parsetree);
730  break;
731 
732  case T_ReassignOwnedStmt:
733  /* no event triggers for global objects */
735  break;
736 
737  case T_LockStmt:
738 
739  /*
740  * Since the lock would just get dropped immediately, LOCK TABLE
741  * outside a transaction block is presumed to be user error.
742  */
743  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
744  /* forbidden in parallel mode due to CommandIsReadOnly */
745  LockTableCommand((LockStmt *) parsetree);
746  break;
747 
749  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
751  break;
752 
753  case T_CheckPointStmt:
754  if (!superuser())
755  ereport(ERROR,
756  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
757  errmsg("must be superuser to do CHECKPOINT")));
758 
759  /*
760  * You might think we should have a PreventCommandDuringRecovery()
761  * here, but we interpret a CHECKPOINT command during recovery as
762  * a request for a restartpoint instead. We allow this since it
763  * can be a useful way of reducing switchover time when using
764  * various forms of replication.
765  */
768  break;
769 
770  case T_ReindexStmt:
771  {
772  ReindexStmt *stmt = (ReindexStmt *) parsetree;
773 
774  /* we choose to allow this during "read only" transactions */
775  PreventCommandDuringRecovery("REINDEX");
776  /* forbidden in parallel mode due to CommandIsReadOnly */
777  switch (stmt->kind)
778  {
780  ReindexIndex(stmt->relation, stmt->options);
781  break;
783  ReindexTable(stmt->relation, stmt->options);
784  break;
788 
789  /*
790  * This cannot run inside a user transaction block; if
791  * we were inside a transaction, then its commit- and
792  * start-transaction-command calls would not have the
793  * intended effect!
794  */
795  PreventInTransactionBlock(isTopLevel,
796  (stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
797  (stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
798  "REINDEX DATABASE");
799  ReindexMultipleTables(stmt->name, stmt->kind, stmt->options);
800  break;
801  default:
802  elog(ERROR, "unrecognized object type: %d",
803  (int) stmt->kind);
804  break;
805  }
806  }
807  break;
808 
809  /*
810  * The following statements are supported by Event Triggers only
811  * in some cases, so we "fast path" them in the other cases.
812  */
813 
814  case T_GrantStmt:
815  {
816  GrantStmt *stmt = (GrantStmt *) parsetree;
817 
819  ProcessUtilitySlow(pstate, pstmt, queryString,
820  context, params, queryEnv,
821  dest, completionTag);
822  else
823  ExecuteGrantStmt(stmt);
824  }
825  break;
826 
827  case T_DropStmt:
828  {
829  DropStmt *stmt = (DropStmt *) parsetree;
830 
832  ProcessUtilitySlow(pstate, pstmt, queryString,
833  context, params, queryEnv,
834  dest, completionTag);
835  else
836  ExecDropStmt(stmt, isTopLevel);
837  }
838  break;
839 
840  case T_RenameStmt:
841  {
842  RenameStmt *stmt = (RenameStmt *) parsetree;
843 
845  ProcessUtilitySlow(pstate, pstmt, queryString,
846  context, params, queryEnv,
847  dest, completionTag);
848  else
849  ExecRenameStmt(stmt);
850  }
851  break;
852 
854  {
855  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
856 
858  ProcessUtilitySlow(pstate, pstmt, queryString,
859  context, params, queryEnv,
860  dest, completionTag);
861  else
862  ExecAlterObjectDependsStmt(stmt, NULL);
863  }
864  break;
865 
867  {
868  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
869 
871  ProcessUtilitySlow(pstate, pstmt, queryString,
872  context, params, queryEnv,
873  dest, completionTag);
874  else
875  ExecAlterObjectSchemaStmt(stmt, NULL);
876  }
877  break;
878 
879  case T_AlterOwnerStmt:
880  {
881  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
882 
884  ProcessUtilitySlow(pstate, pstmt, queryString,
885  context, params, queryEnv,
886  dest, completionTag);
887  else
888  ExecAlterOwnerStmt(stmt);
889  }
890  break;
891 
892  case T_CommentStmt:
893  {
894  CommentStmt *stmt = (CommentStmt *) parsetree;
895 
897  ProcessUtilitySlow(pstate, pstmt, queryString,
898  context, params, queryEnv,
899  dest, completionTag);
900  else
901  CommentObject(stmt);
902  break;
903  }
904 
905  case T_SecLabelStmt:
906  {
907  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
908 
910  ProcessUtilitySlow(pstate, pstmt, queryString,
911  context, params, queryEnv,
912  dest, completionTag);
913  else
914  ExecSecLabelStmt(stmt);
915  break;
916  }
917 
918  default:
919  /* All other statement types have event trigger support */
920  ProcessUtilitySlow(pstate, pstmt, queryString,
921  context, params, queryEnv,
922  dest, completionTag);
923  break;
924  }
925 
926  free_parsestate(pstate);
927 }
928 
929 /*
930  * The "Slow" variant of ProcessUtility should only receive statements
931  * supported by the event triggers facility. Therefore, we always
932  * perform the trigger support calls if the context allows it.
933  */
934 static void
936  PlannedStmt *pstmt,
937  const char *queryString,
938  ProcessUtilityContext context,
939  ParamListInfo params,
940  QueryEnvironment *queryEnv,
942  char *completionTag)
943 {
944  Node *parsetree = pstmt->utilityStmt;
945  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
946  bool isCompleteQuery = (context <= PROCESS_UTILITY_QUERY);
947  bool needCleanup;
948  bool commandCollected = false;
949  ObjectAddress address;
950  ObjectAddress secondaryObject = InvalidObjectAddress;
951 
952  /* All event trigger calls are done only when isCompleteQuery is true */
953  needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
954 
955  /* PG_TRY block is to ensure we call EventTriggerEndCompleteQuery */
956  PG_TRY();
957  {
958  if (isCompleteQuery)
959  EventTriggerDDLCommandStart(parsetree);
960 
961  switch (nodeTag(parsetree))
962  {
963  /*
964  * relation and attribute manipulation
965  */
966  case T_CreateSchemaStmt:
968  queryString,
969  pstmt->stmt_location,
970  pstmt->stmt_len);
971 
972  /*
973  * EventTriggerCollectSimpleCommand called by
974  * CreateSchemaCommand
975  */
976  commandCollected = true;
977  break;
978 
979  case T_CreateStmt:
981  {
982  List *stmts;
983  ListCell *l;
984 
985  /* Run parse analysis ... */
986  stmts = transformCreateStmt((CreateStmt *) parsetree,
987  queryString);
988 
989  /* ... and do it */
990  foreach(l, stmts)
991  {
992  Node *stmt = (Node *) lfirst(l);
993 
994  if (IsA(stmt, CreateStmt))
995  {
996  Datum toast_options;
997  static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
998 
999  /* Create the table itself */
1000  address = DefineRelation((CreateStmt *) stmt,
1001  RELKIND_RELATION,
1002  InvalidOid, NULL,
1003  queryString);
1005  secondaryObject,
1006  stmt);
1007 
1008  /*
1009  * Let NewRelationCreateToastTable decide if this
1010  * one needs a secondary relation too.
1011  */
1013 
1014  /*
1015  * parse and validate reloptions for the toast
1016  * table
1017  */
1018  toast_options = transformRelOptions((Datum) 0,
1019  ((CreateStmt *) stmt)->options,
1020  "toast",
1021  validnsps,
1022  true,
1023  false);
1024  (void) heap_reloptions(RELKIND_TOASTVALUE,
1025  toast_options,
1026  true);
1027 
1029  toast_options);
1030  }
1031  else if (IsA(stmt, CreateForeignTableStmt))
1032  {
1033  /* Create the table itself */
1034  address = DefineRelation((CreateStmt *) stmt,
1035  RELKIND_FOREIGN_TABLE,
1036  InvalidOid, NULL,
1037  queryString);
1039  address.objectId);
1041  secondaryObject,
1042  stmt);
1043  }
1044  else
1045  {
1046  /*
1047  * Recurse for anything else. Note the recursive
1048  * call will stash the objects so created into our
1049  * event trigger context.
1050  */
1051  PlannedStmt *wrapper;
1052 
1053  wrapper = makeNode(PlannedStmt);
1054  wrapper->commandType = CMD_UTILITY;
1055  wrapper->canSetTag = false;
1056  wrapper->utilityStmt = stmt;
1057  wrapper->stmt_location = pstmt->stmt_location;
1058  wrapper->stmt_len = pstmt->stmt_len;
1059 
1060  ProcessUtility(wrapper,
1061  queryString,
1063  params,
1064  NULL,
1065  None_Receiver,
1066  NULL);
1067  }
1068 
1069  /* Need CCI between commands */
1070  if (lnext(l) != NULL)
1072  }
1073 
1074  /*
1075  * The multiple commands generated here are stashed
1076  * individually, so disable collection below.
1077  */
1078  commandCollected = true;
1079  }
1080  break;
1081 
1082  case T_AlterTableStmt:
1083  {
1084  AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
1085  Oid relid;
1086  List *stmts;
1087  ListCell *l;
1088  LOCKMODE lockmode;
1089 
1090  /*
1091  * Figure out lock mode, and acquire lock. This also does
1092  * basic permissions checks, so that we won't wait for a
1093  * lock on (for example) a relation on which we have no
1094  * permissions.
1095  */
1096  lockmode = AlterTableGetLockLevel(atstmt->cmds);
1097  relid = AlterTableLookupRelation(atstmt, lockmode);
1098 
1099  if (OidIsValid(relid))
1100  {
1101  /* Run parse analysis ... */
1102  stmts = transformAlterTableStmt(relid, atstmt,
1103  queryString);
1104 
1105  /* ... ensure we have an event trigger context ... */
1106  EventTriggerAlterTableStart(parsetree);
1108 
1109  /* ... and do it */
1110  foreach(l, stmts)
1111  {
1112  Node *stmt = (Node *) lfirst(l);
1113 
1114  if (IsA(stmt, AlterTableStmt))
1115  {
1116  /* Do the table alteration proper */
1117  AlterTable(relid, lockmode,
1118  (AlterTableStmt *) stmt);
1119  }
1120  else
1121  {
1122  /*
1123  * Recurse for anything else. If we need to
1124  * do so, "close" the current complex-command
1125  * set, and start a new one at the bottom;
1126  * this is needed to ensure the ordering of
1127  * queued commands is consistent with the way
1128  * they are executed here.
1129  */
1130  PlannedStmt *wrapper;
1131 
1133  wrapper = makeNode(PlannedStmt);
1134  wrapper->commandType = CMD_UTILITY;
1135  wrapper->canSetTag = false;
1136  wrapper->utilityStmt = stmt;
1137  wrapper->stmt_location = pstmt->stmt_location;
1138  wrapper->stmt_len = pstmt->stmt_len;
1139  ProcessUtility(wrapper,
1140  queryString,
1142  params,
1143  NULL,
1144  None_Receiver,
1145  NULL);
1146  EventTriggerAlterTableStart(parsetree);
1148  }
1149 
1150  /* Need CCI between commands */
1151  if (lnext(l) != NULL)
1153  }
1154 
1155  /* done */
1157  }
1158  else
1159  ereport(NOTICE,
1160  (errmsg("relation \"%s\" does not exist, skipping",
1161  atstmt->relation->relname)));
1162  }
1163 
1164  /* ALTER TABLE stashes commands internally */
1165  commandCollected = true;
1166  break;
1167 
1168  case T_AlterDomainStmt:
1169  {
1170  AlterDomainStmt *stmt = (AlterDomainStmt *) parsetree;
1171 
1172  /*
1173  * Some or all of these functions are recursive to cover
1174  * inherited things, so permission checks are done there.
1175  */
1176  switch (stmt->subtype)
1177  {
1178  case 'T': /* ALTER DOMAIN DEFAULT */
1179 
1180  /*
1181  * Recursively alter column default for table and,
1182  * if requested, for descendants
1183  */
1184  address =
1186  stmt->def);
1187  break;
1188  case 'N': /* ALTER DOMAIN DROP NOT NULL */
1189  address =
1191  false);
1192  break;
1193  case 'O': /* ALTER DOMAIN SET NOT NULL */
1194  address =
1196  true);
1197  break;
1198  case 'C': /* ADD CONSTRAINT */
1199  address =
1201  stmt->def,
1202  &secondaryObject);
1203  break;
1204  case 'X': /* DROP CONSTRAINT */
1205  address =
1207  stmt->name,
1208  stmt->behavior,
1209  stmt->missing_ok);
1210  break;
1211  case 'V': /* VALIDATE CONSTRAINT */
1212  address =
1214  stmt->name);
1215  break;
1216  default: /* oops */
1217  elog(ERROR, "unrecognized alter domain type: %d",
1218  (int) stmt->subtype);
1219  break;
1220  }
1221  }
1222  break;
1223 
1224  /*
1225  * ************* object creation / destruction **************
1226  */
1227  case T_DefineStmt:
1228  {
1229  DefineStmt *stmt = (DefineStmt *) parsetree;
1230 
1231  switch (stmt->kind)
1232  {
1233  case OBJECT_AGGREGATE:
1234  address =
1235  DefineAggregate(pstate, stmt->defnames, stmt->args,
1236  stmt->oldstyle,
1237  stmt->definition);
1238  break;
1239  case OBJECT_OPERATOR:
1240  Assert(stmt->args == NIL);
1241  address = DefineOperator(stmt->defnames,
1242  stmt->definition);
1243  break;
1244  case OBJECT_TYPE:
1245  Assert(stmt->args == NIL);
1246  address = DefineType(pstate,
1247  stmt->defnames,
1248  stmt->definition);
1249  break;
1250  case OBJECT_TSPARSER:
1251  Assert(stmt->args == NIL);
1252  address = DefineTSParser(stmt->defnames,
1253  stmt->definition);
1254  break;
1255  case OBJECT_TSDICTIONARY:
1256  Assert(stmt->args == NIL);
1257  address = DefineTSDictionary(stmt->defnames,
1258  stmt->definition);
1259  break;
1260  case OBJECT_TSTEMPLATE:
1261  Assert(stmt->args == NIL);
1262  address = DefineTSTemplate(stmt->defnames,
1263  stmt->definition);
1264  break;
1266  Assert(stmt->args == NIL);
1267  address = DefineTSConfiguration(stmt->defnames,
1268  stmt->definition,
1269  &secondaryObject);
1270  break;
1271  case OBJECT_COLLATION:
1272  Assert(stmt->args == NIL);
1273  address = DefineCollation(pstate,
1274  stmt->defnames,
1275  stmt->definition,
1276  stmt->if_not_exists);
1277  break;
1278  default:
1279  elog(ERROR, "unrecognized define stmt type: %d",
1280  (int) stmt->kind);
1281  break;
1282  }
1283  }
1284  break;
1285 
1286  case T_IndexStmt: /* CREATE INDEX */
1287  {
1288  IndexStmt *stmt = (IndexStmt *) parsetree;
1289  Oid relid;
1290  LOCKMODE lockmode;
1291 
1292  if (stmt->concurrent)
1293  PreventInTransactionBlock(isTopLevel,
1294  "CREATE INDEX CONCURRENTLY");
1295 
1296  /*
1297  * Look up the relation OID just once, right here at the
1298  * beginning, so that we don't end up repeating the name
1299  * lookup later and latching onto a different relation
1300  * partway through. To avoid lock upgrade hazards, it's
1301  * important that we take the strongest lock that will
1302  * eventually be needed here, so the lockmode calculation
1303  * needs to match what DefineIndex() does.
1304  */
1305  lockmode = stmt->concurrent ? ShareUpdateExclusiveLock
1306  : ShareLock;
1307  relid =
1308  RangeVarGetRelidExtended(stmt->relation, lockmode,
1309  0,
1311  NULL);
1312 
1313  /*
1314  * CREATE INDEX on partitioned tables (but not regular
1315  * inherited tables) recurses to partitions, so we must
1316  * acquire locks early to avoid deadlocks.
1317  *
1318  * We also take the opportunity to verify that all
1319  * partitions are something we can put an index on,
1320  * to avoid building some indexes only to fail later.
1321  */
1322  if (stmt->relation->inh &&
1323  get_rel_relkind(relid) == RELKIND_PARTITIONED_TABLE)
1324  {
1325  ListCell *lc;
1326  List *inheritors = NIL;
1327 
1328  inheritors = find_all_inheritors(relid, lockmode, NULL);
1329  foreach(lc, inheritors)
1330  {
1331  char relkind = get_rel_relkind(lfirst_oid(lc));
1332 
1333  if (relkind != RELKIND_RELATION &&
1334  relkind != RELKIND_MATVIEW &&
1335  relkind != RELKIND_PARTITIONED_TABLE)
1336  ereport(ERROR,
1337  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1338  errmsg("cannot create index on partitioned table \"%s\"",
1339  stmt->relation->relname),
1340  errdetail("Table \"%s\" contains partitions that are foreign tables.",
1341  stmt->relation->relname)));
1342  }
1343  list_free(inheritors);
1344  }
1345 
1346  /* Run parse analysis ... */
1347  stmt = transformIndexStmt(relid, stmt, queryString);
1348 
1349  /* ... and do it */
1350  EventTriggerAlterTableStart(parsetree);
1351  address =
1352  DefineIndex(relid, /* OID of heap relation */
1353  stmt,
1354  InvalidOid, /* no predefined OID */
1355  InvalidOid, /* no parent index */
1356  InvalidOid, /* no parent constraint */
1357  false, /* is_alter_table */
1358  true, /* check_rights */
1359  true, /* check_not_in_use */
1360  false, /* skip_build */
1361  false); /* quiet */
1362 
1363  /*
1364  * Add the CREATE INDEX node itself to stash right away;
1365  * if there were any commands stashed in the ALTER TABLE
1366  * code, we need them to appear after this one.
1367  */
1368  EventTriggerCollectSimpleCommand(address, secondaryObject,
1369  parsetree);
1370  commandCollected = true;
1372  }
1373  break;
1374 
1375  case T_CreateExtensionStmt:
1376  address = CreateExtension(pstate, (CreateExtensionStmt *) parsetree);
1377  break;
1378 
1379  case T_AlterExtensionStmt:
1380  address = ExecAlterExtensionStmt(pstate, (AlterExtensionStmt *) parsetree);
1381  break;
1382 
1385  &secondaryObject);
1386  break;
1387 
1388  case T_CreateFdwStmt:
1389  address = CreateForeignDataWrapper((CreateFdwStmt *) parsetree);
1390  break;
1391 
1392  case T_AlterFdwStmt:
1393  address = AlterForeignDataWrapper((AlterFdwStmt *) parsetree);
1394  break;
1395 
1397  address = CreateForeignServer((CreateForeignServerStmt *) parsetree);
1398  break;
1399 
1401  address = AlterForeignServer((AlterForeignServerStmt *) parsetree);
1402  break;
1403 
1405  address = CreateUserMapping((CreateUserMappingStmt *) parsetree);
1406  break;
1407 
1409  address = AlterUserMapping((AlterUserMappingStmt *) parsetree);
1410  break;
1411 
1412  case T_DropUserMappingStmt:
1413  RemoveUserMapping((DropUserMappingStmt *) parsetree);
1414  /* no commands stashed for DROP */
1415  commandCollected = true;
1416  break;
1417 
1420  /* commands are stashed inside ImportForeignSchema */
1421  commandCollected = true;
1422  break;
1423 
1424  case T_CompositeTypeStmt: /* CREATE TYPE (composite) */
1425  {
1426  CompositeTypeStmt *stmt = (CompositeTypeStmt *) parsetree;
1427 
1428  address = DefineCompositeType(stmt->typevar,
1429  stmt->coldeflist);
1430  }
1431  break;
1432 
1433  case T_CreateEnumStmt: /* CREATE TYPE AS ENUM */
1434  address = DefineEnum((CreateEnumStmt *) parsetree);
1435  break;
1436 
1437  case T_CreateRangeStmt: /* CREATE TYPE AS RANGE */
1438  address = DefineRange((CreateRangeStmt *) parsetree);
1439  break;
1440 
1441  case T_AlterEnumStmt: /* ALTER TYPE (enum) */
1442  address = AlterEnum((AlterEnumStmt *) parsetree, isTopLevel);
1443  break;
1444 
1445  case T_ViewStmt: /* CREATE VIEW */
1446  EventTriggerAlterTableStart(parsetree);
1447  address = DefineView((ViewStmt *) parsetree, queryString,
1448  pstmt->stmt_location, pstmt->stmt_len);
1449  EventTriggerCollectSimpleCommand(address, secondaryObject,
1450  parsetree);
1451  /* stashed internally */
1452  commandCollected = true;
1454  break;
1455 
1456  case T_CreateFunctionStmt: /* CREATE FUNCTION */
1457  address = CreateFunction(pstate, (CreateFunctionStmt *) parsetree);
1458  break;
1459 
1460  case T_AlterFunctionStmt: /* ALTER FUNCTION */
1461  address = AlterFunction(pstate, (AlterFunctionStmt *) parsetree);
1462  break;
1463 
1464  case T_RuleStmt: /* CREATE RULE */
1465  address = DefineRule((RuleStmt *) parsetree, queryString);
1466  break;
1467 
1468  case T_CreateSeqStmt:
1469  address = DefineSequence(pstate, (CreateSeqStmt *) parsetree);
1470  break;
1471 
1472  case T_AlterSeqStmt:
1473  address = AlterSequence(pstate, (AlterSeqStmt *) parsetree);
1474  break;
1475 
1476  case T_CreateTableAsStmt:
1477  address = ExecCreateTableAs((CreateTableAsStmt *) parsetree,
1478  queryString, params, queryEnv,
1479  completionTag);
1480  break;
1481 
1482  case T_RefreshMatViewStmt:
1483 
1484  /*
1485  * REFRESH CONCURRENTLY executes some DDL commands internally.
1486  * Inhibit DDL command collection here to avoid those commands
1487  * from showing up in the deparsed command queue. The refresh
1488  * command itself is queued, which is enough.
1489  */
1491  PG_TRY();
1492  {
1493  address = ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
1494  queryString, params, completionTag);
1495  }
1496  PG_CATCH();
1497  {
1499  PG_RE_THROW();
1500  }
1501  PG_END_TRY();
1503  break;
1504 
1505  case T_CreateTrigStmt:
1506  address = CreateTrigger((CreateTrigStmt *) parsetree,
1507  queryString, InvalidOid, InvalidOid,
1509  InvalidOid, NULL, false, false);
1510  break;
1511 
1512  case T_CreatePLangStmt:
1513  address = CreateProceduralLanguage((CreatePLangStmt *) parsetree);
1514  break;
1515 
1516  case T_CreateDomainStmt:
1517  address = DefineDomain((CreateDomainStmt *) parsetree);
1518  break;
1519 
1521  address = CreateConversionCommand((CreateConversionStmt *) parsetree);
1522  break;
1523 
1524  case T_CreateCastStmt:
1525  address = CreateCast((CreateCastStmt *) parsetree);
1526  break;
1527 
1528  case T_CreateOpClassStmt:
1529  DefineOpClass((CreateOpClassStmt *) parsetree);
1530  /* command is stashed in DefineOpClass */
1531  commandCollected = true;
1532  break;
1533 
1534  case T_CreateOpFamilyStmt:
1535  address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1536  break;
1537 
1538  case T_CreateTransformStmt:
1539  address = CreateTransform((CreateTransformStmt *) parsetree);
1540  break;
1541 
1542  case T_AlterOpFamilyStmt:
1543  AlterOpFamily((AlterOpFamilyStmt *) parsetree);
1544  /* commands are stashed in AlterOpFamily */
1545  commandCollected = true;
1546  break;
1547 
1549  address = AlterTSDictionary((AlterTSDictionaryStmt *) parsetree);
1550  break;
1551 
1554 
1555  /*
1556  * Commands are stashed in MakeConfigurationMapping and
1557  * DropConfigurationMapping, which are called from
1558  * AlterTSConfiguration
1559  */
1560  commandCollected = true;
1561  break;
1562 
1565  /* commands are stashed in AlterTableMoveAll */
1566  commandCollected = true;
1567  break;
1568 
1569  case T_DropStmt:
1570  ExecDropStmt((DropStmt *) parsetree, isTopLevel);
1571  /* no commands stashed for DROP */
1572  commandCollected = true;
1573  break;
1574 
1575  case T_RenameStmt:
1576  address = ExecRenameStmt((RenameStmt *) parsetree);
1577  break;
1578 
1580  address =
1582  &secondaryObject);
1583  break;
1584 
1586  address =
1588  &secondaryObject);
1589  break;
1590 
1591  case T_AlterOwnerStmt:
1592  address = ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
1593  break;
1594 
1595  case T_AlterOperatorStmt:
1596  address = AlterOperator((AlterOperatorStmt *) parsetree);
1597  break;
1598 
1599  case T_CommentStmt:
1600  address = CommentObject((CommentStmt *) parsetree);
1601  break;
1602 
1603  case T_GrantStmt:
1604  ExecuteGrantStmt((GrantStmt *) parsetree);
1605  /* commands are stashed in ExecGrantStmt_oids */
1606  commandCollected = true;
1607  break;
1608 
1609  case T_DropOwnedStmt:
1610  DropOwnedObjects((DropOwnedStmt *) parsetree);
1611  /* no commands stashed for DROP */
1612  commandCollected = true;
1613  break;
1614 
1618  commandCollected = true;
1619  break;
1620 
1621  case T_CreatePolicyStmt: /* CREATE POLICY */
1622  address = CreatePolicy((CreatePolicyStmt *) parsetree);
1623  break;
1624 
1625  case T_AlterPolicyStmt: /* ALTER POLICY */
1626  address = AlterPolicy((AlterPolicyStmt *) parsetree);
1627  break;
1628 
1629  case T_SecLabelStmt:
1630  address = ExecSecLabelStmt((SecLabelStmt *) parsetree);
1631  break;
1632 
1633  case T_CreateAmStmt:
1634  address = CreateAccessMethod((CreateAmStmt *) parsetree);
1635  break;
1636 
1638  address = CreatePublication((CreatePublicationStmt *) parsetree);
1639  break;
1640 
1642  AlterPublication((AlterPublicationStmt *) parsetree);
1643 
1644  /*
1645  * AlterPublication calls EventTriggerCollectSimpleCommand
1646  * directly
1647  */
1648  commandCollected = true;
1649  break;
1650 
1652  address = CreateSubscription((CreateSubscriptionStmt *) parsetree,
1653  isTopLevel);
1654  break;
1655 
1657  address = AlterSubscription((AlterSubscriptionStmt *) parsetree);
1658  break;
1659 
1661  DropSubscription((DropSubscriptionStmt *) parsetree, isTopLevel);
1662  /* no commands stashed for DROP */
1663  commandCollected = true;
1664  break;
1665 
1666  case T_CreateStatsStmt:
1667  address = CreateStatistics((CreateStatsStmt *) parsetree);
1668  break;
1669 
1670  case T_AlterCollationStmt:
1671  address = AlterCollation((AlterCollationStmt *) parsetree);
1672  break;
1673 
1674  default:
1675  elog(ERROR, "unrecognized node type: %d",
1676  (int) nodeTag(parsetree));
1677  break;
1678  }
1679 
1680  /*
1681  * Remember the object so that ddl_command_end event triggers have
1682  * access to it.
1683  */
1684  if (!commandCollected)
1685  EventTriggerCollectSimpleCommand(address, secondaryObject,
1686  parsetree);
1687 
1688  if (isCompleteQuery)
1689  {
1690  EventTriggerSQLDrop(parsetree);
1691  EventTriggerDDLCommandEnd(parsetree);
1692  }
1693  }
1694  PG_CATCH();
1695  {
1696  if (needCleanup)
1698  PG_RE_THROW();
1699  }
1700  PG_END_TRY();
1701 
1702  if (needCleanup)
1704 }
1705 
1706 /*
1707  * Dispatch function for DropStmt
1708  */
1709 static void
1710 ExecDropStmt(DropStmt *stmt, bool isTopLevel)
1711 {
1712  switch (stmt->removeType)
1713  {
1714  case OBJECT_INDEX:
1715  if (stmt->concurrent)
1716  PreventInTransactionBlock(isTopLevel,
1717  "DROP INDEX CONCURRENTLY");
1718  /* fall through */
1719 
1720  case OBJECT_TABLE:
1721  case OBJECT_SEQUENCE:
1722  case OBJECT_VIEW:
1723  case OBJECT_MATVIEW:
1724  case OBJECT_FOREIGN_TABLE:
1725  RemoveRelations(stmt);
1726  break;
1727  default:
1728  RemoveObjects(stmt);
1729  break;
1730  }
1731 }
1732 
1733 
1734 /*
1735  * UtilityReturnsTuples
1736  * Return "true" if this utility statement will send output to the
1737  * destination.
1738  *
1739  * Generally, there should be a case here for each case in ProcessUtility
1740  * where "dest" is passed on.
1741  */
1742 bool
1744 {
1745  switch (nodeTag(parsetree))
1746  {
1747  case T_FetchStmt:
1748  {
1749  FetchStmt *stmt = (FetchStmt *) parsetree;
1750  Portal portal;
1751 
1752  if (stmt->ismove)
1753  return false;
1754  portal = GetPortalByName(stmt->portalname);
1755  if (!PortalIsValid(portal))
1756  return false; /* not our business to raise error */
1757  return portal->tupDesc ? true : false;
1758  }
1759 
1760  case T_ExecuteStmt:
1761  {
1762  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1763  PreparedStatement *entry;
1764 
1765  entry = FetchPreparedStatement(stmt->name, false);
1766  if (!entry)
1767  return false; /* not our business to raise error */
1768  if (entry->plansource->resultDesc)
1769  return true;
1770  return false;
1771  }
1772 
1773  case T_ExplainStmt:
1774  return true;
1775 
1776  case T_VariableShowStmt:
1777  return true;
1778 
1779  default:
1780  return false;
1781  }
1782 }
1783 
1784 /*
1785  * UtilityTupleDescriptor
1786  * Fetch the actual output tuple descriptor for a utility statement
1787  * for which UtilityReturnsTuples() previously returned "true".
1788  *
1789  * The returned descriptor is created in (or copied into) the current memory
1790  * context.
1791  */
1792 TupleDesc
1794 {
1795  switch (nodeTag(parsetree))
1796  {
1797  case T_FetchStmt:
1798  {
1799  FetchStmt *stmt = (FetchStmt *) parsetree;
1800  Portal portal;
1801 
1802  if (stmt->ismove)
1803  return NULL;
1804  portal = GetPortalByName(stmt->portalname);
1805  if (!PortalIsValid(portal))
1806  return NULL; /* not our business to raise error */
1807  return CreateTupleDescCopy(portal->tupDesc);
1808  }
1809 
1810  case T_ExecuteStmt:
1811  {
1812  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1813  PreparedStatement *entry;
1814 
1815  entry = FetchPreparedStatement(stmt->name, false);
1816  if (!entry)
1817  return NULL; /* not our business to raise error */
1818  return FetchPreparedStatementResultDesc(entry);
1819  }
1820 
1821  case T_ExplainStmt:
1822  return ExplainResultDesc((ExplainStmt *) parsetree);
1823 
1824  case T_VariableShowStmt:
1825  {
1826  VariableShowStmt *n = (VariableShowStmt *) parsetree;
1827 
1828  return GetPGVariableResultDesc(n->name);
1829  }
1830 
1831  default:
1832  return NULL;
1833  }
1834 }
1835 
1836 
1837 /*
1838  * QueryReturnsTuples
1839  * Return "true" if this Query will send output to the destination.
1840  */
1841 #ifdef NOT_USED
1842 bool
1843 QueryReturnsTuples(Query *parsetree)
1844 {
1845  switch (parsetree->commandType)
1846  {
1847  case CMD_SELECT:
1848  /* returns tuples */
1849  return true;
1850  case CMD_INSERT:
1851  case CMD_UPDATE:
1852  case CMD_DELETE:
1853  /* the forms with RETURNING return tuples */
1854  if (parsetree->returningList)
1855  return true;
1856  break;
1857  case CMD_UTILITY:
1858  return UtilityReturnsTuples(parsetree->utilityStmt);
1859  case CMD_UNKNOWN:
1860  case CMD_NOTHING:
1861  /* probably shouldn't get here */
1862  break;
1863  }
1864  return false; /* default */
1865 }
1866 #endif
1867 
1868 
1869 /*
1870  * UtilityContainsQuery
1871  * Return the contained Query, or NULL if there is none
1872  *
1873  * Certain utility statements, such as EXPLAIN, contain a plannable Query.
1874  * This function encapsulates knowledge of exactly which ones do.
1875  * We assume it is invoked only on already-parse-analyzed statements
1876  * (else the contained parsetree isn't a Query yet).
1877  *
1878  * In some cases (currently, only EXPLAIN of CREATE TABLE AS/SELECT INTO and
1879  * CREATE MATERIALIZED VIEW), potentially Query-containing utility statements
1880  * can be nested. This function will drill down to a non-utility Query, or
1881  * return NULL if none.
1882  */
1883 Query *
1885 {
1886  Query *qry;
1887 
1888  switch (nodeTag(parsetree))
1889  {
1890  case T_DeclareCursorStmt:
1891  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
1892  if (qry->commandType == CMD_UTILITY)
1893  return UtilityContainsQuery(qry->utilityStmt);
1894  return qry;
1895 
1896  case T_ExplainStmt:
1897  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
1898  if (qry->commandType == CMD_UTILITY)
1899  return UtilityContainsQuery(qry->utilityStmt);
1900  return qry;
1901 
1902  case T_CreateTableAsStmt:
1903  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
1904  if (qry->commandType == CMD_UTILITY)
1905  return UtilityContainsQuery(qry->utilityStmt);
1906  return qry;
1907 
1908  default:
1909  return NULL;
1910  }
1911 }
1912 
1913 
1914 /*
1915  * AlterObjectTypeCommandTag
1916  * helper function for CreateCommandTag
1917  *
1918  * This covers most cases where ALTER is used with an ObjectType enum.
1919  */
1920 static const char *
1922 {
1923  const char *tag;
1924 
1925  switch (objtype)
1926  {
1927  case OBJECT_AGGREGATE:
1928  tag = "ALTER AGGREGATE";
1929  break;
1930  case OBJECT_ATTRIBUTE:
1931  tag = "ALTER TYPE";
1932  break;
1933  case OBJECT_CAST:
1934  tag = "ALTER CAST";
1935  break;
1936  case OBJECT_COLLATION:
1937  tag = "ALTER COLLATION";
1938  break;
1939  case OBJECT_COLUMN:
1940  tag = "ALTER TABLE";
1941  break;
1942  case OBJECT_CONVERSION:
1943  tag = "ALTER CONVERSION";
1944  break;
1945  case OBJECT_DATABASE:
1946  tag = "ALTER DATABASE";
1947  break;
1948  case OBJECT_DOMAIN:
1949  case OBJECT_DOMCONSTRAINT:
1950  tag = "ALTER DOMAIN";
1951  break;
1952  case OBJECT_EXTENSION:
1953  tag = "ALTER EXTENSION";
1954  break;
1955  case OBJECT_FDW:
1956  tag = "ALTER FOREIGN DATA WRAPPER";
1957  break;
1958  case OBJECT_FOREIGN_SERVER:
1959  tag = "ALTER SERVER";
1960  break;
1961  case OBJECT_FOREIGN_TABLE:
1962  tag = "ALTER FOREIGN TABLE";
1963  break;
1964  case OBJECT_FUNCTION:
1965  tag = "ALTER FUNCTION";
1966  break;
1967  case OBJECT_INDEX:
1968  tag = "ALTER INDEX";
1969  break;
1970  case OBJECT_LANGUAGE:
1971  tag = "ALTER LANGUAGE";
1972  break;
1973  case OBJECT_LARGEOBJECT:
1974  tag = "ALTER LARGE OBJECT";
1975  break;
1976  case OBJECT_OPCLASS:
1977  tag = "ALTER OPERATOR CLASS";
1978  break;
1979  case OBJECT_OPERATOR:
1980  tag = "ALTER OPERATOR";
1981  break;
1982  case OBJECT_OPFAMILY:
1983  tag = "ALTER OPERATOR FAMILY";
1984  break;
1985  case OBJECT_POLICY:
1986  tag = "ALTER POLICY";
1987  break;
1988  case OBJECT_PROCEDURE:
1989  tag = "ALTER PROCEDURE";
1990  break;
1991  case OBJECT_ROLE:
1992  tag = "ALTER ROLE";
1993  break;
1994  case OBJECT_ROUTINE:
1995  tag = "ALTER ROUTINE";
1996  break;
1997  case OBJECT_RULE:
1998  tag = "ALTER RULE";
1999  break;
2000  case OBJECT_SCHEMA:
2001  tag = "ALTER SCHEMA";
2002  break;
2003  case OBJECT_SEQUENCE:
2004  tag = "ALTER SEQUENCE";
2005  break;
2006  case OBJECT_TABLE:
2007  case OBJECT_TABCONSTRAINT:
2008  tag = "ALTER TABLE";
2009  break;
2010  case OBJECT_TABLESPACE:
2011  tag = "ALTER TABLESPACE";
2012  break;
2013  case OBJECT_TRIGGER:
2014  tag = "ALTER TRIGGER";
2015  break;
2016  case OBJECT_EVENT_TRIGGER:
2017  tag = "ALTER EVENT TRIGGER";
2018  break;
2020  tag = "ALTER TEXT SEARCH CONFIGURATION";
2021  break;
2022  case OBJECT_TSDICTIONARY:
2023  tag = "ALTER TEXT SEARCH DICTIONARY";
2024  break;
2025  case OBJECT_TSPARSER:
2026  tag = "ALTER TEXT SEARCH PARSER";
2027  break;
2028  case OBJECT_TSTEMPLATE:
2029  tag = "ALTER TEXT SEARCH TEMPLATE";
2030  break;
2031  case OBJECT_TYPE:
2032  tag = "ALTER TYPE";
2033  break;
2034  case OBJECT_VIEW:
2035  tag = "ALTER VIEW";
2036  break;
2037  case OBJECT_MATVIEW:
2038  tag = "ALTER MATERIALIZED VIEW";
2039  break;
2040  case OBJECT_PUBLICATION:
2041  tag = "ALTER PUBLICATION";
2042  break;
2043  case OBJECT_SUBSCRIPTION:
2044  tag = "ALTER SUBSCRIPTION";
2045  break;
2046  case OBJECT_STATISTIC_EXT:
2047  tag = "ALTER STATISTICS";
2048  break;
2049  default:
2050  tag = "???";
2051  break;
2052  }
2053 
2054  return tag;
2055 }
2056 
2057 /*
2058  * CreateCommandTag
2059  * utility to get a string representation of the command operation,
2060  * given either a raw (un-analyzed) parsetree, an analyzed Query,
2061  * or a PlannedStmt.
2062  *
2063  * This must handle all command types, but since the vast majority
2064  * of 'em are utility commands, it seems sensible to keep it here.
2065  *
2066  * NB: all result strings must be shorter than COMPLETION_TAG_BUFSIZE.
2067  * Also, the result must point at a true constant (permanent storage).
2068  */
2069 const char *
2071 {
2072  const char *tag;
2073 
2074  switch (nodeTag(parsetree))
2075  {
2076  /* recurse if we're given a RawStmt */
2077  case T_RawStmt:
2078  tag = CreateCommandTag(((RawStmt *) parsetree)->stmt);
2079  break;
2080 
2081  /* raw plannable queries */
2082  case T_InsertStmt:
2083  tag = "INSERT";
2084  break;
2085 
2086  case T_DeleteStmt:
2087  tag = "DELETE";
2088  break;
2089 
2090  case T_UpdateStmt:
2091  tag = "UPDATE";
2092  break;
2093 
2094  case T_SelectStmt:
2095  tag = "SELECT";
2096  break;
2097 
2098  /* utility statements --- same whether raw or cooked */
2099  case T_TransactionStmt:
2100  {
2101  TransactionStmt *stmt = (TransactionStmt *) parsetree;
2102 
2103  switch (stmt->kind)
2104  {
2105  case TRANS_STMT_BEGIN:
2106  tag = "BEGIN";
2107  break;
2108 
2109  case TRANS_STMT_START:
2110  tag = "START TRANSACTION";
2111  break;
2112 
2113  case TRANS_STMT_COMMIT:
2114  tag = "COMMIT";
2115  break;
2116 
2117  case TRANS_STMT_ROLLBACK:
2119  tag = "ROLLBACK";
2120  break;
2121 
2122  case TRANS_STMT_SAVEPOINT:
2123  tag = "SAVEPOINT";
2124  break;
2125 
2126  case TRANS_STMT_RELEASE:
2127  tag = "RELEASE";
2128  break;
2129 
2130  case TRANS_STMT_PREPARE:
2131  tag = "PREPARE TRANSACTION";
2132  break;
2133 
2135  tag = "COMMIT PREPARED";
2136  break;
2137 
2139  tag = "ROLLBACK PREPARED";
2140  break;
2141 
2142  default:
2143  tag = "???";
2144  break;
2145  }
2146  }
2147  break;
2148 
2149  case T_DeclareCursorStmt:
2150  tag = "DECLARE CURSOR";
2151  break;
2152 
2153  case T_ClosePortalStmt:
2154  {
2155  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
2156 
2157  if (stmt->portalname == NULL)
2158  tag = "CLOSE CURSOR ALL";
2159  else
2160  tag = "CLOSE CURSOR";
2161  }
2162  break;
2163 
2164  case T_FetchStmt:
2165  {
2166  FetchStmt *stmt = (FetchStmt *) parsetree;
2167 
2168  tag = (stmt->ismove) ? "MOVE" : "FETCH";
2169  }
2170  break;
2171 
2172  case T_CreateDomainStmt:
2173  tag = "CREATE DOMAIN";
2174  break;
2175 
2176  case T_CreateSchemaStmt:
2177  tag = "CREATE SCHEMA";
2178  break;
2179 
2180  case T_CreateStmt:
2181  tag = "CREATE TABLE";
2182  break;
2183 
2185  tag = "CREATE TABLESPACE";
2186  break;
2187 
2188  case T_DropTableSpaceStmt:
2189  tag = "DROP TABLESPACE";
2190  break;
2191 
2193  tag = "ALTER TABLESPACE";
2194  break;
2195 
2196  case T_CreateExtensionStmt:
2197  tag = "CREATE EXTENSION";
2198  break;
2199 
2200  case T_AlterExtensionStmt:
2201  tag = "ALTER EXTENSION";
2202  break;
2203 
2205  tag = "ALTER EXTENSION";
2206  break;
2207 
2208  case T_CreateFdwStmt:
2209  tag = "CREATE FOREIGN DATA WRAPPER";
2210  break;
2211 
2212  case T_AlterFdwStmt:
2213  tag = "ALTER FOREIGN DATA WRAPPER";
2214  break;
2215 
2217  tag = "CREATE SERVER";
2218  break;
2219 
2221  tag = "ALTER SERVER";
2222  break;
2223 
2225  tag = "CREATE USER MAPPING";
2226  break;
2227 
2229  tag = "ALTER USER MAPPING";
2230  break;
2231 
2232  case T_DropUserMappingStmt:
2233  tag = "DROP USER MAPPING";
2234  break;
2235 
2237  tag = "CREATE FOREIGN TABLE";
2238  break;
2239 
2241  tag = "IMPORT FOREIGN SCHEMA";
2242  break;
2243 
2244  case T_DropStmt:
2245  switch (((DropStmt *) parsetree)->removeType)
2246  {
2247  case OBJECT_TABLE:
2248  tag = "DROP TABLE";
2249  break;
2250  case OBJECT_SEQUENCE:
2251  tag = "DROP SEQUENCE";
2252  break;
2253  case OBJECT_VIEW:
2254  tag = "DROP VIEW";
2255  break;
2256  case OBJECT_MATVIEW:
2257  tag = "DROP MATERIALIZED VIEW";
2258  break;
2259  case OBJECT_INDEX:
2260  tag = "DROP INDEX";
2261  break;
2262  case OBJECT_TYPE:
2263  tag = "DROP TYPE";
2264  break;
2265  case OBJECT_DOMAIN:
2266  tag = "DROP DOMAIN";
2267  break;
2268  case OBJECT_COLLATION:
2269  tag = "DROP COLLATION";
2270  break;
2271  case OBJECT_CONVERSION:
2272  tag = "DROP CONVERSION";
2273  break;
2274  case OBJECT_SCHEMA:
2275  tag = "DROP SCHEMA";
2276  break;
2277  case OBJECT_TSPARSER:
2278  tag = "DROP TEXT SEARCH PARSER";
2279  break;
2280  case OBJECT_TSDICTIONARY:
2281  tag = "DROP TEXT SEARCH DICTIONARY";
2282  break;
2283  case OBJECT_TSTEMPLATE:
2284  tag = "DROP TEXT SEARCH TEMPLATE";
2285  break;
2287  tag = "DROP TEXT SEARCH CONFIGURATION";
2288  break;
2289  case OBJECT_FOREIGN_TABLE:
2290  tag = "DROP FOREIGN TABLE";
2291  break;
2292  case OBJECT_EXTENSION:
2293  tag = "DROP EXTENSION";
2294  break;
2295  case OBJECT_FUNCTION:
2296  tag = "DROP FUNCTION";
2297  break;
2298  case OBJECT_PROCEDURE:
2299  tag = "DROP PROCEDURE";
2300  break;
2301  case OBJECT_ROUTINE:
2302  tag = "DROP ROUTINE";
2303  break;
2304  case OBJECT_AGGREGATE:
2305  tag = "DROP AGGREGATE";
2306  break;
2307  case OBJECT_OPERATOR:
2308  tag = "DROP OPERATOR";
2309  break;
2310  case OBJECT_LANGUAGE:
2311  tag = "DROP LANGUAGE";
2312  break;
2313  case OBJECT_CAST:
2314  tag = "DROP CAST";
2315  break;
2316  case OBJECT_TRIGGER:
2317  tag = "DROP TRIGGER";
2318  break;
2319  case OBJECT_EVENT_TRIGGER:
2320  tag = "DROP EVENT TRIGGER";
2321  break;
2322  case OBJECT_RULE:
2323  tag = "DROP RULE";
2324  break;
2325  case OBJECT_FDW:
2326  tag = "DROP FOREIGN DATA WRAPPER";
2327  break;
2328  case OBJECT_FOREIGN_SERVER:
2329  tag = "DROP SERVER";
2330  break;
2331  case OBJECT_OPCLASS:
2332  tag = "DROP OPERATOR CLASS";
2333  break;
2334  case OBJECT_OPFAMILY:
2335  tag = "DROP OPERATOR FAMILY";
2336  break;
2337  case OBJECT_POLICY:
2338  tag = "DROP POLICY";
2339  break;
2340  case OBJECT_TRANSFORM:
2341  tag = "DROP TRANSFORM";
2342  break;
2343  case OBJECT_ACCESS_METHOD:
2344  tag = "DROP ACCESS METHOD";
2345  break;
2346  case OBJECT_PUBLICATION:
2347  tag = "DROP PUBLICATION";
2348  break;
2349  case OBJECT_STATISTIC_EXT:
2350  tag = "DROP STATISTICS";
2351  break;
2352  default:
2353  tag = "???";
2354  }
2355  break;
2356 
2357  case T_TruncateStmt:
2358  tag = "TRUNCATE TABLE";
2359  break;
2360 
2361  case T_CommentStmt:
2362  tag = "COMMENT";
2363  break;
2364 
2365  case T_SecLabelStmt:
2366  tag = "SECURITY LABEL";
2367  break;
2368 
2369  case T_CopyStmt:
2370  tag = "COPY";
2371  break;
2372 
2373  case T_RenameStmt:
2374  tag = AlterObjectTypeCommandTag(((RenameStmt *) parsetree)->renameType);
2375  break;
2376 
2378  tag = AlterObjectTypeCommandTag(((AlterObjectDependsStmt *) parsetree)->objectType);
2379  break;
2380 
2382  tag = AlterObjectTypeCommandTag(((AlterObjectSchemaStmt *) parsetree)->objectType);
2383  break;
2384 
2385  case T_AlterOwnerStmt:
2386  tag = AlterObjectTypeCommandTag(((AlterOwnerStmt *) parsetree)->objectType);
2387  break;
2388 
2390  tag = AlterObjectTypeCommandTag(((AlterTableMoveAllStmt *) parsetree)->objtype);
2391  break;
2392 
2393  case T_AlterTableStmt:
2394  tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->relkind);
2395  break;
2396 
2397  case T_AlterDomainStmt:
2398  tag = "ALTER DOMAIN";
2399  break;
2400 
2401  case T_AlterFunctionStmt:
2402  switch (((AlterFunctionStmt *) parsetree)->objtype)
2403  {
2404  case OBJECT_FUNCTION:
2405  tag = "ALTER FUNCTION";
2406  break;
2407  case OBJECT_PROCEDURE:
2408  tag = "ALTER PROCEDURE";
2409  break;
2410  case OBJECT_ROUTINE:
2411  tag = "ALTER ROUTINE";
2412  break;
2413  default:
2414  tag = "???";
2415  }
2416  break;
2417 
2418  case T_GrantStmt:
2419  {
2420  GrantStmt *stmt = (GrantStmt *) parsetree;
2421 
2422  tag = (stmt->is_grant) ? "GRANT" : "REVOKE";
2423  }
2424  break;
2425 
2426  case T_GrantRoleStmt:
2427  {
2428  GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;
2429 
2430  tag = (stmt->is_grant) ? "GRANT ROLE" : "REVOKE ROLE";
2431  }
2432  break;
2433 
2435  tag = "ALTER DEFAULT PRIVILEGES";
2436  break;
2437 
2438  case T_DefineStmt:
2439  switch (((DefineStmt *) parsetree)->kind)
2440  {
2441  case OBJECT_AGGREGATE:
2442  tag = "CREATE AGGREGATE";
2443  break;
2444  case OBJECT_OPERATOR:
2445  tag = "CREATE OPERATOR";
2446  break;
2447  case OBJECT_TYPE:
2448  tag = "CREATE TYPE";
2449  break;
2450  case OBJECT_TSPARSER:
2451  tag = "CREATE TEXT SEARCH PARSER";
2452  break;
2453  case OBJECT_TSDICTIONARY:
2454  tag = "CREATE TEXT SEARCH DICTIONARY";
2455  break;
2456  case OBJECT_TSTEMPLATE:
2457  tag = "CREATE TEXT SEARCH TEMPLATE";
2458  break;
2460  tag = "CREATE TEXT SEARCH CONFIGURATION";
2461  break;
2462  case OBJECT_COLLATION:
2463  tag = "CREATE COLLATION";
2464  break;
2465  case OBJECT_ACCESS_METHOD:
2466  tag = "CREATE ACCESS METHOD";
2467  break;
2468  default:
2469  tag = "???";
2470  }
2471  break;
2472 
2473  case T_CompositeTypeStmt:
2474  tag = "CREATE TYPE";
2475  break;
2476 
2477  case T_CreateEnumStmt:
2478  tag = "CREATE TYPE";
2479  break;
2480 
2481  case T_CreateRangeStmt:
2482  tag = "CREATE TYPE";
2483  break;
2484 
2485  case T_AlterEnumStmt:
2486  tag = "ALTER TYPE";
2487  break;
2488 
2489  case T_ViewStmt:
2490  tag = "CREATE VIEW";
2491  break;
2492 
2493  case T_CreateFunctionStmt:
2494  if (((CreateFunctionStmt *) parsetree)->is_procedure)
2495  tag = "CREATE PROCEDURE";
2496  else
2497  tag = "CREATE FUNCTION";
2498  break;
2499 
2500  case T_IndexStmt:
2501  tag = "CREATE INDEX";
2502  break;
2503 
2504  case T_RuleStmt:
2505  tag = "CREATE RULE";
2506  break;
2507 
2508  case T_CreateSeqStmt:
2509  tag = "CREATE SEQUENCE";
2510  break;
2511 
2512  case T_AlterSeqStmt:
2513  tag = "ALTER SEQUENCE";
2514  break;
2515 
2516  case T_DoStmt:
2517  tag = "DO";
2518  break;
2519 
2520  case T_CreatedbStmt:
2521  tag = "CREATE DATABASE";
2522  break;
2523 
2524  case T_AlterDatabaseStmt:
2525  tag = "ALTER DATABASE";
2526  break;
2527 
2529  tag = "ALTER DATABASE";
2530  break;
2531 
2532  case T_DropdbStmt:
2533  tag = "DROP DATABASE";
2534  break;
2535 
2536  case T_NotifyStmt:
2537  tag = "NOTIFY";
2538  break;
2539 
2540  case T_ListenStmt:
2541  tag = "LISTEN";
2542  break;
2543 
2544  case T_UnlistenStmt:
2545  tag = "UNLISTEN";
2546  break;
2547 
2548  case T_LoadStmt:
2549  tag = "LOAD";
2550  break;
2551 
2552  case T_CallStmt:
2553  tag = "CALL";
2554  break;
2555 
2556  case T_ClusterStmt:
2557  tag = "CLUSTER";
2558  break;
2559 
2560  case T_VacuumStmt:
2561  if (((VacuumStmt *) parsetree)->options & VACOPT_VACUUM)
2562  tag = "VACUUM";
2563  else
2564  tag = "ANALYZE";
2565  break;
2566 
2567  case T_ExplainStmt:
2568  tag = "EXPLAIN";
2569  break;
2570 
2571  case T_CreateTableAsStmt:
2572  switch (((CreateTableAsStmt *) parsetree)->relkind)
2573  {
2574  case OBJECT_TABLE:
2575  if (((CreateTableAsStmt *) parsetree)->is_select_into)
2576  tag = "SELECT INTO";
2577  else
2578  tag = "CREATE TABLE AS";
2579  break;
2580  case OBJECT_MATVIEW:
2581  tag = "CREATE MATERIALIZED VIEW";
2582  break;
2583  default:
2584  tag = "???";
2585  }
2586  break;
2587 
2588  case T_RefreshMatViewStmt:
2589  tag = "REFRESH MATERIALIZED VIEW";
2590  break;
2591 
2592  case T_AlterSystemStmt:
2593  tag = "ALTER SYSTEM";
2594  break;
2595 
2596  case T_VariableSetStmt:
2597  switch (((VariableSetStmt *) parsetree)->kind)
2598  {
2599  case VAR_SET_VALUE:
2600  case VAR_SET_CURRENT:
2601  case VAR_SET_DEFAULT:
2602  case VAR_SET_MULTI:
2603  tag = "SET";
2604  break;
2605  case VAR_RESET:
2606  case VAR_RESET_ALL:
2607  tag = "RESET";
2608  break;
2609  default:
2610  tag = "???";
2611  }
2612  break;
2613 
2614  case T_VariableShowStmt:
2615  tag = "SHOW";
2616  break;
2617 
2618  case T_DiscardStmt:
2619  switch (((DiscardStmt *) parsetree)->target)
2620  {
2621  case DISCARD_ALL:
2622  tag = "DISCARD ALL";
2623  break;
2624  case DISCARD_PLANS:
2625  tag = "DISCARD PLANS";
2626  break;
2627  case DISCARD_TEMP:
2628  tag = "DISCARD TEMP";
2629  break;
2630  case DISCARD_SEQUENCES:
2631  tag = "DISCARD SEQUENCES";
2632  break;
2633  default:
2634  tag = "???";
2635  }
2636  break;
2637 
2638  case T_CreateTransformStmt:
2639  tag = "CREATE TRANSFORM";
2640  break;
2641 
2642  case T_CreateTrigStmt:
2643  tag = "CREATE TRIGGER";
2644  break;
2645 
2646  case T_CreateEventTrigStmt:
2647  tag = "CREATE EVENT TRIGGER";
2648  break;
2649 
2650  case T_AlterEventTrigStmt:
2651  tag = "ALTER EVENT TRIGGER";
2652  break;
2653 
2654  case T_CreatePLangStmt:
2655  tag = "CREATE LANGUAGE";
2656  break;
2657 
2658  case T_CreateRoleStmt:
2659  tag = "CREATE ROLE";
2660  break;
2661 
2662  case T_AlterRoleStmt:
2663  tag = "ALTER ROLE";
2664  break;
2665 
2666  case T_AlterRoleSetStmt:
2667  tag = "ALTER ROLE";
2668  break;
2669 
2670  case T_DropRoleStmt:
2671  tag = "DROP ROLE";
2672  break;
2673 
2674  case T_DropOwnedStmt:
2675  tag = "DROP OWNED";
2676  break;
2677 
2678  case T_ReassignOwnedStmt:
2679  tag = "REASSIGN OWNED";
2680  break;
2681 
2682  case T_LockStmt:
2683  tag = "LOCK TABLE";
2684  break;
2685 
2686  case T_ConstraintsSetStmt:
2687  tag = "SET CONSTRAINTS";
2688  break;
2689 
2690  case T_CheckPointStmt:
2691  tag = "CHECKPOINT";
2692  break;
2693 
2694  case T_ReindexStmt:
2695  tag = "REINDEX";
2696  break;
2697 
2699  tag = "CREATE CONVERSION";
2700  break;
2701 
2702  case T_CreateCastStmt:
2703  tag = "CREATE CAST";
2704  break;
2705 
2706  case T_CreateOpClassStmt:
2707  tag = "CREATE OPERATOR CLASS";
2708  break;
2709 
2710  case T_CreateOpFamilyStmt:
2711  tag = "CREATE OPERATOR FAMILY";
2712  break;
2713 
2714  case T_AlterOpFamilyStmt:
2715  tag = "ALTER OPERATOR FAMILY";
2716  break;
2717 
2718  case T_AlterOperatorStmt:
2719  tag = "ALTER OPERATOR";
2720  break;
2721 
2723  tag = "ALTER TEXT SEARCH DICTIONARY";
2724  break;
2725 
2727  tag = "ALTER TEXT SEARCH CONFIGURATION";
2728  break;
2729 
2730  case T_CreatePolicyStmt:
2731  tag = "CREATE POLICY";
2732  break;
2733 
2734  case T_AlterPolicyStmt:
2735  tag = "ALTER POLICY";
2736  break;
2737 
2738  case T_CreateAmStmt:
2739  tag = "CREATE ACCESS METHOD";
2740  break;
2741 
2743  tag = "CREATE PUBLICATION";
2744  break;
2745 
2747  tag = "ALTER PUBLICATION";
2748  break;
2749 
2751  tag = "CREATE SUBSCRIPTION";
2752  break;
2753 
2755  tag = "ALTER SUBSCRIPTION";
2756  break;
2757 
2759  tag = "DROP SUBSCRIPTION";
2760  break;
2761 
2762  case T_AlterCollationStmt:
2763  tag = "ALTER COLLATION";
2764  break;
2765 
2766  case T_PrepareStmt:
2767  tag = "PREPARE";
2768  break;
2769 
2770  case T_ExecuteStmt:
2771  tag = "EXECUTE";
2772  break;
2773 
2774  case T_CreateStatsStmt:
2775  tag = "CREATE STATISTICS";
2776  break;
2777 
2778  case T_DeallocateStmt:
2779  {
2780  DeallocateStmt *stmt = (DeallocateStmt *) parsetree;
2781 
2782  if (stmt->name == NULL)
2783  tag = "DEALLOCATE ALL";
2784  else
2785  tag = "DEALLOCATE";
2786  }
2787  break;
2788 
2789  /* already-planned queries */
2790  case T_PlannedStmt:
2791  {
2792  PlannedStmt *stmt = (PlannedStmt *) parsetree;
2793 
2794  switch (stmt->commandType)
2795  {
2796  case CMD_SELECT:
2797 
2798  /*
2799  * We take a little extra care here so that the result
2800  * will be useful for complaints about read-only
2801  * statements
2802  */
2803  if (stmt->rowMarks != NIL)
2804  {
2805  /* not 100% but probably close enough */
2806  switch (((PlanRowMark *) linitial(stmt->rowMarks))->strength)
2807  {
2808  case LCS_FORKEYSHARE:
2809  tag = "SELECT FOR KEY SHARE";
2810  break;
2811  case LCS_FORSHARE:
2812  tag = "SELECT FOR SHARE";
2813  break;
2814  case LCS_FORNOKEYUPDATE:
2815  tag = "SELECT FOR NO KEY UPDATE";
2816  break;
2817  case LCS_FORUPDATE:
2818  tag = "SELECT FOR UPDATE";
2819  break;
2820  default:
2821  tag = "SELECT";
2822  break;
2823  }
2824  }
2825  else
2826  tag = "SELECT";
2827  break;
2828  case CMD_UPDATE:
2829  tag = "UPDATE";
2830  break;
2831  case CMD_INSERT:
2832  tag = "INSERT";
2833  break;
2834  case CMD_DELETE:
2835  tag = "DELETE";
2836  break;
2837  case CMD_UTILITY:
2838  tag = CreateCommandTag(stmt->utilityStmt);
2839  break;
2840  default:
2841  elog(WARNING, "unrecognized commandType: %d",
2842  (int) stmt->commandType);
2843  tag = "???";
2844  break;
2845  }
2846  }
2847  break;
2848 
2849  /* parsed-and-rewritten-but-not-planned queries */
2850  case T_Query:
2851  {
2852  Query *stmt = (Query *) parsetree;
2853 
2854  switch (stmt->commandType)
2855  {
2856  case CMD_SELECT:
2857 
2858  /*
2859  * We take a little extra care here so that the result
2860  * will be useful for complaints about read-only
2861  * statements
2862  */
2863  if (stmt->rowMarks != NIL)
2864  {
2865  /* not 100% but probably close enough */
2866  switch (((RowMarkClause *) linitial(stmt->rowMarks))->strength)
2867  {
2868  case LCS_FORKEYSHARE:
2869  tag = "SELECT FOR KEY SHARE";
2870  break;
2871  case LCS_FORSHARE:
2872  tag = "SELECT FOR SHARE";
2873  break;
2874  case LCS_FORNOKEYUPDATE:
2875  tag = "SELECT FOR NO KEY UPDATE";
2876  break;
2877  case LCS_FORUPDATE:
2878  tag = "SELECT FOR UPDATE";
2879  break;
2880  default:
2881  tag = "???";
2882  break;
2883  }
2884  }
2885  else
2886  tag = "SELECT";
2887  break;
2888  case CMD_UPDATE:
2889  tag = "UPDATE";
2890  break;
2891  case CMD_INSERT:
2892  tag = "INSERT";
2893  break;
2894  case CMD_DELETE:
2895  tag = "DELETE";
2896  break;
2897  case CMD_UTILITY:
2898  tag = CreateCommandTag(stmt->utilityStmt);
2899  break;
2900  default:
2901  elog(WARNING, "unrecognized commandType: %d",
2902  (int) stmt->commandType);
2903  tag = "???";
2904  break;
2905  }
2906  }
2907  break;
2908 
2909  default:
2910  elog(WARNING, "unrecognized node type: %d",
2911  (int) nodeTag(parsetree));
2912  tag = "???";
2913  break;
2914  }
2915 
2916  return tag;
2917 }
2918 
2919 
2920 /*
2921  * GetCommandLogLevel
2922  * utility to get the minimum log_statement level for a command,
2923  * given either a raw (un-analyzed) parsetree, an analyzed Query,
2924  * or a PlannedStmt.
2925  *
2926  * This must handle all command types, but since the vast majority
2927  * of 'em are utility commands, it seems sensible to keep it here.
2928  */
2931 {
2932  LogStmtLevel lev;
2933 
2934  switch (nodeTag(parsetree))
2935  {
2936  /* recurse if we're given a RawStmt */
2937  case T_RawStmt:
2938  lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
2939  break;
2940 
2941  /* raw plannable queries */
2942  case T_InsertStmt:
2943  case T_DeleteStmt:
2944  case T_UpdateStmt:
2945  lev = LOGSTMT_MOD;
2946  break;
2947 
2948  case T_SelectStmt:
2949  if (((SelectStmt *) parsetree)->intoClause)
2950  lev = LOGSTMT_DDL; /* SELECT INTO */
2951  else
2952  lev = LOGSTMT_ALL;
2953  break;
2954 
2955  /* utility statements --- same whether raw or cooked */
2956  case T_TransactionStmt:
2957  lev = LOGSTMT_ALL;
2958  break;
2959 
2960  case T_DeclareCursorStmt:
2961  lev = LOGSTMT_ALL;
2962  break;
2963 
2964  case T_ClosePortalStmt:
2965  lev = LOGSTMT_ALL;
2966  break;
2967 
2968  case T_FetchStmt:
2969  lev = LOGSTMT_ALL;
2970  break;
2971 
2972  case T_CreateSchemaStmt:
2973  lev = LOGSTMT_DDL;
2974  break;
2975 
2976  case T_CreateStmt:
2978  lev = LOGSTMT_DDL;
2979  break;
2980 
2982  case T_DropTableSpaceStmt:
2984  lev = LOGSTMT_DDL;
2985  break;
2986 
2987  case T_CreateExtensionStmt:
2988  case T_AlterExtensionStmt:
2990  lev = LOGSTMT_DDL;
2991  break;
2992 
2993  case T_CreateFdwStmt:
2994  case T_AlterFdwStmt:
2999  case T_DropUserMappingStmt:
3001  lev = LOGSTMT_DDL;
3002  break;
3003 
3004  case T_DropStmt:
3005  lev = LOGSTMT_DDL;
3006  break;
3007 
3008  case T_TruncateStmt:
3009  lev = LOGSTMT_MOD;
3010  break;
3011 
3012  case T_CommentStmt:
3013  lev = LOGSTMT_DDL;
3014  break;
3015 
3016  case T_SecLabelStmt:
3017  lev = LOGSTMT_DDL;
3018  break;
3019 
3020  case T_CopyStmt:
3021  if (((CopyStmt *) parsetree)->is_from)
3022  lev = LOGSTMT_MOD;
3023  else
3024  lev = LOGSTMT_ALL;
3025  break;
3026 
3027  case T_PrepareStmt:
3028  {
3029  PrepareStmt *stmt = (PrepareStmt *) parsetree;
3030 
3031  /* Look through a PREPARE to the contained stmt */
3032  lev = GetCommandLogLevel(stmt->query);
3033  }
3034  break;
3035 
3036  case T_ExecuteStmt:
3037  {
3038  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
3039  PreparedStatement *ps;
3040 
3041  /* Look through an EXECUTE to the referenced stmt */
3042  ps = FetchPreparedStatement(stmt->name, false);
3043  if (ps && ps->plansource->raw_parse_tree)
3045  else
3046  lev = LOGSTMT_ALL;
3047  }
3048  break;
3049 
3050  case T_DeallocateStmt:
3051  lev = LOGSTMT_ALL;
3052  break;
3053 
3054  case T_RenameStmt:
3055  lev = LOGSTMT_DDL;
3056  break;
3057 
3059  lev = LOGSTMT_DDL;
3060  break;
3061 
3063  lev = LOGSTMT_DDL;
3064  break;
3065 
3066  case T_AlterOwnerStmt:
3067  lev = LOGSTMT_DDL;
3068  break;
3069 
3070  case T_AlterOperatorStmt:
3071  lev = LOGSTMT_DDL;
3072  break;
3073 
3075  case T_AlterTableStmt:
3076  lev = LOGSTMT_DDL;
3077  break;
3078 
3079  case T_AlterDomainStmt:
3080  lev = LOGSTMT_DDL;
3081  break;
3082 
3083  case T_GrantStmt:
3084  lev = LOGSTMT_DDL;
3085  break;
3086 
3087  case T_GrantRoleStmt:
3088  lev = LOGSTMT_DDL;
3089  break;
3090 
3092  lev = LOGSTMT_DDL;
3093  break;
3094 
3095  case T_DefineStmt:
3096  lev = LOGSTMT_DDL;
3097  break;
3098 
3099  case T_CompositeTypeStmt:
3100  lev = LOGSTMT_DDL;
3101  break;
3102 
3103  case T_CreateEnumStmt:
3104  lev = LOGSTMT_DDL;
3105  break;
3106 
3107  case T_CreateRangeStmt:
3108  lev = LOGSTMT_DDL;
3109  break;
3110 
3111  case T_AlterEnumStmt:
3112  lev = LOGSTMT_DDL;
3113  break;
3114 
3115  case T_ViewStmt:
3116  lev = LOGSTMT_DDL;
3117  break;
3118 
3119  case T_CreateFunctionStmt:
3120  lev = LOGSTMT_DDL;
3121  break;
3122 
3123  case T_AlterFunctionStmt:
3124  lev = LOGSTMT_DDL;
3125  break;
3126 
3127  case T_IndexStmt:
3128  lev = LOGSTMT_DDL;
3129  break;
3130 
3131  case T_RuleStmt:
3132  lev = LOGSTMT_DDL;
3133  break;
3134 
3135  case T_CreateSeqStmt:
3136  lev = LOGSTMT_DDL;
3137  break;
3138 
3139  case T_AlterSeqStmt:
3140  lev = LOGSTMT_DDL;
3141  break;
3142 
3143  case T_DoStmt:
3144  lev = LOGSTMT_ALL;
3145  break;
3146 
3147  case T_CreatedbStmt:
3148  lev = LOGSTMT_DDL;
3149  break;
3150 
3151  case T_AlterDatabaseStmt:
3152  lev = LOGSTMT_DDL;
3153  break;
3154 
3156  lev = LOGSTMT_DDL;
3157  break;
3158 
3159  case T_DropdbStmt:
3160  lev = LOGSTMT_DDL;
3161  break;
3162 
3163  case T_NotifyStmt:
3164  lev = LOGSTMT_ALL;
3165  break;
3166 
3167  case T_ListenStmt:
3168  lev = LOGSTMT_ALL;
3169  break;
3170 
3171  case T_UnlistenStmt:
3172  lev = LOGSTMT_ALL;
3173  break;
3174 
3175  case T_LoadStmt:
3176  lev = LOGSTMT_ALL;
3177  break;
3178 
3179  case T_CallStmt:
3180  lev = LOGSTMT_ALL;
3181  break;
3182 
3183  case T_ClusterStmt:
3184  lev = LOGSTMT_DDL;
3185  break;
3186 
3187  case T_VacuumStmt:
3188  lev = LOGSTMT_ALL;
3189  break;
3190 
3191  case T_ExplainStmt:
3192  {
3193  ExplainStmt *stmt = (ExplainStmt *) parsetree;
3194  bool analyze = false;
3195  ListCell *lc;
3196 
3197  /* Look through an EXPLAIN ANALYZE to the contained stmt */
3198  foreach(lc, stmt->options)
3199  {
3200  DefElem *opt = (DefElem *) lfirst(lc);
3201 
3202  if (strcmp(opt->defname, "analyze") == 0)
3203  analyze = defGetBoolean(opt);
3204  /* don't "break", as explain.c will use the last value */
3205  }
3206  if (analyze)
3207  return GetCommandLogLevel(stmt->query);
3208 
3209  /* Plain EXPLAIN isn't so interesting */
3210  lev = LOGSTMT_ALL;
3211  }
3212  break;
3213 
3214  case T_CreateTableAsStmt:
3215  lev = LOGSTMT_DDL;
3216  break;
3217 
3218  case T_RefreshMatViewStmt:
3219  lev = LOGSTMT_DDL;
3220  break;
3221 
3222  case T_AlterSystemStmt:
3223  lev = LOGSTMT_DDL;
3224  break;
3225 
3226  case T_VariableSetStmt:
3227  lev = LOGSTMT_ALL;
3228  break;
3229 
3230  case T_VariableShowStmt:
3231  lev = LOGSTMT_ALL;
3232  break;
3233 
3234  case T_DiscardStmt:
3235  lev = LOGSTMT_ALL;
3236  break;
3237 
3238  case T_CreateTrigStmt:
3239  lev = LOGSTMT_DDL;
3240  break;
3241 
3242  case T_CreateEventTrigStmt:
3243  lev = LOGSTMT_DDL;
3244  break;
3245 
3246  case T_AlterEventTrigStmt:
3247  lev = LOGSTMT_DDL;
3248  break;
3249 
3250  case T_CreatePLangStmt:
3251  lev = LOGSTMT_DDL;
3252  break;
3253 
3254  case T_CreateDomainStmt:
3255  lev = LOGSTMT_DDL;
3256  break;
3257 
3258  case T_CreateRoleStmt:
3259  lev = LOGSTMT_DDL;
3260  break;
3261 
3262  case T_AlterRoleStmt:
3263  lev = LOGSTMT_DDL;
3264  break;
3265 
3266  case T_AlterRoleSetStmt:
3267  lev = LOGSTMT_DDL;
3268  break;
3269 
3270  case T_DropRoleStmt:
3271  lev = LOGSTMT_DDL;
3272  break;
3273 
3274  case T_DropOwnedStmt:
3275  lev = LOGSTMT_DDL;
3276  break;
3277 
3278  case T_ReassignOwnedStmt:
3279  lev = LOGSTMT_DDL;
3280  break;
3281 
3282  case T_LockStmt:
3283  lev = LOGSTMT_ALL;
3284  break;
3285 
3286  case T_ConstraintsSetStmt:
3287  lev = LOGSTMT_ALL;
3288  break;
3289 
3290  case T_CheckPointStmt:
3291  lev = LOGSTMT_ALL;
3292  break;
3293 
3294  case T_ReindexStmt:
3295  lev = LOGSTMT_ALL; /* should this be DDL? */
3296  break;
3297 
3299  lev = LOGSTMT_DDL;
3300  break;
3301 
3302  case T_CreateCastStmt:
3303  lev = LOGSTMT_DDL;
3304  break;
3305 
3306  case T_CreateOpClassStmt:
3307  lev = LOGSTMT_DDL;
3308  break;
3309 
3310  case T_CreateOpFamilyStmt:
3311  lev = LOGSTMT_DDL;
3312  break;
3313 
3314  case T_CreateTransformStmt:
3315  lev = LOGSTMT_DDL;
3316  break;
3317 
3318  case T_AlterOpFamilyStmt:
3319  lev = LOGSTMT_DDL;
3320  break;
3321 
3322  case T_CreatePolicyStmt:
3323  lev = LOGSTMT_DDL;
3324  break;
3325 
3326  case T_AlterPolicyStmt:
3327  lev = LOGSTMT_DDL;
3328  break;
3329 
3331  lev = LOGSTMT_DDL;
3332  break;
3333 
3335  lev = LOGSTMT_DDL;
3336  break;
3337 
3338  case T_CreateAmStmt:
3339  lev = LOGSTMT_DDL;
3340  break;
3341 
3343  lev = LOGSTMT_DDL;
3344  break;
3345 
3347  lev = LOGSTMT_DDL;
3348  break;
3349 
3351  lev = LOGSTMT_DDL;
3352  break;
3353 
3355  lev = LOGSTMT_DDL;
3356  break;
3357 
3359  lev = LOGSTMT_DDL;
3360  break;
3361 
3362  case T_CreateStatsStmt:
3363  lev = LOGSTMT_DDL;
3364  break;
3365 
3366  case T_AlterCollationStmt:
3367  lev = LOGSTMT_DDL;
3368  break;
3369 
3370  /* already-planned queries */
3371  case T_PlannedStmt:
3372  {
3373  PlannedStmt *stmt = (PlannedStmt *) parsetree;
3374 
3375  switch (stmt->commandType)
3376  {
3377  case CMD_SELECT:
3378  lev = LOGSTMT_ALL;
3379  break;
3380 
3381  case CMD_UPDATE:
3382  case CMD_INSERT:
3383  case CMD_DELETE:
3384  lev = LOGSTMT_MOD;
3385  break;
3386 
3387  case CMD_UTILITY:
3388  lev = GetCommandLogLevel(stmt->utilityStmt);
3389  break;
3390 
3391  default:
3392  elog(WARNING, "unrecognized commandType: %d",
3393  (int) stmt->commandType);
3394  lev = LOGSTMT_ALL;
3395  break;
3396  }
3397  }
3398  break;
3399 
3400  /* parsed-and-rewritten-but-not-planned queries */
3401  case T_Query:
3402  {
3403  Query *stmt = (Query *) parsetree;
3404 
3405  switch (stmt->commandType)
3406  {
3407  case CMD_SELECT:
3408  lev = LOGSTMT_ALL;
3409  break;
3410 
3411  case CMD_UPDATE:
3412  case CMD_INSERT:
3413  case CMD_DELETE:
3414  lev = LOGSTMT_MOD;
3415  break;
3416 
3417  case CMD_UTILITY:
3418  lev = GetCommandLogLevel(stmt->utilityStmt);
3419  break;
3420 
3421  default:
3422  elog(WARNING, "unrecognized commandType: %d",
3423  (int) stmt->commandType);
3424  lev = LOGSTMT_ALL;
3425  break;
3426  }
3427 
3428  }
3429  break;
3430 
3431  default:
3432  elog(WARNING, "unrecognized node type: %d",
3433  (int) nodeTag(parsetree));
3434  lev = LOGSTMT_ALL;
3435  break;
3436  }
3437 
3438  return lev;
3439 }
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:8170
ObjectType objtype
Definition: parsenodes.h:2618
ObjectAddress AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
Definition: sequence.c:416
ObjectAddress DefineTSParser(List *names, List *parameters)
Definition: tsearchcmds.c:176
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1440
#define NIL
Definition: pg_list.h:69
void closeAllVfds(void)
Definition: fd.c:2767
bool CommandIsReadOnly(PlannedStmt *pstmt)
Definition: utility.c:100
ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt)
Definition: foreigncmds.c:985
void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid)
Definition: foreigncmds.c:1446
void DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
ObjectAddress DefineOperator(List *names, List *parameters)
Definition: operatorcmds.c:67
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:112
ObjectAddress AlterSubscription(AlterSubscriptionStmt *stmt)
ObjectType objtype
Definition: parsenodes.h:2630
#define IsA(nodeptr, _type_)
Definition: nodes.h:568
ObjectAddress DefineTSConfiguration(List *names, List *parameters, ObjectAddress *copied)
Definition: tsearchcmds.c:960
ObjectAddress CreateTransform(CreateTransformStmt *stmt)
ObjectAddress AlterEnum(AlterEnumStmt *stmt, bool isTopLevel)
Definition: typecmds.c:1276
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1710
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:325
void PerformPortalClose(const char *name)
Definition: portalcmds.c:216
ObjectAddress AlterDomainAddConstraint(List *names, Node *newConstraint, ObjectAddress *constrAddr)
Definition: typecmds.c:2539
ObjectAddress CreateForeignDataWrapper(CreateFdwStmt *stmt)
Definition: foreigncmds.c:560
void PreventCommandIfParallelMode(const char *cmdname)
Definition: utility.c:257
DropBehavior behavior
Definition: parsenodes.h:1851
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
Definition: functioncmds.c:865
ObjectType renameType
Definition: parsenodes.h:2843
Oid ReindexTable(RangeVar *relation, int options)
Definition: indexcmds.c:2261
int LOCKMODE
Definition: lockdefs.h:26
ObjectAddress CreatePublication(CreatePublicationStmt *stmt)
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:44
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3213
#define castNode(_type_, nodeptr)
Definition: nodes.h:586
CachedPlanSource * plansource
Definition: prepare.h:31
LogStmtLevel
Definition: tcopprot.h:40
Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
Definition: tablecmds.c:3239
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
ObjectAddress AlterDomainValidateConstraint(List *names, const char *constrName)
Definition: typecmds.c:2648
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1805
void DropOwnedObjects(DropOwnedStmt *stmt)
Definition: user.c:1333
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:1575
ObjectType objectType
Definition: parsenodes.h:2888
void DefineSavepoint(const char *name)
Definition: xact.c:3825
RangeVar * typevar
Definition: parsenodes.h:2988
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:5306
void EventTriggerDDLCommandEnd(Node *parsetree)
void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest)
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:294
ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:76
Definition: nodes.h:517
ObjectAddress ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt, ObjectAddress *objAddr)
Definition: extension.c:3171
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3480
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.c:338
int errcode(int sqlerrcode)
Definition: elog.c:575
void PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params, const char *queryString, bool isTopLevel)
Definition: portalcmds.c:42
ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt)
Definition: proclang.c:63
ProcessUtilityContext
Definition: utility.h:19
bool superuser(void)
Definition: superuser.c:47
char * filename
Definition: parsenodes.h:3058
void EventTriggerInhibitCommandCollection(void)
ObjectAddress DefineDomain(CreateDomainStmt *stmt)
Definition: typecmds.c:726
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
List * options
Definition: parsenodes.h:3177
void Async_Listen(const char *channel)
Definition: async.c:638
ObjectAddress DefineCompositeType(RangeVar *typevar, List *coldeflist)
Definition: typecmds.c:2136
Oid CreateTableSpace(CreateTableSpaceStmt *stmt)
Definition: tablespace.c:234
void AlterTable(Oid relid, LOCKMODE lockmode, AlterTableStmt *stmt)
Definition: tablecmds.c:3290
unsigned int Oid
Definition: postgres_ext.h:31
bool RecoveryInProgress(void)
Definition: xlog.c:7949
List * rowMarks
Definition: parsenodes.h:163
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1322
void RemoveObjects(DropStmt *stmt)
Definition: dropcmds.c:55
Node * utilityStmt
Definition: parsenodes.h:120
ObjectAddress DefineOpClass(CreateOpClassStmt *stmt)
Definition: opclasscmds.c:324
bool EndTransactionBlock(void)
Definition: xact.c:3532
DestReceiver * None_Receiver
Definition: dest.c:91
ObjectAddress CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
void NewRelationCreateToastTable(Oid relOid, Datum reloptions)
Definition: toasting.c:71
#define OidIsValid(objectId)
Definition: c.h:605
void ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause, const char *queryString, ParamListInfo params, DestReceiver *dest, char *completionTag)
Definition: prepare.c:200
int stmt_len
Definition: plannodes.h:100
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Definition: user.c:72
ObjectType removeType
Definition: parsenodes.h:2593
void RollbackToSavepoint(const char *name)
Definition: xact.c:4019
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc.c:8161
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool ignoreOids, bool isReset)
Definition: reloptions.c:773
char relkind
Definition: pg_class.h:51
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:44
TupleDesc resultDesc
Definition: plancache.h:92
void ReindexIndex(RangeVar *indexRelation, int options)
Definition: indexcmds.c:2161
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:1884
void EventTriggerAlterTableStart(Node *parsetree)
#define list_make1(x1)
Definition: pg_list.h:139
bool IsTransactionBlock(void)
Definition: xact.c:4422
char * relname
Definition: primnodes.h:69
Node * query
Definition: parsenodes.h:3176
ObjectAddress DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List *parameters)
Definition: aggregatecmds.c:57
void DeallocateQuery(DeallocateStmt *stmt)
Definition: prepare.c:566
#define true
Definition: c.h:279
RangeVar * relation
Definition: parsenodes.h:2718
bool defGetBoolean(DefElem *def)
Definition: define.c:111
ObjectAddress AlterPolicy(AlterPolicyStmt *stmt)
Definition: policy.c:881
void RemoveRelations(DropStmt *drop)
Definition: tablecmds.c:1078
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.c:377
bool IsInParallelMode(void)
Definition: xact.c:905
#define linitial(l)
Definition: pg_list.h:111
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
Definition: tablecmds.c:13407
List * args
Definition: parsenodes.h:2510
#define ERROR
Definition: elog.h:43
ObjectAddress AlterDomainDefault(List *names, Node *defaultRaw)
Definition: typecmds.c:2194
static void ProcessUtilitySlow(ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.c:935
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:276
char * savepoint_name
Definition: parsenodes.h:2977
bool concurrent
Definition: parsenodes.h:2596
void GrantRole(GrantRoleStmt *stmt)
Definition: user.c:1274
ObjectAddress AlterOperator(AlterOperatorStmt *stmt)
Definition: operatorcmds.c:384
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:300
void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest, char *completionTag)
Definition: portalcmds.c:168
void EventTriggerDDLCommandStart(Node *parsetree)
RangeVar * relation
Definition: parsenodes.h:3288
ObjectAddress CreatePolicy(CreatePolicyStmt *stmt)
Definition: policy.c:686
void EventTriggerSQLDrop(Node *parsetree)
void UserAbortTransactionBlock(void)
Definition: xact.c:3668
ObjectAddress AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
Definition: tsearchcmds.c:1173
ObjectAddress AlterDomainNotNull(List *names, bool notNull)
Definition: typecmds.c:2333
Oid RemoveUserMapping(DropUserMappingStmt *stmt)
Definition: foreigncmds.c:1345
ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt)
Definition: foreigncmds.c:1135
void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
Definition: guc.c:7543
int stmt_location
Definition: plannodes.h:99
Node * stmt
Definition: parsenodes.h:1450
List * transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, const char *queryString)
ObjectAddress AlterTSDictionary(AlterTSDictionaryStmt *stmt)
Definition: tsearchcmds.c:525
void ExecVacuum(VacuumStmt *vacstmt, bool isTopLevel)
Definition: vacuum.c:87
int errdetail(const char *fmt,...)
Definition: elog.c:873
Node * utilityStmt
Definition: plannodes.h:96
ObjectAddress DefineRange(CreateRangeStmt *stmt)
Definition: typecmds.c:1367
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3153
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:227
ObjectAddress DefineEnum(CreateEnumStmt *stmt)
Definition: typecmds.c:1154
bool UtilityReturnsTuples(Node *parsetree)
Definition: utility.c:1743
void(* ProcessUtility_hook_type)(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.h:29
void cluster(ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:106
ObjectAddress DefineView(ViewStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: view.c:417
Oid CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: schemacmds.c:51
void ExecuteDoStmt(DoStmt *stmt, bool atomic)
#define HEAP_RELOPT_NAMESPACES
Definition: reloptions.h:60
const char * p_sourcetext
Definition: parse_node.h:173
void DropTableSpace(DropTableSpaceStmt *stmt)
Definition: tablespace.c:402
ObjectAddress AlterUserMapping(AlterUserMappingStmt *stmt)
Definition: foreigncmds.c:1250
void PrepareQuery(PrepareStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: prepare.c:57
List * returningList
Definition: parsenodes.h:146
char * conditionname
Definition: parsenodes.h:2941
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition: alter.c:325
char * portalname
Definition: parsenodes.h:2695
#define CHECKPOINT_FORCE
Definition: xlog.h:180
ObjectAddress DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
Definition: sequence.c:116
#define lnext(lc)
Definition: pg_list.h:105
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
Definition: tablecmds.c:519
#define ereport(elevel, rest)
Definition: elog.h:122
const char * CreateCommandTag(Node *parsetree)
Definition: utility.c:2070
void ExecAlterDefaultPrivilegesStmt(ParseState *pstate, AlterDefaultPrivilegesStmt *stmt)
Definition: aclchk.c:910
ObjectAddress DefineType(ParseState *pstate, List *names, List *parameters)
Definition: typecmds.c:113
Oid AlterEventTrigger(AlterEventTrigStmt *stmt)
bool inh
Definition: primnodes.h:70
Node * arg
Definition: parsenodes.h:731
ObjectType
Definition: parsenodes.h:1634
void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind, int options)
Definition: indexcmds.c:2289
ObjectAddress CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt)
Definition: extension.c:1621
bool missing_ok
Definition: parsenodes.h:3098
void BeginTransactionBlock(void)
Definition: xact.c:3412
void EventTriggerEndCompleteQuery(void)
bool is_grant
Definition: parsenodes.h:1870
#define WARNING
Definition: elog.h:40
Oid AlterRole(AlterRoleStmt *stmt)
Definition: user.c:504
LOCKMODE AlterTableGetLockLevel(List *cmds)
Definition: tablecmds.c:3359
ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt)
Definition: foreigncmds.c:861
#define PortalIsValid(p)
Definition: portal.h:201
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:7329
Definition: nodes.h:309
bool canSetTag
Definition: plannodes.h:53
bool ismove
Definition: parsenodes.h:2696
void EventTriggerUndoInhibitCommandCollection(void)
uintptr_t Datum
Definition: postgres.h:367
void CommandCounterIncrement(void)
Definition: xact.c:914
CmdType commandType
Definition: plannodes.h:45
void ReleaseSavepoint(const char *name)
Definition: xact.c:3910
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:886
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:527
ObjectType kind
Definition: parsenodes.h:2507
char * conditionname
Definition: parsenodes.h:2930
void dropdb(const char *dbname, bool missing_ok)
Definition: dbcommands.c:780
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:425
void EventTriggerCollectAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt)
List * rowMarks
Definition: plannodes.h:88
TupleDesc tupDesc
Definition: portal.h:157
#define InvalidOid
Definition: postgres_ext.h:36
ObjectAddress DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_exists)
Definition: collationcmds.c:51
List * defnames
Definition: parsenodes.h:2509
bool EventTriggerSupportsObjectType(ObjectType obtype)
bool XactReadOnly
Definition: xact.c:76
#define NOTICE
Definition: elog.h:37
Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
Definition: dbcommands.c:1397
CmdType commandType
Definition: parsenodes.h:112
ObjectAddress CreateCast(CreateCastStmt *stmt)
void FinishPreparedTransaction(const char *gid, bool isCommit)
Definition: twophase.c:1433
#define CHECKPOINT_WAIT
Definition: xlog.h:184
ObjectAddress ExecAlterExtensionStmt(ParseState *pstate, AlterExtensionStmt *stmt)
Definition: extension.c:2863
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:463
#define PG_CATCH()
Definition: elog.h:293
#define makeNode(_type_)
Definition: nodes.h:565
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
#define COMPLETION_TAG_BUFSIZE
Definition: dest.h:74
ObjectAddress DefineTSDictionary(List *names, List *parameters)
Definition: tsearchcmds.c:409
void DoCopy(ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
Definition: copy.c:782
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
ReindexObjectType kind
Definition: parsenodes.h:3286
bool InSecurityRestrictedOperation(void)
Definition: miscinit.c:511
bool hasModifyingCTE
Definition: plannodes.h:51
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:137
Node * query
Definition: parsenodes.h:3344
ObjectAddress CreateConversionCommand(CreateConversionStmt *stmt)
void Async_UnlistenAll(void)
Definition: async.c:670
Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
Definition: tablecmds.c:11066
ObjectAddress AlterForeignDataWrapper(AlterFdwStmt *stmt)
Definition: foreigncmds.c:673
List * transformCreateStmt(CreateStmt *stmt, const char *queryString)
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition: alter.c:802
#define PG_RE_THROW()
Definition: elog.h:314
struct RawStmt * raw_parse_tree
Definition: plancache.h:83
void PreventCommandIfReadOnly(const char *cmdname)
Definition: utility.c:239
#define nodeTag(nodeptr)
Definition: nodes.h:522
void EventTriggerAlterTableRelid(Oid objectId)
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest)
Definition: explain.c:143
void Async_Notify(const char *channel, const char *payload)
Definition: async.c:543
Oid AlterOpFamily(AlterOpFamilyStmt *stmt)
Definition: opclasscmds.c:764
ObjectAddress DefineOpFamily(CreateOpFamilyStmt *stmt)
Definition: opclasscmds.c:719
ObjectAddress AlterDomainDropConstraint(List *names, const char *constrName, DropBehavior behavior, bool missing_ok)
Definition: typecmds.c:2449
bool concurrent
Definition: parsenodes.h:2737
ObjectAddress DefineRule(RuleStmt *stmt, const char *queryString)
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
Definition: pg_inherits.c:166
void LockTableCommand(LockStmt *lockstmt)
Definition: lockcmds.c:40
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
Definition: dbcommands.c:99
const ObjectAddress InvalidObjectAddress
void ImportForeignSchema(ImportForeignSchemaStmt *stmt)
Definition: foreigncmds.c:1526
int errmsg(const char *fmt,...)
Definition: elog.c:797
RangeVar * relation
Definition: parsenodes.h:1718
void list_free(List *list)
Definition: list.c:1133
void ReassignOwnedObjects(ReassignOwnedStmt *stmt)
Definition: user.c:1359
ObjectAddress AlterCollation(AlterCollationStmt *stmt)
#define ShareLock
Definition: lockdefs.h:41
ObjectType objtype
Definition: parsenodes.h:1872
ObjectAddress DefineTSTemplate(List *names, List *parameters)
Definition: tsearchcmds.c:729
char * name
Definition: parsenodes.h:3356
bool if_not_exists
Definition: parsenodes.h:2512
#define CHECKPOINT_IMMEDIATE
Definition: xlog.h:179
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:159
static void check_xact_readonly(Node *parsetree)
Definition: utility.c:134
void DropRole(DropRoleStmt *stmt)
Definition: user.c:966
ObjectAddress ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, ParamListInfo params, char *completionTag)
Definition: matview.c:135
const char * name
Definition: parsenodes.h:3289
char * defname
Definition: parsenodes.h:730
ObjectAddress CreateAccessMethod(CreateAmStmt *stmt)
Definition: amcmds.c:41
ObjectAddress ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, char *completionTag)
Definition: createas.c:224
List * definition
Definition: parsenodes.h:2511
#define elog
Definition: elog.h:219
void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
#define PG_TRY()
Definition: elog.h:284
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:77
static const char * AlterObjectTypeCommandTag(ObjectType objtype)
Definition: utility.c:1921
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:495
Definition: pg_list.h:45
ObjectAddress AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt)
TupleDesc UtilityTupleDescriptor(Node *parsetree)
Definition: utility.c:1793
#define UINT64_FORMAT
Definition: c.h:368
static long analyze(struct nfa *nfa)
Definition: regc_nfa.c:2816
bool oldstyle
Definition: parsenodes.h:2508
char * dbname
Definition: parsenodes.h:3097
#define PG_END_TRY()
Definition: elog.h:300
void DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
Definition: discard.c:31
void RequireTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3219
void Async_Unlisten(const char *channel)
Definition: async.c:652
#define lfirst_oid(lc)
Definition: pg_list.h:108
void AlterPublication(AlterPublicationStmt *stmt)
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7687
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:2930
bool EventTriggerBeginCompleteQuery(void)
void RequestCheckpoint(int flags)
Definition: checkpointer.c:967
char * payload
Definition: parsenodes.h:2931
TransactionStmtKind kind
Definition: parsenodes.h:2975
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:385
void EventTriggerAlterTableEnd(void)
ObjectAddress CreateStatistics(CreateStatsStmt *stmt)
Definition: statscmds.c:55
char * conditionname
Definition: parsenodes.h:2951
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:988