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