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