PostgreSQL Source Code  git master
utility.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/reloptions.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "catalog/catalog.h"
#include "catalog/namespace.h"
#include "catalog/pg_inherits.h"
#include "catalog/toasting.h"
#include "commands/alter.h"
#include "commands/async.h"
#include "commands/cluster.h"
#include "commands/collationcmds.h"
#include "commands/comment.h"
#include "commands/conversioncmds.h"
#include "commands/copy.h"
#include "commands/createas.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/discard.h"
#include "commands/event_trigger.h"
#include "commands/explain.h"
#include "commands/extension.h"
#include "commands/lockcmds.h"
#include "commands/matview.h"
#include "commands/policy.h"
#include "commands/portalcmds.h"
#include "commands/prepare.h"
#include "commands/proclang.h"
#include "commands/publicationcmds.h"
#include "commands/schemacmds.h"
#include "commands/seclabel.h"
#include "commands/sequence.h"
#include "commands/subscriptioncmds.h"
#include "commands/tablecmds.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "commands/typecmds.h"
#include "commands/user.h"
#include "commands/vacuum.h"
#include "commands/view.h"
#include "miscadmin.h"
#include "parser/parse_utilcmd.h"
#include "postmaster/bgwriter.h"
#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteRemove.h"
#include "storage/fd.h"
#include "tcop/pquery.h"
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/syscache.h"
Include dependency graph for utility.c:

Go to the source code of this file.

Functions

static int ClassifyUtilityCommandAsReadOnly (Node *parsetree)
 
static void ProcessUtilitySlow (ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
static void ExecDropStmt (DropStmt *stmt, bool isTopLevel)
 
bool CommandIsReadOnly (PlannedStmt *pstmt)
 
void PreventCommandIfReadOnly (const char *cmdname)
 
void PreventCommandIfParallelMode (const char *cmdname)
 
void PreventCommandDuringRecovery (const char *cmdname)
 
static void CheckRestrictedOperation (const char *cmdname)
 
void ProcessUtility (PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
void standard_ProcessUtility (PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
 
void ProcessUtilityForAlterTable (Node *stmt, AlterTableUtilityContext *context)
 
bool UtilityReturnsTuples (Node *parsetree)
 
TupleDesc UtilityTupleDescriptor (Node *parsetree)
 
QueryUtilityContainsQuery (Node *parsetree)
 
static CommandTag AlterObjectTypeCommandTag (ObjectType objtype)
 
CommandTag CreateCommandTag (Node *parsetree)
 
LogStmtLevel GetCommandLogLevel (Node *parsetree)
 

Variables

ProcessUtility_hook_type ProcessUtility_hook = NULL
 

Function Documentation

◆ AlterObjectTypeCommandTag()

static CommandTag AlterObjectTypeCommandTag ( ObjectType  objtype)
static

Definition at line 2098 of file utility.c.

References OBJECT_AGGREGATE, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, and OBJECT_VIEW.

Referenced by CreateCommandTag().

2099 {
2100  CommandTag tag;
2101 
2102  switch (objtype)
2103  {
2104  case OBJECT_AGGREGATE:
2105  tag = CMDTAG_ALTER_AGGREGATE;
2106  break;
2107  case OBJECT_ATTRIBUTE:
2108  tag = CMDTAG_ALTER_TYPE;
2109  break;
2110  case OBJECT_CAST:
2111  tag = CMDTAG_ALTER_CAST;
2112  break;
2113  case OBJECT_COLLATION:
2114  tag = CMDTAG_ALTER_COLLATION;
2115  break;
2116  case OBJECT_COLUMN:
2117  tag = CMDTAG_ALTER_TABLE;
2118  break;
2119  case OBJECT_CONVERSION:
2120  tag = CMDTAG_ALTER_CONVERSION;
2121  break;
2122  case OBJECT_DATABASE:
2123  tag = CMDTAG_ALTER_DATABASE;
2124  break;
2125  case OBJECT_DOMAIN:
2126  case OBJECT_DOMCONSTRAINT:
2127  tag = CMDTAG_ALTER_DOMAIN;
2128  break;
2129  case OBJECT_EXTENSION:
2130  tag = CMDTAG_ALTER_EXTENSION;
2131  break;
2132  case OBJECT_FDW:
2133  tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
2134  break;
2135  case OBJECT_FOREIGN_SERVER:
2136  tag = CMDTAG_ALTER_SERVER;
2137  break;
2138  case OBJECT_FOREIGN_TABLE:
2139  tag = CMDTAG_ALTER_FOREIGN_TABLE;
2140  break;
2141  case OBJECT_FUNCTION:
2142  tag = CMDTAG_ALTER_FUNCTION;
2143  break;
2144  case OBJECT_INDEX:
2145  tag = CMDTAG_ALTER_INDEX;
2146  break;
2147  case OBJECT_LANGUAGE:
2148  tag = CMDTAG_ALTER_LANGUAGE;
2149  break;
2150  case OBJECT_LARGEOBJECT:
2151  tag = CMDTAG_ALTER_LARGE_OBJECT;
2152  break;
2153  case OBJECT_OPCLASS:
2154  tag = CMDTAG_ALTER_OPERATOR_CLASS;
2155  break;
2156  case OBJECT_OPERATOR:
2157  tag = CMDTAG_ALTER_OPERATOR;
2158  break;
2159  case OBJECT_OPFAMILY:
2160  tag = CMDTAG_ALTER_OPERATOR_FAMILY;
2161  break;
2162  case OBJECT_POLICY:
2163  tag = CMDTAG_ALTER_POLICY;
2164  break;
2165  case OBJECT_PROCEDURE:
2166  tag = CMDTAG_ALTER_PROCEDURE;
2167  break;
2168  case OBJECT_ROLE:
2169  tag = CMDTAG_ALTER_ROLE;
2170  break;
2171  case OBJECT_ROUTINE:
2172  tag = CMDTAG_ALTER_ROUTINE;
2173  break;
2174  case OBJECT_RULE:
2175  tag = CMDTAG_ALTER_RULE;
2176  break;
2177  case OBJECT_SCHEMA:
2178  tag = CMDTAG_ALTER_SCHEMA;
2179  break;
2180  case OBJECT_SEQUENCE:
2181  tag = CMDTAG_ALTER_SEQUENCE;
2182  break;
2183  case OBJECT_TABLE:
2184  case OBJECT_TABCONSTRAINT:
2185  tag = CMDTAG_ALTER_TABLE;
2186  break;
2187  case OBJECT_TABLESPACE:
2188  tag = CMDTAG_ALTER_TABLESPACE;
2189  break;
2190  case OBJECT_TRIGGER:
2191  tag = CMDTAG_ALTER_TRIGGER;
2192  break;
2193  case OBJECT_EVENT_TRIGGER:
2194  tag = CMDTAG_ALTER_EVENT_TRIGGER;
2195  break;
2197  tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
2198  break;
2199  case OBJECT_TSDICTIONARY:
2200  tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
2201  break;
2202  case OBJECT_TSPARSER:
2203  tag = CMDTAG_ALTER_TEXT_SEARCH_PARSER;
2204  break;
2205  case OBJECT_TSTEMPLATE:
2206  tag = CMDTAG_ALTER_TEXT_SEARCH_TEMPLATE;
2207  break;
2208  case OBJECT_TYPE:
2209  tag = CMDTAG_ALTER_TYPE;
2210  break;
2211  case OBJECT_VIEW:
2212  tag = CMDTAG_ALTER_VIEW;
2213  break;
2214  case OBJECT_MATVIEW:
2215  tag = CMDTAG_ALTER_MATERIALIZED_VIEW;
2216  break;
2217  case OBJECT_PUBLICATION:
2218  tag = CMDTAG_ALTER_PUBLICATION;
2219  break;
2220  case OBJECT_SUBSCRIPTION:
2221  tag = CMDTAG_ALTER_SUBSCRIPTION;
2222  break;
2223  case OBJECT_STATISTIC_EXT:
2224  tag = CMDTAG_ALTER_STATISTICS;
2225  break;
2226  default:
2227  tag = CMDTAG_UNKNOWN;
2228  break;
2229  }
2230 
2231  return tag;
2232 }
CommandTag
Definition: cmdtag.h:20

◆ CheckRestrictedOperation()

static void CheckRestrictedOperation ( const char *  cmdname)
static

Definition at line 460 of file utility.c.

References ereport, errcode(), errmsg(), ERROR, and InSecurityRestrictedOperation().

Referenced by standard_ProcessUtility().

461 {
463  ereport(ERROR,
464  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
465  /* translator: %s is name of a SQL command, eg PREPARE */
466  errmsg("cannot execute %s within security-restricted operation",
467  cmdname)));
468 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
bool InSecurityRestrictedOperation(void)
Definition: miscinit.c:571
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ ClassifyUtilityCommandAsReadOnly()

static int ClassifyUtilityCommandAsReadOnly ( Node parsetree)
static

Definition at line 132 of file utility.c.

References COMMAND_IS_NOT_READ_ONLY, COMMAND_IS_STRICTLY_READ_ONLY, COMMAND_OK_IN_READ_ONLY_TXN, COMMAND_OK_IN_RECOVERY, elog, ERROR, CopyStmt::is_from, TransactionStmt::kind, LockStmt::mode, nodeTag, RowExclusiveLock, T_AlterCollationStmt, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterStatsStmt, T_AlterSubscriptionStmt, T_AlterSystemStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterTypeStmt, T_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PrepareStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, and TRANS_STMT_START.

Referenced by standard_ProcessUtility().

133 {
134  switch (nodeTag(parsetree))
135  {
138  case T_AlterDatabaseStmt:
140  case T_AlterDomainStmt:
141  case T_AlterEnumStmt:
145  case T_AlterFdwStmt:
147  case T_AlterFunctionStmt:
150  case T_AlterOpFamilyStmt:
151  case T_AlterOperatorStmt:
152  case T_AlterOwnerStmt:
153  case T_AlterPolicyStmt:
155  case T_AlterRoleSetStmt:
156  case T_AlterRoleStmt:
157  case T_AlterSeqStmt:
158  case T_AlterStatsStmt:
164  case T_AlterTableStmt:
165  case T_AlterTypeStmt:
167  case T_CommentStmt:
168  case T_CompositeTypeStmt:
169  case T_CreateAmStmt:
170  case T_CreateCastStmt:
172  case T_CreateDomainStmt:
173  case T_CreateEnumStmt:
176  case T_CreateFdwStmt:
180  case T_CreateOpClassStmt:
182  case T_CreatePLangStmt:
183  case T_CreatePolicyStmt:
185  case T_CreateRangeStmt:
186  case T_CreateRoleStmt:
187  case T_CreateSchemaStmt:
188  case T_CreateSeqStmt:
189  case T_CreateStatsStmt:
190  case T_CreateStmt:
192  case T_CreateTableAsStmt:
195  case T_CreateTrigStmt:
197  case T_CreatedbStmt:
198  case T_DefineStmt:
199  case T_DropOwnedStmt:
200  case T_DropRoleStmt:
201  case T_DropStmt:
205  case T_DropdbStmt:
206  case T_GrantRoleStmt:
207  case T_GrantStmt:
209  case T_IndexStmt:
210  case T_ReassignOwnedStmt:
212  case T_RenameStmt:
213  case T_RuleStmt:
214  case T_SecLabelStmt:
215  case T_TruncateStmt:
216  case T_ViewStmt:
217  {
218  /* DDL is not read-only, and neither is TRUNCATE. */
220  }
221 
222  case T_AlterSystemStmt:
223  {
224  /*
225  * Surprisingly, ALTER SYSTEM meets all our definitions of
226  * read-only: it changes nothing that affects the output of
227  * pg_dump, it doesn't write WAL or imperil the application
228  * of future WAL, and it doesn't depend on any state that needs
229  * to be synchronized with parallel workers.
230  *
231  * So, despite the fact that it writes to a file, it's read
232  * only!
233  */
235  }
236 
237  case T_CallStmt:
238  case T_DoStmt:
239  {
240  /*
241  * Commands inside the DO block or the called procedure might
242  * not be read only, but they'll be checked separately when we
243  * try to execute them. Here we only need to worry about the
244  * DO or CALL command itself.
245  */
247  }
248 
249  case T_CheckPointStmt:
250  {
251  /*
252  * You might think that this should not be permitted in
253  * recovery, but we interpret a CHECKPOINT command during
254  * recovery as a request for a restartpoint instead. We allow
255  * this since it can be a useful way of reducing switchover
256  * time when using various forms of replication.
257  */
259  }
260 
261  case T_ClosePortalStmt:
263  case T_DeallocateStmt:
264  case T_DeclareCursorStmt:
265  case T_DiscardStmt:
266  case T_ExecuteStmt:
267  case T_FetchStmt:
268  case T_LoadStmt:
269  case T_PrepareStmt:
270  case T_UnlistenStmt:
271  case T_VariableSetStmt:
272  {
273  /*
274  * These modify only backend-local state, so they're OK to
275  * run in a read-only transaction or on a standby. However,
276  * they are disallowed in parallel mode, because they either
277  * rely upon or modify backend-local state that might not be
278  * synchronized among cooperating backends.
279  */
281  }
282 
283  case T_ClusterStmt:
284  case T_ReindexStmt:
285  case T_VacuumStmt:
286  {
287  /*
288  * These commands write WAL, so they're not strictly read-only,
289  * and running them in parallel workers isn't supported.
290  *
291  * However, they don't change the database state in a way that
292  * would affect pg_dump output, so it's fine to run them in a
293  * read-only transaction. (CLUSTER might change the order of
294  * rows on disk, which could affect the ordering of pg_dump
295  * output, but that's not semantically significant.)
296  */
298  }
299 
300  case T_CopyStmt:
301  {
302  CopyStmt *stmt = (CopyStmt *) parsetree;
303 
304  /*
305  * You might think that COPY FROM is not at all read only,
306  * but it's OK to copy into a temporary table, because that
307  * wouldn't change the output of pg_dump. If the target table
308  * turns out to be non-temporary, DoCopy itself will call
309  * PreventCommandIfReadOnly.
310  */
311  if (stmt->is_from)
313  else
315  }
316 
317  case T_ExplainStmt:
318  case T_VariableShowStmt:
319  {
320  /*
321  * These commands don't modify any data and are safe to run
322  * in a parallel worker.
323  */
325  }
326 
327  case T_ListenStmt:
328  case T_NotifyStmt:
329  {
330  /*
331  * NOTIFY requires an XID assignment, so it can't be permitted
332  * on a standby. Perhaps LISTEN could, since without NOTIFY
333  * it would be OK to just do nothing, at least until promotion,
334  * but we currently prohibit it lest the user get the wrong
335  * idea.
336  *
337  * (We do allow T_UnlistenStmt on a standby, though, because
338  * it's a no-op.)
339  */
341  }
342 
343  case T_LockStmt:
344  {
345  LockStmt *stmt = (LockStmt *) parsetree;
346 
347  /*
348  * Only weaker locker modes are allowed during recovery. The
349  * restrictions here must match those in LockAcquireExtended().
350  */
351  if (stmt->mode > RowExclusiveLock)
353  else
355  }
356 
357  case T_TransactionStmt:
358  {
359  TransactionStmt *stmt = (TransactionStmt *) parsetree;
360 
361  /*
362  * PREPARE, COMMIT PREPARED, and ROLLBACK PREPARED all
363  * write WAL, so they're not read-only in the strict sense;
364  * but the first and third do not change pg_dump output, so
365  * they're OK in a read-only transactions.
366  *
367  * We also consider COMMIT PREPARED to be OK in a read-only
368  * transaction environment, by way of exception.
369  */
370  switch (stmt->kind)
371  {
372  case TRANS_STMT_BEGIN:
373  case TRANS_STMT_START:
374  case TRANS_STMT_COMMIT:
375  case TRANS_STMT_ROLLBACK:
377  case TRANS_STMT_RELEASE:
380 
381  case TRANS_STMT_PREPARE:
385  }
386  elog(ERROR, "unrecognized TransactionStmtKind: %d",
387  (int) stmt->kind);
388  return 0; /* silence stupider compilers */
389  }
390 
391  default:
392  elog(ERROR, "unrecognized node type: %d",
393  (int) nodeTag(parsetree));
394  return 0; /* silence stupider compilers */
395  }
396 }
#define COMMAND_OK_IN_RECOVERY
Definition: utility.h:58
#define ERROR
Definition: elog.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
#define nodeTag(nodeptr)
Definition: nodes.h:531
#define COMMAND_IS_NOT_READ_ONLY
Definition: utility.h:68
bool is_from
Definition: parsenodes.h:2013
#define elog(elevel,...)
Definition: elog.h:214
#define COMMAND_IS_STRICTLY_READ_ONLY
Definition: utility.h:65
#define COMMAND_OK_IN_READ_ONLY_TXN
Definition: utility.h:56
TransactionStmtKind kind
Definition: parsenodes.h:3053

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

Definition at line 99 of file utility.c.

References Assert, CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, PlannedStmt::commandType, elog, PlannedStmt::hasModifyingCTE, IsA, NIL, PlannedStmt::rowMarks, and WARNING.

Referenced by _SPI_execute_plan(), CreateCommandName(), init_execution_state(), and SPI_cursor_open_internal().

100 {
101  Assert(IsA(pstmt, PlannedStmt));
102  switch (pstmt->commandType)
103  {
104  case CMD_SELECT:
105  if (pstmt->rowMarks != NIL)
106  return false; /* SELECT FOR [KEY] UPDATE/SHARE */
107  else if (pstmt->hasModifyingCTE)
108  return false; /* data-modifying CTE */
109  else
110  return true;
111  case CMD_UPDATE:
112  case CMD_INSERT:
113  case CMD_DELETE:
114  return false;
115  case CMD_UTILITY:
116  /* For now, treat all utility commands as read/write */
117  return false;
118  default:
119  elog(WARNING, "unrecognized commandType: %d",
120  (int) pstmt->commandType);
121  break;
122  }
123  return false;
124 }
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:577
#define WARNING
Definition: elog.h:40
CmdType commandType
Definition: plannodes.h:46
List * rowMarks
Definition: plannodes.h:84
#define Assert(condition)
Definition: c.h:738
bool hasModifyingCTE
Definition: plannodes.h:52
#define elog(elevel,...)
Definition: elog.h:214

◆ CreateCommandTag()

CommandTag CreateCommandTag ( Node parsetree)

Definition at line 2244 of file utility.c.

References AlterObjectTypeCommandTag(), CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, PlannedStmt::commandType, Query::commandType, CreateCommandTag(), DISCARD_ALL, DISCARD_PLANS, DISCARD_SEQUENCES, DISCARD_TEMP, elog, GrantStmt::is_grant, GrantRoleStmt::is_grant, FetchStmt::ismove, TransactionStmt::kind, LCS_FORKEYSHARE, LCS_FORNOKEYUPDATE, LCS_FORSHARE, LCS_FORUPDATE, linitial, DeallocateStmt::name, NIL, nodeTag, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DOMAIN, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_TABLE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ClosePortalStmt::portalname, PlannedStmt::rowMarks, Query::rowMarks, T_AlterCollationStmt, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterStatsStmt, T_AlterSubscriptionStmt, T_AlterSystemStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterTypeStmt, T_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DeleteStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PrepareStmt, T_Query, T_RawStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_SelectStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_UpdateStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, PlannedStmt::utilityStmt, Query::utilityStmt, VAR_RESET, VAR_RESET_ALL, VAR_SET_CURRENT, VAR_SET_DEFAULT, VAR_SET_MULTI, VAR_SET_VALUE, and WARNING.

Referenced by _SPI_prepare_oneshot_plan(), _SPI_prepare_plan(), CreateCommandName(), CreateCommandTag(), EventTriggerCommonSetup(), exec_parse_message(), exec_simple_query(), PrepareQuery(), and standard_ProcessUtility().

2245 {
2246  CommandTag tag;
2247 
2248  switch (nodeTag(parsetree))
2249  {
2250  /* recurse if we're given a RawStmt */
2251  case T_RawStmt:
2252  tag = CreateCommandTag(((RawStmt *) parsetree)->stmt);
2253  break;
2254 
2255  /* raw plannable queries */
2256  case T_InsertStmt:
2257  tag = CMDTAG_INSERT;
2258  break;
2259 
2260  case T_DeleteStmt:
2261  tag = CMDTAG_DELETE;
2262  break;
2263 
2264  case T_UpdateStmt:
2265  tag = CMDTAG_UPDATE;
2266  break;
2267 
2268  case T_SelectStmt:
2269  tag = CMDTAG_SELECT;
2270  break;
2271 
2272  /* utility statements --- same whether raw or cooked */
2273  case T_TransactionStmt:
2274  {
2275  TransactionStmt *stmt = (TransactionStmt *) parsetree;
2276 
2277  switch (stmt->kind)
2278  {
2279  case TRANS_STMT_BEGIN:
2280  tag = CMDTAG_BEGIN;
2281  break;
2282 
2283  case TRANS_STMT_START:
2284  tag = CMDTAG_START_TRANSACTION;
2285  break;
2286 
2287  case TRANS_STMT_COMMIT:
2288  tag = CMDTAG_COMMIT;
2289  break;
2290 
2291  case TRANS_STMT_ROLLBACK:
2293  tag = CMDTAG_ROLLBACK;
2294  break;
2295 
2296  case TRANS_STMT_SAVEPOINT:
2297  tag = CMDTAG_SAVEPOINT;
2298  break;
2299 
2300  case TRANS_STMT_RELEASE:
2301  tag = CMDTAG_RELEASE;
2302  break;
2303 
2304  case TRANS_STMT_PREPARE:
2305  tag = CMDTAG_PREPARE_TRANSACTION;
2306  break;
2307 
2309  tag = CMDTAG_COMMIT_PREPARED;
2310  break;
2311 
2313  tag = CMDTAG_ROLLBACK_PREPARED;
2314  break;
2315 
2316  default:
2317  tag = CMDTAG_UNKNOWN;
2318  break;
2319  }
2320  }
2321  break;
2322 
2323  case T_DeclareCursorStmt:
2324  tag = CMDTAG_DECLARE_CURSOR;
2325  break;
2326 
2327  case T_ClosePortalStmt:
2328  {
2329  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
2330 
2331  if (stmt->portalname == NULL)
2332  tag = CMDTAG_CLOSE_CURSOR_ALL;
2333  else
2334  tag = CMDTAG_CLOSE_CURSOR;
2335  }
2336  break;
2337 
2338  case T_FetchStmt:
2339  {
2340  FetchStmt *stmt = (FetchStmt *) parsetree;
2341 
2342  tag = (stmt->ismove) ? CMDTAG_MOVE : CMDTAG_FETCH;
2343  }
2344  break;
2345 
2346  case T_CreateDomainStmt:
2347  tag = CMDTAG_CREATE_DOMAIN;
2348  break;
2349 
2350  case T_CreateSchemaStmt:
2351  tag = CMDTAG_CREATE_SCHEMA;
2352  break;
2353 
2354  case T_CreateStmt:
2355  tag = CMDTAG_CREATE_TABLE;
2356  break;
2357 
2359  tag = CMDTAG_CREATE_TABLESPACE;
2360  break;
2361 
2362  case T_DropTableSpaceStmt:
2363  tag = CMDTAG_DROP_TABLESPACE;
2364  break;
2365 
2367  tag = CMDTAG_ALTER_TABLESPACE;
2368  break;
2369 
2370  case T_CreateExtensionStmt:
2371  tag = CMDTAG_CREATE_EXTENSION;
2372  break;
2373 
2374  case T_AlterExtensionStmt:
2375  tag = CMDTAG_ALTER_EXTENSION;
2376  break;
2377 
2379  tag = CMDTAG_ALTER_EXTENSION;
2380  break;
2381 
2382  case T_CreateFdwStmt:
2383  tag = CMDTAG_CREATE_FOREIGN_DATA_WRAPPER;
2384  break;
2385 
2386  case T_AlterFdwStmt:
2387  tag = CMDTAG_ALTER_FOREIGN_DATA_WRAPPER;
2388  break;
2389 
2391  tag = CMDTAG_CREATE_SERVER;
2392  break;
2393 
2395  tag = CMDTAG_ALTER_SERVER;
2396  break;
2397 
2399  tag = CMDTAG_CREATE_USER_MAPPING;
2400  break;
2401 
2403  tag = CMDTAG_ALTER_USER_MAPPING;
2404  break;
2405 
2406  case T_DropUserMappingStmt:
2407  tag = CMDTAG_DROP_USER_MAPPING;
2408  break;
2409 
2411  tag = CMDTAG_CREATE_FOREIGN_TABLE;
2412  break;
2413 
2415  tag = CMDTAG_IMPORT_FOREIGN_SCHEMA;
2416  break;
2417 
2418  case T_DropStmt:
2419  switch (((DropStmt *) parsetree)->removeType)
2420  {
2421  case OBJECT_TABLE:
2422  tag = CMDTAG_DROP_TABLE;
2423  break;
2424  case OBJECT_SEQUENCE:
2425  tag = CMDTAG_DROP_SEQUENCE;
2426  break;
2427  case OBJECT_VIEW:
2428  tag = CMDTAG_DROP_VIEW;
2429  break;
2430  case OBJECT_MATVIEW:
2431  tag = CMDTAG_DROP_MATERIALIZED_VIEW;
2432  break;
2433  case OBJECT_INDEX:
2434  tag = CMDTAG_DROP_INDEX;
2435  break;
2436  case OBJECT_TYPE:
2437  tag = CMDTAG_DROP_TYPE;
2438  break;
2439  case OBJECT_DOMAIN:
2440  tag = CMDTAG_DROP_DOMAIN;
2441  break;
2442  case OBJECT_COLLATION:
2443  tag = CMDTAG_DROP_COLLATION;
2444  break;
2445  case OBJECT_CONVERSION:
2446  tag = CMDTAG_DROP_CONVERSION;
2447  break;
2448  case OBJECT_SCHEMA:
2449  tag = CMDTAG_DROP_SCHEMA;
2450  break;
2451  case OBJECT_TSPARSER:
2452  tag = CMDTAG_DROP_TEXT_SEARCH_PARSER;
2453  break;
2454  case OBJECT_TSDICTIONARY:
2455  tag = CMDTAG_DROP_TEXT_SEARCH_DICTIONARY;
2456  break;
2457  case OBJECT_TSTEMPLATE:
2458  tag = CMDTAG_DROP_TEXT_SEARCH_TEMPLATE;
2459  break;
2461  tag = CMDTAG_DROP_TEXT_SEARCH_CONFIGURATION;
2462  break;
2463  case OBJECT_FOREIGN_TABLE:
2464  tag = CMDTAG_DROP_FOREIGN_TABLE;
2465  break;
2466  case OBJECT_EXTENSION:
2467  tag = CMDTAG_DROP_EXTENSION;
2468  break;
2469  case OBJECT_FUNCTION:
2470  tag = CMDTAG_DROP_FUNCTION;
2471  break;
2472  case OBJECT_PROCEDURE:
2473  tag = CMDTAG_DROP_PROCEDURE;
2474  break;
2475  case OBJECT_ROUTINE:
2476  tag = CMDTAG_DROP_ROUTINE;
2477  break;
2478  case OBJECT_AGGREGATE:
2479  tag = CMDTAG_DROP_AGGREGATE;
2480  break;
2481  case OBJECT_OPERATOR:
2482  tag = CMDTAG_DROP_OPERATOR;
2483  break;
2484  case OBJECT_LANGUAGE:
2485  tag = CMDTAG_DROP_LANGUAGE;
2486  break;
2487  case OBJECT_CAST:
2488  tag = CMDTAG_DROP_CAST;
2489  break;
2490  case OBJECT_TRIGGER:
2491  tag = CMDTAG_DROP_TRIGGER;
2492  break;
2493  case OBJECT_EVENT_TRIGGER:
2494  tag = CMDTAG_DROP_EVENT_TRIGGER;
2495  break;
2496  case OBJECT_RULE:
2497  tag = CMDTAG_DROP_RULE;
2498  break;
2499  case OBJECT_FDW:
2500  tag = CMDTAG_DROP_FOREIGN_DATA_WRAPPER;
2501  break;
2502  case OBJECT_FOREIGN_SERVER:
2503  tag = CMDTAG_DROP_SERVER;
2504  break;
2505  case OBJECT_OPCLASS:
2506  tag = CMDTAG_DROP_OPERATOR_CLASS;
2507  break;
2508  case OBJECT_OPFAMILY:
2509  tag = CMDTAG_DROP_OPERATOR_FAMILY;
2510  break;
2511  case OBJECT_POLICY:
2512  tag = CMDTAG_DROP_POLICY;
2513  break;
2514  case OBJECT_TRANSFORM:
2515  tag = CMDTAG_DROP_TRANSFORM;
2516  break;
2517  case OBJECT_ACCESS_METHOD:
2518  tag = CMDTAG_DROP_ACCESS_METHOD;
2519  break;
2520  case OBJECT_PUBLICATION:
2521  tag = CMDTAG_DROP_PUBLICATION;
2522  break;
2523  case OBJECT_STATISTIC_EXT:
2524  tag = CMDTAG_DROP_STATISTICS;
2525  break;
2526  default:
2527  tag = CMDTAG_UNKNOWN;
2528  }
2529  break;
2530 
2531  case T_TruncateStmt:
2532  tag = CMDTAG_TRUNCATE_TABLE;
2533  break;
2534 
2535  case T_CommentStmt:
2536  tag = CMDTAG_COMMENT;
2537  break;
2538 
2539  case T_SecLabelStmt:
2540  tag = CMDTAG_SECURITY_LABEL;
2541  break;
2542 
2543  case T_CopyStmt:
2544  tag = CMDTAG_COPY;
2545  break;
2546 
2547  case T_RenameStmt:
2548 
2549  /*
2550  * When the column is renamed, the command tag is created from its
2551  * relation type
2552  */
2553  tag = AlterObjectTypeCommandTag(((RenameStmt *) parsetree)->renameType == OBJECT_COLUMN ?
2554  ((RenameStmt *) parsetree)->relationType :
2555  ((RenameStmt *) parsetree)->renameType);
2556  break;
2557 
2559  tag = AlterObjectTypeCommandTag(((AlterObjectDependsStmt *) parsetree)->objectType);
2560  break;
2561 
2563  tag = AlterObjectTypeCommandTag(((AlterObjectSchemaStmt *) parsetree)->objectType);
2564  break;
2565 
2566  case T_AlterOwnerStmt:
2567  tag = AlterObjectTypeCommandTag(((AlterOwnerStmt *) parsetree)->objectType);
2568  break;
2569 
2571  tag = AlterObjectTypeCommandTag(((AlterTableMoveAllStmt *) parsetree)->objtype);
2572  break;
2573 
2574  case T_AlterTableStmt:
2575  tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->relkind);
2576  break;
2577 
2578  case T_AlterDomainStmt:
2579  tag = CMDTAG_ALTER_DOMAIN;
2580  break;
2581 
2582  case T_AlterFunctionStmt:
2583  switch (((AlterFunctionStmt *) parsetree)->objtype)
2584  {
2585  case OBJECT_FUNCTION:
2586  tag = CMDTAG_ALTER_FUNCTION;
2587  break;
2588  case OBJECT_PROCEDURE:
2589  tag = CMDTAG_ALTER_PROCEDURE;
2590  break;
2591  case OBJECT_ROUTINE:
2592  tag = CMDTAG_ALTER_ROUTINE;
2593  break;
2594  default:
2595  tag = CMDTAG_UNKNOWN;
2596  }
2597  break;
2598 
2599  case T_GrantStmt:
2600  {
2601  GrantStmt *stmt = (GrantStmt *) parsetree;
2602 
2603  tag = (stmt->is_grant) ? CMDTAG_GRANT : CMDTAG_REVOKE;
2604  }
2605  break;
2606 
2607  case T_GrantRoleStmt:
2608  {
2609  GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;
2610 
2611  tag = (stmt->is_grant) ? CMDTAG_GRANT_ROLE : CMDTAG_REVOKE_ROLE;
2612  }
2613  break;
2614 
2616  tag = CMDTAG_ALTER_DEFAULT_PRIVILEGES;
2617  break;
2618 
2619  case T_DefineStmt:
2620  switch (((DefineStmt *) parsetree)->kind)
2621  {
2622  case OBJECT_AGGREGATE:
2623  tag = CMDTAG_CREATE_AGGREGATE;
2624  break;
2625  case OBJECT_OPERATOR:
2626  tag = CMDTAG_CREATE_OPERATOR;
2627  break;
2628  case OBJECT_TYPE:
2629  tag = CMDTAG_CREATE_TYPE;
2630  break;
2631  case OBJECT_TSPARSER:
2632  tag = CMDTAG_CREATE_TEXT_SEARCH_PARSER;
2633  break;
2634  case OBJECT_TSDICTIONARY:
2635  tag = CMDTAG_CREATE_TEXT_SEARCH_DICTIONARY;
2636  break;
2637  case OBJECT_TSTEMPLATE:
2638  tag = CMDTAG_CREATE_TEXT_SEARCH_TEMPLATE;
2639  break;
2641  tag = CMDTAG_CREATE_TEXT_SEARCH_CONFIGURATION;
2642  break;
2643  case OBJECT_COLLATION:
2644  tag = CMDTAG_CREATE_COLLATION;
2645  break;
2646  case OBJECT_ACCESS_METHOD:
2647  tag = CMDTAG_CREATE_ACCESS_METHOD;
2648  break;
2649  default:
2650  tag = CMDTAG_UNKNOWN;
2651  }
2652  break;
2653 
2654  case T_CompositeTypeStmt:
2655  tag = CMDTAG_CREATE_TYPE;
2656  break;
2657 
2658  case T_CreateEnumStmt:
2659  tag = CMDTAG_CREATE_TYPE;
2660  break;
2661 
2662  case T_CreateRangeStmt:
2663  tag = CMDTAG_CREATE_TYPE;
2664  break;
2665 
2666  case T_AlterEnumStmt:
2667  tag = CMDTAG_ALTER_TYPE;
2668  break;
2669 
2670  case T_ViewStmt:
2671  tag = CMDTAG_CREATE_VIEW;
2672  break;
2673 
2674  case T_CreateFunctionStmt:
2675  if (((CreateFunctionStmt *) parsetree)->is_procedure)
2676  tag = CMDTAG_CREATE_PROCEDURE;
2677  else
2678  tag = CMDTAG_CREATE_FUNCTION;
2679  break;
2680 
2681  case T_IndexStmt:
2682  tag = CMDTAG_CREATE_INDEX;
2683  break;
2684 
2685  case T_RuleStmt:
2686  tag = CMDTAG_CREATE_RULE;
2687  break;
2688 
2689  case T_CreateSeqStmt:
2690  tag = CMDTAG_CREATE_SEQUENCE;
2691  break;
2692 
2693  case T_AlterSeqStmt:
2694  tag = CMDTAG_ALTER_SEQUENCE;
2695  break;
2696 
2697  case T_DoStmt:
2698  tag = CMDTAG_DO;
2699  break;
2700 
2701  case T_CreatedbStmt:
2702  tag = CMDTAG_CREATE_DATABASE;
2703  break;
2704 
2705  case T_AlterDatabaseStmt:
2706  tag = CMDTAG_ALTER_DATABASE;
2707  break;
2708 
2710  tag = CMDTAG_ALTER_DATABASE;
2711  break;
2712 
2713  case T_DropdbStmt:
2714  tag = CMDTAG_DROP_DATABASE;
2715  break;
2716 
2717  case T_NotifyStmt:
2718  tag = CMDTAG_NOTIFY;
2719  break;
2720 
2721  case T_ListenStmt:
2722  tag = CMDTAG_LISTEN;
2723  break;
2724 
2725  case T_UnlistenStmt:
2726  tag = CMDTAG_UNLISTEN;
2727  break;
2728 
2729  case T_LoadStmt:
2730  tag = CMDTAG_LOAD;
2731  break;
2732 
2733  case T_CallStmt:
2734  tag = CMDTAG_CALL;
2735  break;
2736 
2737  case T_ClusterStmt:
2738  tag = CMDTAG_CLUSTER;
2739  break;
2740 
2741  case T_VacuumStmt:
2742  if (((VacuumStmt *) parsetree)->is_vacuumcmd)
2743  tag = CMDTAG_VACUUM;
2744  else
2745  tag = CMDTAG_ANALYZE;
2746  break;
2747 
2748  case T_ExplainStmt:
2749  tag = CMDTAG_EXPLAIN;
2750  break;
2751 
2752  case T_CreateTableAsStmt:
2753  switch (((CreateTableAsStmt *) parsetree)->relkind)
2754  {
2755  case OBJECT_TABLE:
2756  if (((CreateTableAsStmt *) parsetree)->is_select_into)
2757  tag = CMDTAG_SELECT_INTO;
2758  else
2759  tag = CMDTAG_CREATE_TABLE_AS;
2760  break;
2761  case OBJECT_MATVIEW:
2762  tag = CMDTAG_CREATE_MATERIALIZED_VIEW;
2763  break;
2764  default:
2765  tag = CMDTAG_UNKNOWN;
2766  }
2767  break;
2768 
2769  case T_RefreshMatViewStmt:
2770  tag = CMDTAG_REFRESH_MATERIALIZED_VIEW;
2771  break;
2772 
2773  case T_AlterSystemStmt:
2774  tag = CMDTAG_ALTER_SYSTEM;
2775  break;
2776 
2777  case T_VariableSetStmt:
2778  switch (((VariableSetStmt *) parsetree)->kind)
2779  {
2780  case VAR_SET_VALUE:
2781  case VAR_SET_CURRENT:
2782  case VAR_SET_DEFAULT:
2783  case VAR_SET_MULTI:
2784  tag = CMDTAG_SET;
2785  break;
2786  case VAR_RESET:
2787  case VAR_RESET_ALL:
2788  tag = CMDTAG_RESET;
2789  break;
2790  default:
2791  tag = CMDTAG_UNKNOWN;
2792  }
2793  break;
2794 
2795  case T_VariableShowStmt:
2796  tag = CMDTAG_SHOW;
2797  break;
2798 
2799  case T_DiscardStmt:
2800  switch (((DiscardStmt *) parsetree)->target)
2801  {
2802  case DISCARD_ALL:
2803  tag = CMDTAG_DISCARD_ALL;
2804  break;
2805  case DISCARD_PLANS:
2806  tag = CMDTAG_DISCARD_PLANS;
2807  break;
2808  case DISCARD_TEMP:
2809  tag = CMDTAG_DISCARD_TEMP;
2810  break;
2811  case DISCARD_SEQUENCES:
2812  tag = CMDTAG_DISCARD_SEQUENCES;
2813  break;
2814  default:
2815  tag = CMDTAG_UNKNOWN;
2816  }
2817  break;
2818 
2819  case T_CreateTransformStmt:
2820  tag = CMDTAG_CREATE_TRANSFORM;
2821  break;
2822 
2823  case T_CreateTrigStmt:
2824  tag = CMDTAG_CREATE_TRIGGER;
2825  break;
2826 
2827  case T_CreateEventTrigStmt:
2828  tag = CMDTAG_CREATE_EVENT_TRIGGER;
2829  break;
2830 
2831  case T_AlterEventTrigStmt:
2832  tag = CMDTAG_ALTER_EVENT_TRIGGER;
2833  break;
2834 
2835  case T_CreatePLangStmt:
2836  tag = CMDTAG_CREATE_LANGUAGE;
2837  break;
2838 
2839  case T_CreateRoleStmt:
2840  tag = CMDTAG_CREATE_ROLE;
2841  break;
2842 
2843  case T_AlterRoleStmt:
2844  tag = CMDTAG_ALTER_ROLE;
2845  break;
2846 
2847  case T_AlterRoleSetStmt:
2848  tag = CMDTAG_ALTER_ROLE;
2849  break;
2850 
2851  case T_DropRoleStmt:
2852  tag = CMDTAG_DROP_ROLE;
2853  break;
2854 
2855  case T_DropOwnedStmt:
2856  tag = CMDTAG_DROP_OWNED;
2857  break;
2858 
2859  case T_ReassignOwnedStmt:
2860  tag = CMDTAG_REASSIGN_OWNED;
2861  break;
2862 
2863  case T_LockStmt:
2864  tag = CMDTAG_LOCK_TABLE;
2865  break;
2866 
2867  case T_ConstraintsSetStmt:
2868  tag = CMDTAG_SET_CONSTRAINTS;
2869  break;
2870 
2871  case T_CheckPointStmt:
2872  tag = CMDTAG_CHECKPOINT;
2873  break;
2874 
2875  case T_ReindexStmt:
2876  tag = CMDTAG_REINDEX;
2877  break;
2878 
2880  tag = CMDTAG_CREATE_CONVERSION;
2881  break;
2882 
2883  case T_CreateCastStmt:
2884  tag = CMDTAG_CREATE_CAST;
2885  break;
2886 
2887  case T_CreateOpClassStmt:
2888  tag = CMDTAG_CREATE_OPERATOR_CLASS;
2889  break;
2890 
2891  case T_CreateOpFamilyStmt:
2892  tag = CMDTAG_CREATE_OPERATOR_FAMILY;
2893  break;
2894 
2895  case T_AlterOpFamilyStmt:
2896  tag = CMDTAG_ALTER_OPERATOR_FAMILY;
2897  break;
2898 
2899  case T_AlterOperatorStmt:
2900  tag = CMDTAG_ALTER_OPERATOR;
2901  break;
2902 
2903  case T_AlterTypeStmt:
2904  tag = CMDTAG_ALTER_TYPE;
2905  break;
2906 
2908  tag = CMDTAG_ALTER_TEXT_SEARCH_DICTIONARY;
2909  break;
2910 
2912  tag = CMDTAG_ALTER_TEXT_SEARCH_CONFIGURATION;
2913  break;
2914 
2915  case T_CreatePolicyStmt:
2916  tag = CMDTAG_CREATE_POLICY;
2917  break;
2918 
2919  case T_AlterPolicyStmt:
2920  tag = CMDTAG_ALTER_POLICY;
2921  break;
2922 
2923  case T_CreateAmStmt:
2924  tag = CMDTAG_CREATE_ACCESS_METHOD;
2925  break;
2926 
2928  tag = CMDTAG_CREATE_PUBLICATION;
2929  break;
2930 
2932  tag = CMDTAG_ALTER_PUBLICATION;
2933  break;
2934 
2936  tag = CMDTAG_CREATE_SUBSCRIPTION;
2937  break;
2938 
2940  tag = CMDTAG_ALTER_SUBSCRIPTION;
2941  break;
2942 
2944  tag = CMDTAG_DROP_SUBSCRIPTION;
2945  break;
2946 
2947  case T_AlterCollationStmt:
2948  tag = CMDTAG_ALTER_COLLATION;
2949  break;
2950 
2951  case T_PrepareStmt:
2952  tag = CMDTAG_PREPARE;
2953  break;
2954 
2955  case T_ExecuteStmt:
2956  tag = CMDTAG_EXECUTE;
2957  break;
2958 
2959  case T_CreateStatsStmt:
2960  tag = CMDTAG_CREATE_STATISTICS;
2961  break;
2962 
2963  case T_AlterStatsStmt:
2964  tag = CMDTAG_ALTER_STATISTICS;
2965  break;
2966 
2967  case T_DeallocateStmt:
2968  {
2969  DeallocateStmt *stmt = (DeallocateStmt *) parsetree;
2970 
2971  if (stmt->name == NULL)
2972  tag = CMDTAG_DEALLOCATE_ALL;
2973  else
2974  tag = CMDTAG_DEALLOCATE;
2975  }
2976  break;
2977 
2978  /* already-planned queries */
2979  case T_PlannedStmt:
2980  {
2981  PlannedStmt *stmt = (PlannedStmt *) parsetree;
2982 
2983  switch (stmt->commandType)
2984  {
2985  case CMD_SELECT:
2986 
2987  /*
2988  * We take a little extra care here so that the result
2989  * will be useful for complaints about read-only
2990  * statements
2991  */
2992  if (stmt->rowMarks != NIL)
2993  {
2994  /* not 100% but probably close enough */
2995  switch (((PlanRowMark *) linitial(stmt->rowMarks))->strength)
2996  {
2997  case LCS_FORKEYSHARE:
2998  tag = CMDTAG_SELECT_FOR_KEY_SHARE;
2999  break;
3000  case LCS_FORSHARE:
3001  tag = CMDTAG_SELECT_FOR_SHARE;
3002  break;
3003  case LCS_FORNOKEYUPDATE:
3004  tag = CMDTAG_SELECT_FOR_NO_KEY_UPDATE;
3005  break;
3006  case LCS_FORUPDATE:
3007  tag = CMDTAG_SELECT_FOR_UPDATE;
3008  break;
3009  default:
3010  tag = CMDTAG_SELECT;
3011  break;
3012  }
3013  }
3014  else
3015  tag = CMDTAG_SELECT;
3016  break;
3017  case CMD_UPDATE:
3018  tag = CMDTAG_UPDATE;
3019  break;
3020  case CMD_INSERT:
3021  tag = CMDTAG_INSERT;
3022  break;
3023  case CMD_DELETE:
3024  tag = CMDTAG_DELETE;
3025  break;
3026  case CMD_UTILITY:
3027  tag = CreateCommandTag(stmt->utilityStmt);
3028  break;
3029  default:
3030  elog(WARNING, "unrecognized commandType: %d",
3031  (int) stmt->commandType);
3032  tag = CMDTAG_UNKNOWN;
3033  break;
3034  }
3035  }
3036  break;
3037 
3038  /* parsed-and-rewritten-but-not-planned queries */
3039  case T_Query:
3040  {
3041  Query *stmt = (Query *) parsetree;
3042 
3043  switch (stmt->commandType)
3044  {
3045  case CMD_SELECT:
3046 
3047  /*
3048  * We take a little extra care here so that the result
3049  * will be useful for complaints about read-only
3050  * statements
3051  */
3052  if (stmt->rowMarks != NIL)
3053  {
3054  /* not 100% but probably close enough */
3055  switch (((RowMarkClause *) linitial(stmt->rowMarks))->strength)
3056  {
3057  case LCS_FORKEYSHARE:
3058  tag = CMDTAG_SELECT_FOR_KEY_SHARE;
3059  break;
3060  case LCS_FORSHARE:
3061  tag = CMDTAG_SELECT_FOR_SHARE;
3062  break;
3063  case LCS_FORNOKEYUPDATE:
3064  tag = CMDTAG_SELECT_FOR_NO_KEY_UPDATE;
3065  break;
3066  case LCS_FORUPDATE:
3067  tag = CMDTAG_SELECT_FOR_UPDATE;
3068  break;
3069  default:
3070  tag = CMDTAG_UNKNOWN;
3071  break;
3072  }
3073  }
3074  else
3075  tag = CMDTAG_SELECT;
3076  break;
3077  case CMD_UPDATE:
3078  tag = CMDTAG_UPDATE;
3079  break;
3080  case CMD_INSERT:
3081  tag = CMDTAG_INSERT;
3082  break;
3083  case CMD_DELETE:
3084  tag = CMDTAG_DELETE;
3085  break;
3086  case CMD_UTILITY:
3087  tag = CreateCommandTag(stmt->utilityStmt);
3088  break;
3089  default:
3090  elog(WARNING, "unrecognized commandType: %d",
3091  (int) stmt->commandType);
3092  tag = CMDTAG_UNKNOWN;
3093  break;
3094  }
3095  }
3096  break;
3097 
3098  default:
3099  elog(WARNING, "unrecognized node type: %d",
3100  (int) nodeTag(parsetree));
3101  tag = CMDTAG_UNKNOWN;
3102  break;
3103  }
3104 
3105  return tag;
3106 }
#define NIL
Definition: pg_list.h:65
CommandTag
Definition: cmdtag.h:20
static CommandTag AlterObjectTypeCommandTag(ObjectType objtype)
Definition: utility.c:2098
List * rowMarks
Definition: parsenodes.h:163
Node * utilityStmt
Definition: parsenodes.h:120
#define linitial(l)
Definition: pg_list.h:195
Node * utilityStmt
Definition: plannodes.h:92
bool is_grant
Definition: parsenodes.h:1925
#define WARNING
Definition: elog.h:40
Definition: nodes.h:310
bool ismove
Definition: parsenodes.h:2756
CmdType commandType
Definition: plannodes.h:46
List * rowMarks
Definition: plannodes.h:84
CmdType commandType
Definition: parsenodes.h:112
CommandTag CreateCommandTag(Node *parsetree)
Definition: utility.c:2244
#define nodeTag(nodeptr)
Definition: nodes.h:531
#define elog(elevel,...)
Definition: elog.h:214
TransactionStmtKind kind
Definition: parsenodes.h:3053

◆ ExecDropStmt()

static void ExecDropStmt ( DropStmt stmt,
bool  isTopLevel 
)
static

Definition at line 1878 of file utility.c.

References DropStmt::concurrent, OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_VIEW, PreventInTransactionBlock(), RemoveObjects(), RemoveRelations(), and DropStmt::removeType.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

1879 {
1880  switch (stmt->removeType)
1881  {
1882  case OBJECT_INDEX:
1883  if (stmt->concurrent)
1884  PreventInTransactionBlock(isTopLevel,
1885  "DROP INDEX CONCURRENTLY");
1886  /* fall through */
1887 
1888  case OBJECT_TABLE:
1889  case OBJECT_SEQUENCE:
1890  case OBJECT_VIEW:
1891  case OBJECT_MATVIEW:
1892  case OBJECT_FOREIGN_TABLE:
1893  RemoveRelations(stmt);
1894  break;
1895  default:
1896  RemoveObjects(stmt);
1897  break;
1898  }
1899 }
void RemoveObjects(DropStmt *stmt)
Definition: dropcmds.c:57
ObjectType removeType
Definition: parsenodes.h:2653
void RemoveRelations(DropStmt *drop)
Definition: tablecmds.c:1254
bool concurrent
Definition: parsenodes.h:2656
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3331

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3119 of file utility.c.

References analyze(), CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, PlannedStmt::commandType, Query::commandType, defGetBoolean(), DefElem::defname, elog, FetchPreparedStatement(), GetCommandLogLevel(), lfirst, LOGSTMT_ALL, LOGSTMT_DDL, LOGSTMT_MOD, ExecuteStmt::name, nodeTag, ExplainStmt::options, PreparedStatement::plansource, ExplainStmt::query, PrepareStmt::query, CachedPlanSource::raw_parse_tree, RawStmt::stmt, T_AlterCollationStmt, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterStatsStmt, T_AlterSubscriptionStmt, T_AlterSystemStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterTypeStmt, T_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DeleteStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PrepareStmt, T_Query, T_RawStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_SelectStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_UpdateStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, PlannedStmt::utilityStmt, Query::utilityStmt, and WARNING.

Referenced by check_log_statement(), CreateCommandName(), and GetCommandLogLevel().

3120 {
3121  LogStmtLevel lev;
3122 
3123  switch (nodeTag(parsetree))
3124  {
3125  /* recurse if we're given a RawStmt */
3126  case T_RawStmt:
3127  lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
3128  break;
3129 
3130  /* raw plannable queries */
3131  case T_InsertStmt:
3132  case T_DeleteStmt:
3133  case T_UpdateStmt:
3134  lev = LOGSTMT_MOD;
3135  break;
3136 
3137  case T_SelectStmt:
3138  if (((SelectStmt *) parsetree)->intoClause)
3139  lev = LOGSTMT_DDL; /* SELECT INTO */
3140  else
3141  lev = LOGSTMT_ALL;
3142  break;
3143 
3144  /* utility statements --- same whether raw or cooked */
3145  case T_TransactionStmt:
3146  lev = LOGSTMT_ALL;
3147  break;
3148 
3149  case T_DeclareCursorStmt:
3150  lev = LOGSTMT_ALL;
3151  break;
3152 
3153  case T_ClosePortalStmt:
3154  lev = LOGSTMT_ALL;
3155  break;
3156 
3157  case T_FetchStmt:
3158  lev = LOGSTMT_ALL;
3159  break;
3160 
3161  case T_CreateSchemaStmt:
3162  lev = LOGSTMT_DDL;
3163  break;
3164 
3165  case T_CreateStmt:
3167  lev = LOGSTMT_DDL;
3168  break;
3169 
3171  case T_DropTableSpaceStmt:
3173  lev = LOGSTMT_DDL;
3174  break;
3175 
3176  case T_CreateExtensionStmt:
3177  case T_AlterExtensionStmt:
3179  lev = LOGSTMT_DDL;
3180  break;
3181 
3182  case T_CreateFdwStmt:
3183  case T_AlterFdwStmt:
3188  case T_DropUserMappingStmt:
3190  lev = LOGSTMT_DDL;
3191  break;
3192 
3193  case T_DropStmt:
3194  lev = LOGSTMT_DDL;
3195  break;
3196 
3197  case T_TruncateStmt:
3198  lev = LOGSTMT_MOD;
3199  break;
3200 
3201  case T_CommentStmt:
3202  lev = LOGSTMT_DDL;
3203  break;
3204 
3205  case T_SecLabelStmt:
3206  lev = LOGSTMT_DDL;
3207  break;
3208 
3209  case T_CopyStmt:
3210  if (((CopyStmt *) parsetree)->is_from)
3211  lev = LOGSTMT_MOD;
3212  else
3213  lev = LOGSTMT_ALL;
3214  break;
3215 
3216  case T_PrepareStmt:
3217  {
3218  PrepareStmt *stmt = (PrepareStmt *) parsetree;
3219 
3220  /* Look through a PREPARE to the contained stmt */
3221  lev = GetCommandLogLevel(stmt->query);
3222  }
3223  break;
3224 
3225  case T_ExecuteStmt:
3226  {
3227  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
3228  PreparedStatement *ps;
3229 
3230  /* Look through an EXECUTE to the referenced stmt */
3231  ps = FetchPreparedStatement(stmt->name, false);
3232  if (ps && ps->plansource->raw_parse_tree)
3234  else
3235  lev = LOGSTMT_ALL;
3236  }
3237  break;
3238 
3239  case T_DeallocateStmt:
3240  lev = LOGSTMT_ALL;
3241  break;
3242 
3243  case T_RenameStmt:
3244  lev = LOGSTMT_DDL;
3245  break;
3246 
3248  lev = LOGSTMT_DDL;
3249  break;
3250 
3252  lev = LOGSTMT_DDL;
3253  break;
3254 
3255  case T_AlterOwnerStmt:
3256  lev = LOGSTMT_DDL;
3257  break;
3258 
3259  case T_AlterOperatorStmt:
3260  lev = LOGSTMT_DDL;
3261  break;
3262 
3263  case T_AlterTypeStmt:
3264  lev = LOGSTMT_DDL;
3265  break;
3266 
3268  case T_AlterTableStmt:
3269  lev = LOGSTMT_DDL;
3270  break;
3271 
3272  case T_AlterDomainStmt:
3273  lev = LOGSTMT_DDL;
3274  break;
3275 
3276  case T_GrantStmt:
3277  lev = LOGSTMT_DDL;
3278  break;
3279 
3280  case T_GrantRoleStmt:
3281  lev = LOGSTMT_DDL;
3282  break;
3283 
3285  lev = LOGSTMT_DDL;
3286  break;
3287 
3288  case T_DefineStmt:
3289  lev = LOGSTMT_DDL;
3290  break;
3291 
3292  case T_CompositeTypeStmt:
3293  lev = LOGSTMT_DDL;
3294  break;
3295 
3296  case T_CreateEnumStmt:
3297  lev = LOGSTMT_DDL;
3298  break;
3299 
3300  case T_CreateRangeStmt:
3301  lev = LOGSTMT_DDL;
3302  break;
3303 
3304  case T_AlterEnumStmt:
3305  lev = LOGSTMT_DDL;
3306  break;
3307 
3308  case T_ViewStmt:
3309  lev = LOGSTMT_DDL;
3310  break;
3311 
3312  case T_CreateFunctionStmt:
3313  lev = LOGSTMT_DDL;
3314  break;
3315 
3316  case T_AlterFunctionStmt:
3317  lev = LOGSTMT_DDL;
3318  break;
3319 
3320  case T_IndexStmt:
3321  lev = LOGSTMT_DDL;
3322  break;
3323 
3324  case T_RuleStmt:
3325  lev = LOGSTMT_DDL;
3326  break;
3327 
3328  case T_CreateSeqStmt:
3329  lev = LOGSTMT_DDL;
3330  break;
3331 
3332  case T_AlterSeqStmt:
3333  lev = LOGSTMT_DDL;
3334  break;
3335 
3336  case T_DoStmt:
3337  lev = LOGSTMT_ALL;
3338  break;
3339 
3340  case T_CreatedbStmt:
3341  lev = LOGSTMT_DDL;
3342  break;
3343 
3344  case T_AlterDatabaseStmt:
3345  lev = LOGSTMT_DDL;
3346  break;
3347 
3349  lev = LOGSTMT_DDL;
3350  break;
3351 
3352  case T_DropdbStmt:
3353  lev = LOGSTMT_DDL;
3354  break;
3355 
3356  case T_NotifyStmt:
3357  lev = LOGSTMT_ALL;
3358  break;
3359 
3360  case T_ListenStmt:
3361  lev = LOGSTMT_ALL;
3362  break;
3363 
3364  case T_UnlistenStmt:
3365  lev = LOGSTMT_ALL;
3366  break;
3367 
3368  case T_LoadStmt:
3369  lev = LOGSTMT_ALL;
3370  break;
3371 
3372  case T_CallStmt:
3373  lev = LOGSTMT_ALL;
3374  break;
3375 
3376  case T_ClusterStmt:
3377  lev = LOGSTMT_DDL;
3378  break;
3379 
3380  case T_VacuumStmt:
3381  lev = LOGSTMT_ALL;
3382  break;
3383 
3384  case T_ExplainStmt:
3385  {
3386  ExplainStmt *stmt = (ExplainStmt *) parsetree;
3387  bool analyze = false;
3388  ListCell *lc;
3389 
3390  /* Look through an EXPLAIN ANALYZE to the contained stmt */
3391  foreach(lc, stmt->options)
3392  {
3393  DefElem *opt = (DefElem *) lfirst(lc);
3394 
3395  if (strcmp(opt->defname, "analyze") == 0)
3396  analyze = defGetBoolean(opt);
3397  /* don't "break", as explain.c will use the last value */
3398  }
3399  if (analyze)
3400  return GetCommandLogLevel(stmt->query);
3401 
3402  /* Plain EXPLAIN isn't so interesting */
3403  lev = LOGSTMT_ALL;
3404  }
3405  break;
3406 
3407  case T_CreateTableAsStmt:
3408  lev = LOGSTMT_DDL;
3409  break;
3410 
3411  case T_RefreshMatViewStmt:
3412  lev = LOGSTMT_DDL;
3413  break;
3414 
3415  case T_AlterSystemStmt:
3416  lev = LOGSTMT_DDL;
3417  break;
3418 
3419  case T_VariableSetStmt:
3420  lev = LOGSTMT_ALL;
3421  break;
3422 
3423  case T_VariableShowStmt:
3424  lev = LOGSTMT_ALL;
3425  break;
3426 
3427  case T_DiscardStmt:
3428  lev = LOGSTMT_ALL;
3429  break;
3430 
3431  case T_CreateTrigStmt:
3432  lev = LOGSTMT_DDL;
3433  break;
3434 
3435  case T_CreateEventTrigStmt:
3436  lev = LOGSTMT_DDL;
3437  break;
3438 
3439  case T_AlterEventTrigStmt:
3440  lev = LOGSTMT_DDL;
3441  break;
3442 
3443  case T_CreatePLangStmt:
3444  lev = LOGSTMT_DDL;
3445  break;
3446 
3447  case T_CreateDomainStmt:
3448  lev = LOGSTMT_DDL;
3449  break;
3450 
3451  case T_CreateRoleStmt:
3452  lev = LOGSTMT_DDL;
3453  break;
3454 
3455  case T_AlterRoleStmt:
3456  lev = LOGSTMT_DDL;
3457  break;
3458 
3459  case T_AlterRoleSetStmt:
3460  lev = LOGSTMT_DDL;
3461  break;
3462 
3463  case T_DropRoleStmt:
3464  lev = LOGSTMT_DDL;
3465  break;
3466 
3467  case T_DropOwnedStmt:
3468  lev = LOGSTMT_DDL;
3469  break;
3470 
3471  case T_ReassignOwnedStmt:
3472  lev = LOGSTMT_DDL;
3473  break;
3474 
3475  case T_LockStmt:
3476  lev = LOGSTMT_ALL;
3477  break;
3478 
3479  case T_ConstraintsSetStmt:
3480  lev = LOGSTMT_ALL;
3481  break;
3482 
3483  case T_CheckPointStmt:
3484  lev = LOGSTMT_ALL;
3485  break;
3486 
3487  case T_ReindexStmt:
3488  lev = LOGSTMT_ALL; /* should this be DDL? */
3489  break;
3490 
3492  lev = LOGSTMT_DDL;
3493  break;
3494 
3495  case T_CreateCastStmt:
3496  lev = LOGSTMT_DDL;
3497  break;
3498 
3499  case T_CreateOpClassStmt:
3500  lev = LOGSTMT_DDL;
3501  break;
3502 
3503  case T_CreateOpFamilyStmt:
3504  lev = LOGSTMT_DDL;
3505  break;
3506 
3507  case T_CreateTransformStmt:
3508  lev = LOGSTMT_DDL;
3509  break;
3510 
3511  case T_AlterOpFamilyStmt:
3512  lev = LOGSTMT_DDL;
3513  break;
3514 
3515  case T_CreatePolicyStmt:
3516  lev = LOGSTMT_DDL;
3517  break;
3518 
3519  case T_AlterPolicyStmt:
3520  lev = LOGSTMT_DDL;
3521  break;
3522 
3524  lev = LOGSTMT_DDL;
3525  break;
3526 
3528  lev = LOGSTMT_DDL;
3529  break;
3530 
3531  case T_CreateAmStmt:
3532  lev = LOGSTMT_DDL;
3533  break;
3534 
3536  lev = LOGSTMT_DDL;
3537  break;
3538 
3540  lev = LOGSTMT_DDL;
3541  break;
3542 
3544  lev = LOGSTMT_DDL;
3545  break;
3546 
3548  lev = LOGSTMT_DDL;
3549  break;
3550 
3552  lev = LOGSTMT_DDL;
3553  break;
3554 
3555  case T_CreateStatsStmt:
3556  lev = LOGSTMT_DDL;
3557  break;
3558 
3559  case T_AlterStatsStmt:
3560  lev = LOGSTMT_DDL;
3561  break;
3562 
3563  case T_AlterCollationStmt:
3564  lev = LOGSTMT_DDL;
3565  break;
3566 
3567  /* already-planned queries */
3568  case T_PlannedStmt:
3569  {
3570  PlannedStmt *stmt = (PlannedStmt *) parsetree;
3571 
3572  switch (stmt->commandType)
3573  {
3574  case CMD_SELECT:
3575  lev = LOGSTMT_ALL;
3576  break;
3577 
3578  case CMD_UPDATE:
3579  case CMD_INSERT:
3580  case CMD_DELETE:
3581  lev = LOGSTMT_MOD;
3582  break;
3583 
3584  case CMD_UTILITY:
3585  lev = GetCommandLogLevel(stmt->utilityStmt);
3586  break;
3587 
3588  default:
3589  elog(WARNING, "unrecognized commandType: %d",
3590  (int) stmt->commandType);
3591  lev = LOGSTMT_ALL;
3592  break;
3593  }
3594  }
3595  break;
3596 
3597  /* parsed-and-rewritten-but-not-planned queries */
3598  case T_Query:
3599  {
3600  Query *stmt = (Query *) parsetree;
3601 
3602  switch (stmt->commandType)
3603  {
3604  case CMD_SELECT:
3605  lev = LOGSTMT_ALL;
3606  break;
3607 
3608  case CMD_UPDATE:
3609  case CMD_INSERT:
3610  case CMD_DELETE:
3611  lev = LOGSTMT_MOD;
3612  break;
3613 
3614  case CMD_UTILITY:
3615  lev = GetCommandLogLevel(stmt->utilityStmt);
3616  break;
3617 
3618  default:
3619  elog(WARNING, "unrecognized commandType: %d",
3620  (int) stmt->commandType);
3621  lev = LOGSTMT_ALL;
3622  break;
3623  }
3624 
3625  }
3626  break;
3627 
3628  default:
3629  elog(WARNING, "unrecognized node type: %d",
3630  (int) nodeTag(parsetree));
3631  lev = LOGSTMT_ALL;
3632  break;
3633  }
3634 
3635  return lev;
3636 }
CachedPlanSource * plansource
Definition: prepare.h:31
LogStmtLevel
Definition: tcopprot.h:35
List * options
Definition: parsenodes.h:3251
Node * utilityStmt
Definition: parsenodes.h:120
Node * query
Definition: parsenodes.h:3250
bool defGetBoolean(DefElem *def)
Definition: define.c:111
Node * stmt
Definition: parsenodes.h:1507
Node * utilityStmt
Definition: plannodes.h:92
#define WARNING
Definition: elog.h:40
Definition: nodes.h:310
CmdType commandType
Definition: plannodes.h:46
CmdType commandType
Definition: parsenodes.h:112
#define lfirst(lc)
Definition: pg_list.h:190
Node * query
Definition: parsenodes.h:3420
struct RawStmt * raw_parse_tree
Definition: plancache.h:99
#define nodeTag(nodeptr)
Definition: nodes.h:531
#define elog(elevel,...)
Definition: elog.h:214
char * name
Definition: parsenodes.h:3432
char * defname
Definition: parsenodes.h:731
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:469
static long analyze(struct nfa *nfa)
Definition: regc_nfa.c:2816
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:3119

◆ PreventCommandDuringRecovery()

void PreventCommandDuringRecovery ( const char *  cmdname)

Definition at line 442 of file utility.c.

References ereport, errcode(), errmsg(), ERROR, and RecoveryInProgress().

Referenced by pg_notify(), standard_ProcessUtility(), and txid_current().

443 {
444  if (RecoveryInProgress())
445  ereport(ERROR,
446  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
447  /* translator: %s is name of a SQL command, eg CREATE */
448  errmsg("cannot execute %s during recovery",
449  cmdname)));
450 }
int errcode(int sqlerrcode)
Definition: elog.c:610
bool RecoveryInProgress(void)
Definition: xlog.c:8051
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ PreventCommandIfParallelMode()

void PreventCommandIfParallelMode ( const char *  cmdname)

Definition at line 423 of file utility.c.

References ereport, errcode(), errmsg(), ERROR, and IsInParallelMode().

Referenced by do_setval(), ExecCheckXactReadOnly(), nextval_internal(), and standard_ProcessUtility().

424 {
425  if (IsInParallelMode())
426  ereport(ERROR,
427  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
428  /* translator: %s is name of a SQL command, eg CREATE */
429  errmsg("cannot execute %s during a parallel operation",
430  cmdname)));
431 }
int errcode(int sqlerrcode)
Definition: elog.c:610
bool IsInParallelMode(void)
Definition: xact.c:996
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ PreventCommandIfReadOnly()

void PreventCommandIfReadOnly ( const char *  cmdname)

Definition at line 405 of file utility.c.

References ereport, errcode(), errmsg(), ERROR, and XactReadOnly.

Referenced by do_setval(), DoCopy(), ExecCheckXactReadOnly(), nextval_internal(), and standard_ProcessUtility().

406 {
407  if (XactReadOnly)
408  ereport(ERROR,
409  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
410  /* translator: %s is name of a SQL command, eg CREATE */
411  errmsg("cannot execute %s in a read-only transaction",
412  cmdname)));
413 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
bool XactReadOnly
Definition: xact.c:77
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ ProcessUtility()

void ProcessUtility ( PlannedStmt pstmt,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
QueryEnvironment queryEnv,
DestReceiver dest,
QueryCompletion qc 
)

Definition at line 499 of file utility.c.

References Assert, CMD_UTILITY, QueryCompletion::commandTag, PlannedStmt::commandType, generate_unaccent_rules::dest, IsA, ProcessUtility_hook, and standard_ProcessUtility().

Referenced by _SPI_execute_plan(), CreateSchemaCommand(), execute_sql_string(), ImportForeignSchema(), PortalRunUtility(), postquel_getnext(), ProcessUtilityForAlterTable(), and ProcessUtilitySlow().

506 {
507  Assert(IsA(pstmt, PlannedStmt));
508  Assert(pstmt->commandType == CMD_UTILITY);
509  Assert(queryString != NULL); /* required as of 8.4 */
510  Assert(qc == NULL || qc->commandTag == CMDTAG_UNKNOWN);
511 
512  /*
513  * We provide a function hook variable that lets loadable plugins get
514  * control when ProcessUtility is called. Such a plugin would normally
515  * call standard_ProcessUtility().
516  */
518  (*ProcessUtility_hook) (pstmt, queryString,
519  context, params, queryEnv,
520  dest, qc);
521  else
522  standard_ProcessUtility(pstmt, queryString,
523  context, params, queryEnv,
524  dest, qc);
525 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:577
ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:75
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:539
CmdType commandType
Definition: plannodes.h:46
CommandTag commandTag
Definition: cmdtag.h:30
#define Assert(condition)
Definition: c.h:738

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

Definition at line 1843 of file utility.c.

References PlannedStmt::canSetTag, CMD_UTILITY, PlannedStmt::commandType, EventTriggerAlterTableEnd(), EventTriggerAlterTableRelid(), EventTriggerAlterTableStart(), makeNode, None_Receiver, AlterTableUtilityContext::params, PROCESS_UTILITY_SUBCOMMAND, ProcessUtility(), AlterTableUtilityContext::pstmt, AlterTableUtilityContext::queryEnv, AlterTableUtilityContext::queryString, AlterTableUtilityContext::relid, PlannedStmt::stmt_len, PlannedStmt::stmt_location, and PlannedStmt::utilityStmt.

Referenced by ATParseTransformCmd(), and ATRewriteTables().

1844 {
1845  PlannedStmt *wrapper;
1846 
1847  /*
1848  * For event triggers, we must "close" the current complex-command set,
1849  * and start a new one afterwards; this is needed to ensure the ordering
1850  * of command events is consistent with the way they were executed.
1851  */
1853 
1854  /* Create a suitable wrapper */
1855  wrapper = makeNode(PlannedStmt);
1856  wrapper->commandType = CMD_UTILITY;
1857  wrapper->canSetTag = false;
1858  wrapper->utilityStmt = stmt;
1859  wrapper->stmt_location = context->pstmt->stmt_location;
1860  wrapper->stmt_len = context->pstmt->stmt_len;
1861 
1862  ProcessUtility(wrapper,
1863  context->queryString,
1865  context->params,
1866  context->queryEnv,
1867  None_Receiver,
1868  NULL);
1869 
1872 }
PlannedStmt * pstmt
Definition: utility.h:32
DestReceiver * None_Receiver
Definition: dest.c:96
int stmt_len
Definition: plannodes.h:96
void EventTriggerAlterTableStart(Node *parsetree)
int stmt_location
Definition: plannodes.h:95
Node * utilityStmt
Definition: plannodes.h:92
const char * queryString
Definition: utility.h:33
QueryEnvironment * queryEnv
Definition: utility.h:36
bool canSetTag
Definition: plannodes.h:54
CmdType commandType
Definition: plannodes.h:46
#define makeNode(_type_)
Definition: nodes.h:574
void EventTriggerAlterTableRelid(Oid objectId)
ParamListInfo params
Definition: utility.h:35
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:499
void EventTriggerAlterTableEnd(void)

◆ ProcessUtilitySlow()

static void ProcessUtilitySlow ( ParseState pstate,
PlannedStmt pstmt,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
QueryEnvironment queryEnv,
DestReceiver dest,
QueryCompletion qc 
)
static

Definition at line 1089 of file utility.c.

References AlterCollation(), AlterDomainAddConstraint(), AlterDomainDefault(), AlterDomainDropConstraint(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEnum(), AlterForeignDataWrapper(), AlterForeignServer(), AlterFunction(), AlterOperator(), AlterOpFamily(), AlterPolicy(), AlterPublication(), AlterSequence(), AlterStatistics(), AlterSubscription(), AlterTable(), AlterTableGetLockLevel(), AlterTableLookupRelation(), AlterTableMoveAll(), AlterTSConfiguration(), AlterTSDictionary(), AlterType(), AlterUserMapping(), DefineStmt::args, Assert, AlterDomainStmt::behavior, PlannedStmt::canSetTag, CMD_UTILITY, AlterTableStmt::cmds, CompositeTypeStmt::coldeflist, CommandCounterIncrement(), PlannedStmt::commandType, CommentObject(), IndexStmt::concurrent, CreateAccessMethod(), CreateCast(), CreateConversionCommand(), CreateExtension(), CreateForeignDataWrapper(), CreateForeignServer(), CreateForeignTable(), CreateFunction(), CreatePolicy(), CreateProceduralLanguage(), CreatePublication(), CreateSchemaCommand(), CreateStatistics(), CreateSubscription(), CreateTransform(), CreateTrigger(), CreateUserMapping(), AlterDomainStmt::def, DefineAggregate(), DefineCollation(), DefineCompositeType(), DefineDomain(), DefineEnum(), DefineIndex(), DefineOpClass(), DefineOperator(), DefineOpFamily(), DefineRange(), DefineRelation(), DefineRule(), DefineSequence(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), DefineType(), DefineView(), DefineStmt::definition, DefineStmt::defnames, DropOwnedObjects(), DropSubscription(), elog, ereport, errcode(), errdetail(), errmsg(), ERROR, EventTriggerAlterTableEnd(), EventTriggerAlterTableRelid(), EventTriggerAlterTableStart(), EventTriggerBeginCompleteQuery(), EventTriggerCollectAlterDefPrivs(), EventTriggerCollectSimpleCommand(), EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerEndCompleteQuery(), EventTriggerInhibitCommandCollection(), EventTriggerSQLDrop(), EventTriggerUndoInhibitCommandCollection(), ExecAlterDefaultPrivilegesStmt(), ExecAlterExtensionContentsStmt(), ExecAlterExtensionStmt(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecCreateTableAs(), ExecDropStmt(), ExecRefreshMatView(), ExecRenameStmt(), ExecSecLabelStmt(), ExecuteGrantStmt(), find_all_inheritors(), get_rel_relkind(), HEAP_RELOPT_NAMESPACES, heap_reloptions(), DefineStmt::if_not_exists, ImportForeignSchema(), RangeVar::inh, InvalidObjectAddress, InvalidOid, IsA, DefineStmt::kind, lfirst, lfirst_oid, list_free(), lnext(), makeNode, AlterDomainStmt::missing_ok, AlterDomainStmt::name, NewRelationCreateToastTable(), NIL, nodeTag, None_Receiver, NOTICE, OBJECT_AGGREGATE, OBJECT_COLLATION, OBJECT_OPERATOR, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, ObjectAddress::objectId, OidIsValid, DefineStmt::oldstyle, AlterTableUtilityContext::params, PG_END_TRY, PG_FINALLY, PG_TRY, PreventInTransactionBlock(), IndexStmt::primary, PROCESS_UTILITY_SUBCOMMAND, PROCESS_UTILITY_TOPLEVEL, ProcessUtility(), AlterTableUtilityContext::pstmt, AlterTableUtilityContext::queryEnv, AlterTableUtilityContext::queryString, RangeVarCallbackOwnsRelation(), RangeVarGetRelidExtended(), AlterTableStmt::relation, IndexStmt::relation, AlterTableUtilityContext::relid, RangeVar::relname, RemoveUserMapping(), DefineStmt::replace, ShareLock, ShareUpdateExclusiveLock, PlannedStmt::stmt_len, PlannedStmt::stmt_location, AlterDomainStmt::subtype, T_AlterCollationStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterSeqStmt, T_AlterStatsStmt, T_AlterSubscriptionStmt, T_AlterTableMoveAllStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterTypeStmt, T_AlterUserMappingStmt, T_CommentStmt, T_CompositeTypeStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DefineStmt, T_DropOwnedStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropUserMappingStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_RefreshMatViewStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_ViewStmt, transformCreateStmt(), transformIndexStmt(), transformRelOptions(), AlterDomainStmt::typeName, CompositeTypeStmt::typevar, IndexStmt::unique, and PlannedStmt::utilityStmt.

Referenced by standard_ProcessUtility().

1097 {
1098  Node *parsetree = pstmt->utilityStmt;
1099  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
1100  bool isCompleteQuery = (context != PROCESS_UTILITY_SUBCOMMAND);
1101  bool needCleanup;
1102  bool commandCollected = false;
1103  ObjectAddress address;
1104  ObjectAddress secondaryObject = InvalidObjectAddress;
1105 
1106  /* All event trigger calls are done only when isCompleteQuery is true */
1107  needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
1108 
1109  /* PG_TRY block is to ensure we call EventTriggerEndCompleteQuery */
1110  PG_TRY();
1111  {
1112  if (isCompleteQuery)
1113  EventTriggerDDLCommandStart(parsetree);
1114 
1115  switch (nodeTag(parsetree))
1116  {
1117  /*
1118  * relation and attribute manipulation
1119  */
1120  case T_CreateSchemaStmt:
1121  CreateSchemaCommand((CreateSchemaStmt *) parsetree,
1122  queryString,
1123  pstmt->stmt_location,
1124  pstmt->stmt_len);
1125 
1126  /*
1127  * EventTriggerCollectSimpleCommand called by
1128  * CreateSchemaCommand
1129  */
1130  commandCollected = true;
1131  break;
1132 
1133  case T_CreateStmt:
1135  {
1136  List *stmts;
1137  ListCell *l;
1138 
1139  /* Run parse analysis ... */
1140  stmts = transformCreateStmt((CreateStmt *) parsetree,
1141  queryString);
1142 
1143  /* ... and do it */
1144  foreach(l, stmts)
1145  {
1146  Node *stmt = (Node *) lfirst(l);
1147 
1148  if (IsA(stmt, CreateStmt))
1149  {
1150  Datum toast_options;
1151  static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
1152 
1153  /* Create the table itself */
1154  address = DefineRelation((CreateStmt *) stmt,
1155  RELKIND_RELATION,
1156  InvalidOid, NULL,
1157  queryString);
1159  secondaryObject,
1160  stmt);
1161 
1162  /*
1163  * Let NewRelationCreateToastTable decide if this
1164  * one needs a secondary relation too.
1165  */
1167 
1168  /*
1169  * parse and validate reloptions for the toast
1170  * table
1171  */
1172  toast_options = transformRelOptions((Datum) 0,
1173  ((CreateStmt *) stmt)->options,
1174  "toast",
1175  validnsps,
1176  true,
1177  false);
1178  (void) heap_reloptions(RELKIND_TOASTVALUE,
1179  toast_options,
1180  true);
1181 
1183  toast_options);
1184  }
1185  else if (IsA(stmt, CreateForeignTableStmt))
1186  {
1187  /* Create the table itself */
1188  address = DefineRelation((CreateStmt *) stmt,
1189  RELKIND_FOREIGN_TABLE,
1190  InvalidOid, NULL,
1191  queryString);
1193  address.objectId);
1195  secondaryObject,
1196  stmt);
1197  }
1198  else
1199  {
1200  /*
1201  * Recurse for anything else. Note the recursive
1202  * call will stash the objects so created into our
1203  * event trigger context.
1204  */
1205  PlannedStmt *wrapper;
1206 
1207  wrapper = makeNode(PlannedStmt);
1208  wrapper->commandType = CMD_UTILITY;
1209  wrapper->canSetTag = false;
1210  wrapper->utilityStmt = stmt;
1211  wrapper->stmt_location = pstmt->stmt_location;
1212  wrapper->stmt_len = pstmt->stmt_len;
1213 
1214  ProcessUtility(wrapper,
1215  queryString,
1217  params,
1218  NULL,
1219  None_Receiver,
1220  NULL);
1221  }
1222 
1223  /* Need CCI between commands */
1224  if (lnext(stmts, l) != NULL)
1226  }
1227 
1228  /*
1229  * The multiple commands generated here are stashed
1230  * individually, so disable collection below.
1231  */
1232  commandCollected = true;
1233  }
1234  break;
1235 
1236  case T_AlterTableStmt:
1237  {
1238  AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
1239  Oid relid;
1240  LOCKMODE lockmode;
1241 
1242  /*
1243  * Figure out lock mode, and acquire lock. This also does
1244  * basic permissions checks, so that we won't wait for a
1245  * lock on (for example) a relation on which we have no
1246  * permissions.
1247  */
1248  lockmode = AlterTableGetLockLevel(atstmt->cmds);
1249  relid = AlterTableLookupRelation(atstmt, lockmode);
1250 
1251  if (OidIsValid(relid))
1252  {
1253  AlterTableUtilityContext atcontext;
1254 
1255  /* Set up info needed for recursive callbacks ... */
1256  atcontext.pstmt = pstmt;
1257  atcontext.queryString = queryString;
1258  atcontext.relid = relid;
1259  atcontext.params = params;
1260  atcontext.queryEnv = queryEnv;
1261 
1262  /* ... ensure we have an event trigger context ... */
1263  EventTriggerAlterTableStart(parsetree);
1265 
1266  /* ... and do it */
1267  AlterTable(atstmt, lockmode, &atcontext);
1268 
1269  /* done */
1271  }
1272  else
1273  ereport(NOTICE,
1274  (errmsg("relation \"%s\" does not exist, skipping",
1275  atstmt->relation->relname)));
1276  }
1277 
1278  /* ALTER TABLE stashes commands internally */
1279  commandCollected = true;
1280  break;
1281 
1282  case T_AlterDomainStmt:
1283  {
1284  AlterDomainStmt *stmt = (AlterDomainStmt *) parsetree;
1285 
1286  /*
1287  * Some or all of these functions are recursive to cover
1288  * inherited things, so permission checks are done there.
1289  */
1290  switch (stmt->subtype)
1291  {
1292  case 'T': /* ALTER DOMAIN DEFAULT */
1293 
1294  /*
1295  * Recursively alter column default for table and,
1296  * if requested, for descendants
1297  */
1298  address =
1300  stmt->def);
1301  break;
1302  case 'N': /* ALTER DOMAIN DROP NOT NULL */
1303  address =
1305  false);
1306  break;
1307  case 'O': /* ALTER DOMAIN SET NOT NULL */
1308  address =
1310  true);
1311  break;
1312  case 'C': /* ADD CONSTRAINT */
1313  address =
1315  stmt->def,
1316  &secondaryObject);
1317  break;
1318  case 'X': /* DROP CONSTRAINT */
1319  address =
1321  stmt->name,
1322  stmt->behavior,
1323  stmt->missing_ok);
1324  break;
1325  case 'V': /* VALIDATE CONSTRAINT */
1326  address =
1328  stmt->name);
1329  break;
1330  default: /* oops */
1331  elog(ERROR, "unrecognized alter domain type: %d",
1332  (int) stmt->subtype);
1333  break;
1334  }
1335  }
1336  break;
1337 
1338  /*
1339  * ************* object creation / destruction **************
1340  */
1341  case T_DefineStmt:
1342  {
1343  DefineStmt *stmt = (DefineStmt *) parsetree;
1344 
1345  switch (stmt->kind)
1346  {
1347  case OBJECT_AGGREGATE:
1348  address =
1349  DefineAggregate(pstate, stmt->defnames, stmt->args,
1350  stmt->oldstyle,
1351  stmt->definition,
1352  stmt->replace);
1353  break;
1354  case OBJECT_OPERATOR:
1355  Assert(stmt->args == NIL);
1356  address = DefineOperator(stmt->defnames,
1357  stmt->definition);
1358  break;
1359  case OBJECT_TYPE:
1360  Assert(stmt->args == NIL);
1361  address = DefineType(pstate,
1362  stmt->defnames,
1363  stmt->definition);
1364  break;
1365  case OBJECT_TSPARSER:
1366  Assert(stmt->args == NIL);
1367  address = DefineTSParser(stmt->defnames,
1368  stmt->definition);
1369  break;
1370  case OBJECT_TSDICTIONARY:
1371  Assert(stmt->args == NIL);
1372  address = DefineTSDictionary(stmt->defnames,
1373  stmt->definition);
1374  break;
1375  case OBJECT_TSTEMPLATE:
1376  Assert(stmt->args == NIL);
1377  address = DefineTSTemplate(stmt->defnames,
1378  stmt->definition);
1379  break;
1381  Assert(stmt->args == NIL);
1382  address = DefineTSConfiguration(stmt->defnames,
1383  stmt->definition,
1384  &secondaryObject);
1385  break;
1386  case OBJECT_COLLATION:
1387  Assert(stmt->args == NIL);
1388  address = DefineCollation(pstate,
1389  stmt->defnames,
1390  stmt->definition,
1391  stmt->if_not_exists);
1392  break;
1393  default:
1394  elog(ERROR, "unrecognized define stmt type: %d",
1395  (int) stmt->kind);
1396  break;
1397  }
1398  }
1399  break;
1400 
1401  case T_IndexStmt: /* CREATE INDEX */
1402  {
1403  IndexStmt *stmt = (IndexStmt *) parsetree;
1404  Oid relid;
1405  LOCKMODE lockmode;
1406 
1407  if (stmt->concurrent)
1408  PreventInTransactionBlock(isTopLevel,
1409  "CREATE INDEX CONCURRENTLY");
1410 
1411  /*
1412  * Look up the relation OID just once, right here at the
1413  * beginning, so that we don't end up repeating the name
1414  * lookup later and latching onto a different relation
1415  * partway through. To avoid lock upgrade hazards, it's
1416  * important that we take the strongest lock that will
1417  * eventually be needed here, so the lockmode calculation
1418  * needs to match what DefineIndex() does.
1419  */
1420  lockmode = stmt->concurrent ? ShareUpdateExclusiveLock
1421  : ShareLock;
1422  relid =
1423  RangeVarGetRelidExtended(stmt->relation, lockmode,
1424  0,
1426  NULL);
1427 
1428  /*
1429  * CREATE INDEX on partitioned tables (but not regular
1430  * inherited tables) recurses to partitions, so we must
1431  * acquire locks early to avoid deadlocks.
1432  *
1433  * We also take the opportunity to verify that all
1434  * partitions are something we can put an index on, to
1435  * avoid building some indexes only to fail later.
1436  */
1437  if (stmt->relation->inh &&
1438  get_rel_relkind(relid) == RELKIND_PARTITIONED_TABLE)
1439  {
1440  ListCell *lc;
1441  List *inheritors = NIL;
1442 
1443  inheritors = find_all_inheritors(relid, lockmode, NULL);
1444  foreach(lc, inheritors)
1445  {
1446  char relkind = get_rel_relkind(lfirst_oid(lc));
1447 
1448  if (relkind != RELKIND_RELATION &&
1449  relkind != RELKIND_MATVIEW &&
1450  relkind != RELKIND_PARTITIONED_TABLE &&
1451  relkind != RELKIND_FOREIGN_TABLE)
1452  elog(ERROR, "unexpected relkind \"%c\" on partition \"%s\"",
1453  relkind, stmt->relation->relname);
1454 
1455  if (relkind == RELKIND_FOREIGN_TABLE &&
1456  (stmt->unique || stmt->primary))
1457  ereport(ERROR,
1458  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1459  errmsg("cannot create unique index on partitioned table \"%s\"",
1460  stmt->relation->relname),
1461  errdetail("Table \"%s\" contains partitions that are foreign tables.",
1462  stmt->relation->relname)));
1463  }
1464  list_free(inheritors);
1465  }
1466 
1467  /* Run parse analysis ... */
1468  stmt = transformIndexStmt(relid, stmt, queryString);
1469 
1470  /* ... and do it */
1471  EventTriggerAlterTableStart(parsetree);
1472  address =
1473  DefineIndex(relid, /* OID of heap relation */
1474  stmt,
1475  InvalidOid, /* no predefined OID */
1476  InvalidOid, /* no parent index */
1477  InvalidOid, /* no parent constraint */
1478  false, /* is_alter_table */
1479  true, /* check_rights */
1480  true, /* check_not_in_use */
1481  false, /* skip_build */
1482  false); /* quiet */
1483 
1484  /*
1485  * Add the CREATE INDEX node itself to stash right away;
1486  * if there were any commands stashed in the ALTER TABLE
1487  * code, we need them to appear after this one.
1488  */
1489  EventTriggerCollectSimpleCommand(address, secondaryObject,
1490  parsetree);
1491  commandCollected = true;
1493  }
1494  break;
1495 
1496  case T_CreateExtensionStmt:
1497  address = CreateExtension(pstate, (CreateExtensionStmt *) parsetree);
1498  break;
1499 
1500  case T_AlterExtensionStmt:
1501  address = ExecAlterExtensionStmt(pstate, (AlterExtensionStmt *) parsetree);
1502  break;
1503 
1506  &secondaryObject);
1507  break;
1508 
1509  case T_CreateFdwStmt:
1510  address = CreateForeignDataWrapper((CreateFdwStmt *) parsetree);
1511  break;
1512 
1513  case T_AlterFdwStmt:
1514  address = AlterForeignDataWrapper((AlterFdwStmt *) parsetree);
1515  break;
1516 
1518  address = CreateForeignServer((CreateForeignServerStmt *) parsetree);
1519  break;
1520 
1522  address = AlterForeignServer((AlterForeignServerStmt *) parsetree);
1523  break;
1524 
1526  address = CreateUserMapping((CreateUserMappingStmt *) parsetree);
1527  break;
1528 
1530  address = AlterUserMapping((AlterUserMappingStmt *) parsetree);
1531  break;
1532 
1533  case T_DropUserMappingStmt:
1534  RemoveUserMapping((DropUserMappingStmt *) parsetree);
1535  /* no commands stashed for DROP */
1536  commandCollected = true;
1537  break;
1538 
1541  /* commands are stashed inside ImportForeignSchema */
1542  commandCollected = true;
1543  break;
1544 
1545  case T_CompositeTypeStmt: /* CREATE TYPE (composite) */
1546  {
1547  CompositeTypeStmt *stmt = (CompositeTypeStmt *) parsetree;
1548 
1549  address = DefineCompositeType(stmt->typevar,
1550  stmt->coldeflist);
1551  }
1552  break;
1553 
1554  case T_CreateEnumStmt: /* CREATE TYPE AS ENUM */
1555  address = DefineEnum((CreateEnumStmt *) parsetree);
1556  break;
1557 
1558  case T_CreateRangeStmt: /* CREATE TYPE AS RANGE */
1559  address = DefineRange((CreateRangeStmt *) parsetree);
1560  break;
1561 
1562  case T_AlterEnumStmt: /* ALTER TYPE (enum) */
1563  address = AlterEnum((AlterEnumStmt *) parsetree);
1564  break;
1565 
1566  case T_ViewStmt: /* CREATE VIEW */
1567  EventTriggerAlterTableStart(parsetree);
1568  address = DefineView((ViewStmt *) parsetree, queryString,
1569  pstmt->stmt_location, pstmt->stmt_len);
1570  EventTriggerCollectSimpleCommand(address, secondaryObject,
1571  parsetree);
1572  /* stashed internally */
1573  commandCollected = true;
1575  break;
1576 
1577  case T_CreateFunctionStmt: /* CREATE FUNCTION */
1578  address = CreateFunction(pstate, (CreateFunctionStmt *) parsetree);
1579  break;
1580 
1581  case T_AlterFunctionStmt: /* ALTER FUNCTION */
1582  address = AlterFunction(pstate, (AlterFunctionStmt *) parsetree);
1583  break;
1584 
1585  case T_RuleStmt: /* CREATE RULE */
1586  address = DefineRule((RuleStmt *) parsetree, queryString);
1587  break;
1588 
1589  case T_CreateSeqStmt:
1590  address = DefineSequence(pstate, (CreateSeqStmt *) parsetree);
1591  break;
1592 
1593  case T_AlterSeqStmt:
1594  address = AlterSequence(pstate, (AlterSeqStmt *) parsetree);
1595  break;
1596 
1597  case T_CreateTableAsStmt:
1598  address = ExecCreateTableAs(pstate, (CreateTableAsStmt *) parsetree,
1599  params, queryEnv, qc);
1600  break;
1601 
1602  case T_RefreshMatViewStmt:
1603 
1604  /*
1605  * REFRESH CONCURRENTLY executes some DDL commands internally.
1606  * Inhibit DDL command collection here to avoid those commands
1607  * from showing up in the deparsed command queue. The refresh
1608  * command itself is queued, which is enough.
1609  */
1611  PG_TRY();
1612  {
1613  address = ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
1614  queryString, params, qc);
1615  }
1616  PG_FINALLY();
1617  {
1619  }
1620  PG_END_TRY();
1621  break;
1622 
1623  case T_CreateTrigStmt:
1624  address = CreateTrigger((CreateTrigStmt *) parsetree,
1625  queryString, InvalidOid, InvalidOid,
1627  InvalidOid, NULL, false, false);
1628  break;
1629 
1630  case T_CreatePLangStmt:
1631  address = CreateProceduralLanguage((CreatePLangStmt *) parsetree);
1632  break;
1633 
1634  case T_CreateDomainStmt:
1635  address = DefineDomain((CreateDomainStmt *) parsetree);
1636  break;
1637 
1639  address = CreateConversionCommand((CreateConversionStmt *) parsetree);
1640  break;
1641 
1642  case T_CreateCastStmt:
1643  address = CreateCast((CreateCastStmt *) parsetree);
1644  break;
1645 
1646  case T_CreateOpClassStmt:
1647  DefineOpClass((CreateOpClassStmt *) parsetree);
1648  /* command is stashed in DefineOpClass */
1649  commandCollected = true;
1650  break;
1651 
1652  case T_CreateOpFamilyStmt:
1653  address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1654  break;
1655 
1656  case T_CreateTransformStmt:
1657  address = CreateTransform((CreateTransformStmt *) parsetree);
1658  break;
1659 
1660  case T_AlterOpFamilyStmt:
1661  AlterOpFamily((AlterOpFamilyStmt *) parsetree);
1662  /* commands are stashed in AlterOpFamily */
1663  commandCollected = true;
1664  break;
1665 
1667  address = AlterTSDictionary((AlterTSDictionaryStmt *) parsetree);
1668  break;
1669 
1672 
1673  /*
1674  * Commands are stashed in MakeConfigurationMapping and
1675  * DropConfigurationMapping, which are called from
1676  * AlterTSConfiguration
1677  */
1678  commandCollected = true;
1679  break;
1680 
1683  /* commands are stashed in AlterTableMoveAll */
1684  commandCollected = true;
1685  break;
1686 
1687  case T_DropStmt:
1688  ExecDropStmt((DropStmt *) parsetree, isTopLevel);
1689  /* no commands stashed for DROP */
1690  commandCollected = true;
1691  break;
1692 
1693  case T_RenameStmt:
1694  address = ExecRenameStmt((RenameStmt *) parsetree);
1695  break;
1696 
1698  address =
1700  &secondaryObject);
1701  break;
1702 
1704  address =
1706  &secondaryObject);
1707  break;
1708 
1709  case T_AlterOwnerStmt:
1710  address = ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
1711  break;
1712 
1713  case T_AlterOperatorStmt:
1714  address = AlterOperator((AlterOperatorStmt *) parsetree);
1715  break;
1716 
1717  case T_AlterTypeStmt:
1718  address = AlterType((AlterTypeStmt *) parsetree);
1719  break;
1720 
1721  case T_CommentStmt:
1722  address = CommentObject((CommentStmt *) parsetree);
1723  break;
1724 
1725  case T_GrantStmt:
1726  ExecuteGrantStmt((GrantStmt *) parsetree);
1727  /* commands are stashed in ExecGrantStmt_oids */
1728  commandCollected = true;
1729  break;
1730 
1731  case T_DropOwnedStmt:
1732  DropOwnedObjects((DropOwnedStmt *) parsetree);
1733  /* no commands stashed for DROP */
1734  commandCollected = true;
1735  break;
1736 
1740  commandCollected = true;
1741  break;
1742 
1743  case T_CreatePolicyStmt: /* CREATE POLICY */
1744  address = CreatePolicy((CreatePolicyStmt *) parsetree);
1745  break;
1746 
1747  case T_AlterPolicyStmt: /* ALTER POLICY */
1748  address = AlterPolicy((AlterPolicyStmt *) parsetree);
1749  break;
1750 
1751  case T_SecLabelStmt:
1752  address = ExecSecLabelStmt((SecLabelStmt *) parsetree);
1753  break;
1754 
1755  case T_CreateAmStmt:
1756  address = CreateAccessMethod((CreateAmStmt *) parsetree);
1757  break;
1758 
1760  address = CreatePublication((CreatePublicationStmt *) parsetree);
1761  break;
1762 
1764  AlterPublication((AlterPublicationStmt *) parsetree);
1765 
1766  /*
1767  * AlterPublication calls EventTriggerCollectSimpleCommand
1768  * directly
1769  */
1770  commandCollected = true;
1771  break;
1772 
1774  address = CreateSubscription((CreateSubscriptionStmt *) parsetree,
1775  isTopLevel);
1776  break;
1777 
1779  address = AlterSubscription((AlterSubscriptionStmt *) parsetree);
1780  break;
1781 
1783  DropSubscription((DropSubscriptionStmt *) parsetree, isTopLevel);
1784  /* no commands stashed for DROP */
1785  commandCollected = true;
1786  break;
1787 
1788  case T_CreateStatsStmt:
1789  address = CreateStatistics((CreateStatsStmt *) parsetree);
1790  break;
1791 
1792  case T_AlterStatsStmt:
1793  address = AlterStatistics((AlterStatsStmt *) parsetree);
1794  break;
1795 
1796  case T_AlterCollationStmt:
1797  address = AlterCollation((AlterCollationStmt *) parsetree);
1798  break;
1799 
1800  default:
1801  elog(ERROR, "unrecognized node type: %d",
1802  (int) nodeTag(parsetree));
1803  break;
1804  }
1805 
1806  /*
1807  * Remember the object so that ddl_command_end event triggers have
1808  * access to it.
1809  */
1810  if (!commandCollected)
1811  EventTriggerCollectSimpleCommand(address, secondaryObject,
1812  parsetree);
1813 
1814  if (isCompleteQuery)
1815  {
1816  EventTriggerSQLDrop(parsetree);
1817  EventTriggerDDLCommandEnd(parsetree);
1818  }
1819  }
1820  PG_FINALLY();
1821  {
1822  if (needCleanup)
1824  }
1825  PG_END_TRY();
1826 }
ObjectAddress AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
Definition: sequence.c:422
ObjectAddress DefineTSParser(List *names, List *parameters)
Definition: tsearchcmds.c:179
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1996
#define NIL
Definition: pg_list.h:65
bool primary
Definition: parsenodes.h:2787
ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt)
Definition: foreigncmds.c:993
void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid)
Definition: foreigncmds.c:1463
void DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
ObjectAddress DefineOperator(List *names, List *parameters)
Definition: operatorcmds.c:65
ObjectAddress AlterSubscription(AlterSubscriptionStmt *stmt)
#define IsA(nodeptr, _type_)
Definition: nodes.h:577
ObjectAddress DefineTSConfiguration(List *names, List *parameters, ObjectAddress *copied)
Definition: tsearchcmds.c:966
ObjectAddress CreateTransform(CreateTransformStmt *stmt)
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1878
ObjectAddress DefineIndex(Oid relationId, IndexStmt *stmt, Oid indexRelationId, Oid parentIndexId, Oid parentConstraintId, bool is_alter_table, bool check_rights, bool check_not_in_use, bool skip_build, bool quiet)
Definition: indexcmds.c:479
ObjectAddress AlterDomainAddConstraint(List *names, Node *newConstraint, ObjectAddress *constrAddr)
Definition: typecmds.c:2471
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool acceptOidsOff, bool isReset)
Definition: reloptions.c:1132
ObjectAddress CreateForeignDataWrapper(CreateFdwStmt *stmt)
Definition: foreigncmds.c:562
DropBehavior behavior
Definition: parsenodes.h:1906
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
Definition: functioncmds.c:922
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:321
int LOCKMODE
Definition: lockdefs.h:26
ObjectAddress CreatePublication(CreatePublicationStmt *stmt)
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:44
PlannedStmt * pstmt
Definition: utility.h:32
Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
Definition: tablecmds.c:3507
ObjectAddress AlterDomainValidateConstraint(List *names, const char *constrName)
Definition: typecmds.c:2587
ObjectAddress DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List *parameters, bool replace)
Definition: aggregatecmds.c:57
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1866
ObjectAddress AlterEnum(AlterEnumStmt *stmt)
Definition: typecmds.c:1214
void DropOwnedObjects(DropOwnedStmt *stmt)
Definition: user.c:1360
RangeVar * typevar
Definition: parsenodes.h:3067
void EventTriggerDDLCommandEnd(Node *parsetree)
Definition: nodes.h:526
ObjectAddress ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt, ObjectAddress *objAddr)
Definition: extension.c:3264
int errcode(int sqlerrcode)
Definition: elog.c:610
ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt)
Definition: proclang.c:39
void EventTriggerInhibitCommandCollection(void)
ObjectAddress DefineDomain(CreateDomainStmt *stmt)
Definition: typecmds.c:657
ObjectAddress DefineCompositeType(RangeVar *typevar, List *coldeflist)
Definition: typecmds.c:2063
unsigned int Oid
Definition: postgres_ext.h:31
ObjectAddress DefineOpClass(CreateOpClassStmt *stmt)
Definition: opclasscmds.c:331
DestReceiver * None_Receiver
Definition: dest.c:96
ObjectAddress CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
void NewRelationCreateToastTable(Oid relOid, Datum reloptions)
Definition: toasting.c:72
#define OidIsValid(objectId)
Definition: c.h:644
int stmt_len
Definition: plannodes.h:96
void EventTriggerAlterTableStart(Node *parsetree)
char * relname
Definition: primnodes.h:68
void AlterTable(AlterTableStmt *stmt, LOCKMODE lockmode, AlterTableUtilityContext *context)
Definition: tablecmds.c:3563
RangeVar * relation
Definition: parsenodes.h:2774
ObjectAddress AlterPolicy(AlterPolicyStmt *stmt)
Definition: policy.c:890
ObjectAddress AlterStatistics(AlterStatsStmt *stmt)
Definition: statscmds.c:425
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
Definition: tablecmds.c:15369
List * args
Definition: parsenodes.h:2569
#define ERROR
Definition: elog.h:43
ObjectAddress AlterDomainDefault(List *names, Node *defaultRaw)
Definition: typecmds.c:2121
ObjectAddress AlterOperator(AlterOperatorStmt *stmt)
Definition: operatorcmds.c:385
void EventTriggerDDLCommandStart(Node *parsetree)
ObjectAddress CreatePolicy(CreatePolicyStmt *stmt)
Definition: policy.c:690
void EventTriggerSQLDrop(Node *parsetree)
ObjectAddress AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
Definition: tsearchcmds.c:1182
ObjectAddress AlterType(AlterTypeStmt *stmt)
Definition: typecmds.c:3653
ObjectAddress AlterDomainNotNull(List *names, bool notNull)
Definition: typecmds.c:2252
Oid RemoveUserMapping(DropUserMappingStmt *stmt)
Definition: foreigncmds.c:1360
ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt)
Definition: foreigncmds.c:1143
int stmt_location
Definition: plannodes.h:95
ObjectAddress AlterTSDictionary(AlterTSDictionaryStmt *stmt)
Definition: tsearchcmds.c:535
int errdetail(const char *fmt,...)
Definition: elog.c:957
Node * utilityStmt
Definition: plannodes.h:92
ObjectAddress DefineRange(CreateRangeStmt *stmt)
Definition: typecmds.c:1284
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3331
const char * queryString
Definition: utility.h:33
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:236
ObjectAddress DefineEnum(CreateEnumStmt *stmt)
Definition: typecmds.c:1092
ObjectAddress DefineView(ViewStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: view.c:407
Oid CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: schemacmds.c:50
#define HEAP_RELOPT_NAMESPACES
Definition: reloptions.h:61
ObjectAddress AlterUserMapping(AlterUserMappingStmt *stmt)
Definition: foreigncmds.c:1265
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition: alter.c:331
ObjectAddress DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
Definition: sequence.c:118
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
Definition: tablecmds.c:579
QueryEnvironment * queryEnv
Definition: utility.h:36
void ExecAlterDefaultPrivilegesStmt(ParseState *pstate, AlterDefaultPrivilegesStmt *stmt)
Definition: aclchk.c:913
ObjectAddress DefineType(ParseState *pstate, List *names, List *parameters)
Definition: typecmds.c:139
bool inh
Definition: primnodes.h:69
ObjectAddress CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt)
Definition: extension.c:1667
void EventTriggerEndCompleteQuery(void)
LOCKMODE AlterTableGetLockLevel(List *cmds)
Definition: tablecmds.c:3637
ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt)
Definition: foreigncmds.c:866
bool replace
Definition: parsenodes.h:2572
#define PG_FINALLY()
Definition: elog.h:312
bool canSetTag
Definition: plannodes.h:54
void EventTriggerUndoInhibitCommandCollection(void)
uintptr_t Datum
Definition: postgres.h:367
CmdType commandType
Definition: plannodes.h:46
void CommandCounterIncrement(void)
Definition: xact.c:1005
bool unique
Definition: parsenodes.h:2786
ObjectType kind
Definition: parsenodes.h:2566
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:431
void EventTriggerCollectAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt)
#define InvalidOid
Definition: postgres_ext.h:36
ObjectAddress DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_exists)
Definition: collationcmds.c:52
List * defnames
Definition: parsenodes.h:2568
#define ereport(elevel,...)
Definition: elog.h:144
#define NOTICE
Definition: elog.h:37
ObjectAddress CreateCast(CreateCastStmt *stmt)
ObjectAddress ExecAlterExtensionStmt(ParseState *pstate, AlterExtensionStmt *stmt)
Definition: extension.c:2956
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:485
#define makeNode(_type_)
Definition: nodes.h:574
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
ObjectAddress DefineTSDictionary(List *names, List *parameters)
Definition: tsearchcmds.c:415
#define Assert(condition)
Definition: c.h:738
#define lfirst(lc)
Definition: pg_list.h:190
ObjectAddress ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, ParamListInfo params, QueryCompletion *qc)
Definition: matview.c:138
ObjectAddress CreateConversionCommand(CreateConversionStmt *stmt)
Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
Definition: tablecmds.c:13082
ObjectAddress AlterForeignDataWrapper(AlterFdwStmt *stmt)
Definition: foreigncmds.c:678
List * transformCreateStmt(CreateStmt *stmt, const char *queryString)
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition: alter.c:823
ObjectAddress ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, ParamListInfo params, QueryEnvironment *queryEnv, QueryCompletion *qc)
Definition: createas.c:226
#define nodeTag(nodeptr)
Definition: nodes.h:531
void EventTriggerAlterTableRelid(Oid objectId)
Oid AlterOpFamily(AlterOpFamilyStmt *stmt)
Definition: opclasscmds.c:777
ObjectAddress DefineOpFamily(CreateOpFamilyStmt *stmt)
Definition: opclasscmds.c:732
ObjectAddress AlterDomainDropConstraint(List *names, const char *constrName, DropBehavior behavior, bool missing_ok)
Definition: typecmds.c:2372
bool concurrent
Definition: parsenodes.h:2792
ObjectAddress DefineRule(RuleStmt *stmt, const char *queryString)
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
Definition: pg_inherits.c:165
const ObjectAddress InvalidObjectAddress
void ImportForeignSchema(ImportForeignSchemaStmt *stmt)
Definition: foreigncmds.c:1543
int errmsg(const char *fmt,...)
Definition: elog.c:824
RangeVar * relation
Definition: parsenodes.h:1775
void list_free(List *list)
Definition: list.c:1377
#define elog(elevel,...)
Definition: elog.h:214
ObjectAddress AlterCollation(AlterCollationStmt *stmt)
#define ShareLock
Definition: lockdefs.h:41
ObjectAddress DefineTSTemplate(List *names, List *parameters)
Definition: tsearchcmds.c:733
bool if_not_exists
Definition: parsenodes.h:2571
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:157
ObjectAddress CreateAccessMethod(CreateAmStmt *stmt)
Definition: amcmds.c:42
List * definition
Definition: parsenodes.h:2570
void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
#define PG_TRY()
Definition: elog.h:295
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
Definition: pg_list.h:50
ObjectAddress AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt)
ParamListInfo params
Definition: utility.h:35
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
Definition: utility.c:499
bool oldstyle
Definition: parsenodes.h:2567
#define PG_END_TRY()
Definition: elog.h:320
#define lfirst_oid(lc)
Definition: pg_list.h:192
void AlterPublication(AlterPublicationStmt *stmt)
bool EventTriggerBeginCompleteQuery(void)
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:384
void EventTriggerAlterTableEnd(void)
ObjectAddress CreateStatistics(CreateStatsStmt *stmt)
Definition: statscmds.c:62

◆ standard_ProcessUtility()

void standard_ProcessUtility ( PlannedStmt pstmt,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
QueryEnvironment queryEnv,
DestReceiver dest,
QueryCompletion qc 
)

Definition at line 539 of file utility.c.

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterSystemSetConfigFile(), AlterTableSpaceOptions(), DefElem::arg, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), BeginTransactionBlock(), castNode, TransactionStmt::chain, check_stack_depth(), CHECKPOINT_FORCE, CHECKPOINT_IMMEDIATE, CHECKPOINT_WAIT, CheckRestrictedOperation(), ClassifyUtilityCommandAsReadOnly(), closeAllVfds(), cluster(), COMMAND_IS_STRICTLY_READ_ONLY, COMMAND_OK_IN_PARALLEL_MODE, COMMAND_OK_IN_READ_ONLY_TXN, COMMAND_OK_IN_RECOVERY, CommandCounterIncrement(), CommentObject(), ReindexStmt::concurrent, NotifyStmt::conditionname, ListenStmt::conditionname, UnlistenStmt::conditionname, CreateCommandTag(), createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DeallocateQuery(), DefineSavepoint(), DefElem::defname, DiscardCommand(), DoCopy(), DropDatabase(), DropRole(), DropTableSpace(), elog, EndTransactionBlock(), ereport, errcode(), errmsg(), ERROR, EventTriggerSupportsObjectType(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteCallStmt(), ExecuteDoStmt(), ExecuteGrantStmt(), ExecuteQuery(), ExecuteTruncate(), ExecVacuum(), ExplainQuery(), LoadStmt::filename, FinishPreparedTransaction(), free_parsestate(), GetCommandTagName(), GetPGVariable(), TransactionStmt::gid, GrantRole(), IsInParallelMode(), IsTransactionBlock(), TransactionStmt::kind, ReindexStmt::kind, lfirst, list_make1, load_file(), LockTableCommand(), make_parsestate(), VariableShowStmt::name, ReindexStmt::name, nodeTag, AlterObjectDependsStmt::objectType, AlterObjectSchemaStmt::objectType, AlterOwnerStmt::objectType, GrantStmt::objtype, CommentStmt::objtype, SecLabelStmt::objtype, TransactionStmt::options, ReindexStmt::options, ParseState::p_queryEnv, ParseState::p_sourcetext, NotifyStmt::payload, PerformCursorOpen(), PerformPortalClose(), PerformPortalFetch(), ClosePortalStmt::portalname, PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventCommandIfParallelMode(), PreventCommandIfReadOnly(), PreventInTransactionBlock(), PROCESS_UTILITY_QUERY_NONATOMIC, PROCESS_UTILITY_TOPLEVEL, ProcessUtilitySlow(), ReassignOwnedObjects(), RecoveryInProgress(), REINDEX_OBJECT_DATABASE, REINDEX_OBJECT_INDEX, REINDEX_OBJECT_SCHEMA, REINDEX_OBJECT_SYSTEM, REINDEX_OBJECT_TABLE, ReindexIndex(), ReindexMultipleTables(), ReindexTable(), ReindexStmt::relation, ReleaseSavepoint(), DropStmt::removeType, RenameStmt::renameType, RequestCheckpoint(), RequireTransactionBlock(), RollbackToSavepoint(), TransactionStmt::savepoint_name, SetPGVariable(), SetQueryCompletion(), PlannedStmt::stmt_len, PlannedStmt::stmt_location, superuser(), T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterEventTrigStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOwnerStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSystemStmt, T_AlterTableSpaceOptionsStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreatedbStmt, T_CreateEventTrigStmt, T_CreateRoleStmt, T_CreateTableSpaceStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropRoleStmt, T_DropStmt, T_DropTableSpaceStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PrepareStmt, T_ReassignOwnedStmt, T_ReindexStmt, T_RenameStmt, T_SecLabelStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, UserAbortTransactionBlock(), PlannedStmt::utilityStmt, WarnNoTransactionBlock(), and XactReadOnly.

Referenced by pgss_ProcessUtility(), ProcessUtility(), and sepgsql_utility_command().

546 {
547  Node *parsetree = pstmt->utilityStmt;
548  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
549  bool isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
550  ParseState *pstate;
551  int readonly_flags;
552 
553  /* This can recurse, so check for excessive recursion */
555 
556  /* Prohibit read/write commands in read-only states. */
557  readonly_flags = ClassifyUtilityCommandAsReadOnly(parsetree);
558  if (readonly_flags != COMMAND_IS_STRICTLY_READ_ONLY &&
560  {
561  CommandTag commandtag = CreateCommandTag(parsetree);
562 
563  if ((readonly_flags & COMMAND_OK_IN_READ_ONLY_TXN) == 0)
565  if ((readonly_flags & COMMAND_OK_IN_PARALLEL_MODE) == 0)
567  if ((readonly_flags & COMMAND_OK_IN_RECOVERY) == 0)
569  }
570 
571  pstate = make_parsestate(NULL);
572  pstate->p_sourcetext = queryString;
573  pstate->p_queryEnv = queryEnv;
574 
575  switch (nodeTag(parsetree))
576  {
577  /*
578  * ******************** transactions ********************
579  */
580  case T_TransactionStmt:
581  {
582  TransactionStmt *stmt = (TransactionStmt *) parsetree;
583 
584  switch (stmt->kind)
585  {
586  /*
587  * START TRANSACTION, as defined by SQL99: Identical
588  * to BEGIN. Same code for both.
589  */
590  case TRANS_STMT_BEGIN:
591  case TRANS_STMT_START:
592  {
593  ListCell *lc;
594 
596  foreach(lc, stmt->options)
597  {
598  DefElem *item = (DefElem *) lfirst(lc);
599 
600  if (strcmp(item->defname, "transaction_isolation") == 0)
601  SetPGVariable("transaction_isolation",
602  list_make1(item->arg),
603  true);
604  else if (strcmp(item->defname, "transaction_read_only") == 0)
605  SetPGVariable("transaction_read_only",
606  list_make1(item->arg),
607  true);
608  else if (strcmp(item->defname, "transaction_deferrable") == 0)
609  SetPGVariable("transaction_deferrable",
610  list_make1(item->arg),
611  true);
612  }
613  }
614  break;
615 
616  case TRANS_STMT_COMMIT:
617  if (!EndTransactionBlock(stmt->chain))
618  {
619  /* report unsuccessful commit in qc */
620  if (qc)
621  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
622  }
623  break;
624 
625  case TRANS_STMT_PREPARE:
626  if (!PrepareTransactionBlock(stmt->gid))
627  {
628  /* report unsuccessful commit in qc */
629  if (qc)
630  SetQueryCompletion(qc, CMDTAG_ROLLBACK, 0);
631  }
632  break;
633 
635  PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
636  FinishPreparedTransaction(stmt->gid, true);
637  break;
638 
640  PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
641  FinishPreparedTransaction(stmt->gid, false);
642  break;
643 
644  case TRANS_STMT_ROLLBACK:
646  break;
647 
649  RequireTransactionBlock(isTopLevel, "SAVEPOINT");
651  break;
652 
653  case TRANS_STMT_RELEASE:
654  RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
656  break;
657 
659  RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
661 
662  /*
663  * CommitTransactionCommand is in charge of
664  * re-defining the savepoint again
665  */
666  break;
667  }
668  }
669  break;
670 
671  /*
672  * Portal (cursor) manipulation
673  */
674  case T_DeclareCursorStmt:
675  PerformCursorOpen(pstate, (DeclareCursorStmt *) parsetree, params,
676  isTopLevel);
677  break;
678 
679  case T_ClosePortalStmt:
680  {
681  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
682 
683  CheckRestrictedOperation("CLOSE");
685  }
686  break;
687 
688  case T_FetchStmt:
689  PerformPortalFetch((FetchStmt *) parsetree, dest, qc);
690  break;
691 
692  case T_DoStmt:
693  ExecuteDoStmt((DoStmt *) parsetree, isAtomicContext);
694  break;
695 
697  /* no event triggers for global objects */
698  PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
699  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
700  break;
701 
703  /* no event triggers for global objects */
704  PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
705  DropTableSpace((DropTableSpaceStmt *) parsetree);
706  break;
707 
709  /* no event triggers for global objects */
711  break;
712 
713  case T_TruncateStmt:
714  ExecuteTruncate((TruncateStmt *) parsetree);
715  break;
716 
717  case T_CopyStmt:
718  {
719  uint64 processed;
720 
721  DoCopy(pstate, (CopyStmt *) parsetree,
722  pstmt->stmt_location, pstmt->stmt_len,
723  &processed);
724  if (qc)
725  SetQueryCompletion(qc, CMDTAG_COPY, processed);
726  }
727  break;
728 
729  case T_PrepareStmt:
730  CheckRestrictedOperation("PREPARE");
731  PrepareQuery(pstate, (PrepareStmt *) parsetree,
732  pstmt->stmt_location, pstmt->stmt_len);
733  break;
734 
735  case T_ExecuteStmt:
736  ExecuteQuery(pstate,
737  (ExecuteStmt *) parsetree, NULL,
738  params,
739  dest, qc);
740  break;
741 
742  case T_DeallocateStmt:
743  CheckRestrictedOperation("DEALLOCATE");
744  DeallocateQuery((DeallocateStmt *) parsetree);
745  break;
746 
747  case T_GrantRoleStmt:
748  /* no event triggers for global objects */
749  GrantRole((GrantRoleStmt *) parsetree);
750  break;
751 
752  case T_CreatedbStmt:
753  /* no event triggers for global objects */
754  PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
755  createdb(pstate, (CreatedbStmt *) parsetree);
756  break;
757 
758  case T_AlterDatabaseStmt:
759  /* no event triggers for global objects */
760  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
761  break;
762 
764  /* no event triggers for global objects */
765  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
766  break;
767 
768  case T_DropdbStmt:
769  /* no event triggers for global objects */
770  PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
771  DropDatabase(pstate, (DropdbStmt *) parsetree);
772  break;
773 
774  /* Query-level asynchronous notification */
775  case T_NotifyStmt:
776  {
777  NotifyStmt *stmt = (NotifyStmt *) parsetree;
778 
779  Async_Notify(stmt->conditionname, stmt->payload);
780  }
781  break;
782 
783  case T_ListenStmt:
784  {
785  ListenStmt *stmt = (ListenStmt *) parsetree;
786 
787  CheckRestrictedOperation("LISTEN");
789  }
790  break;
791 
792  case T_UnlistenStmt:
793  {
794  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
795 
796  CheckRestrictedOperation("UNLISTEN");
797  if (stmt->conditionname)
799  else
801  }
802  break;
803 
804  case T_LoadStmt:
805  {
806  LoadStmt *stmt = (LoadStmt *) parsetree;
807 
808  closeAllVfds(); /* probably not necessary... */
809  /* Allowed names are restricted if you're not superuser */
810  load_file(stmt->filename, !superuser());
811  }
812  break;
813 
814  case T_CallStmt:
815  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
816  break;
817 
818  case T_ClusterStmt:
819  cluster((ClusterStmt *) parsetree, isTopLevel);
820  break;
821 
822  case T_VacuumStmt:
823  ExecVacuum(pstate, (VacuumStmt *) parsetree, isTopLevel);
824  break;
825 
826  case T_ExplainStmt:
827  ExplainQuery(pstate, (ExplainStmt *) parsetree, params, dest);
828  break;
829 
830  case T_AlterSystemStmt:
831  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
833  break;
834 
835  case T_VariableSetStmt:
836  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
837  break;
838 
839  case T_VariableShowStmt:
840  {
841  VariableShowStmt *n = (VariableShowStmt *) parsetree;
842 
843  GetPGVariable(n->name, dest);
844  }
845  break;
846 
847  case T_DiscardStmt:
848  /* should we allow DISCARD PLANS? */
849  CheckRestrictedOperation("DISCARD");
850  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
851  break;
852 
854  /* no event triggers on event triggers */
856  break;
857 
859  /* no event triggers on event triggers */
860  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
861  break;
862 
863  /*
864  * ******************************** ROLE statements ****
865  */
866  case T_CreateRoleStmt:
867  /* no event triggers for global objects */
868  CreateRole(pstate, (CreateRoleStmt *) parsetree);
869  break;
870 
871  case T_AlterRoleStmt:
872  /* no event triggers for global objects */
873  AlterRole((AlterRoleStmt *) parsetree);
874  break;
875 
876  case T_AlterRoleSetStmt:
877  /* no event triggers for global objects */
878  AlterRoleSet((AlterRoleSetStmt *) parsetree);
879  break;
880 
881  case T_DropRoleStmt:
882  /* no event triggers for global objects */
883  DropRole((DropRoleStmt *) parsetree);
884  break;
885 
886  case T_ReassignOwnedStmt:
887  /* no event triggers for global objects */
889  break;
890 
891  case T_LockStmt:
892 
893  /*
894  * Since the lock would just get dropped immediately, LOCK TABLE
895  * outside a transaction block is presumed to be user error.
896  */
897  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
898  LockTableCommand((LockStmt *) parsetree);
899  break;
900 
902  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
904  break;
905 
906  case T_CheckPointStmt:
907  if (!superuser())
908  ereport(ERROR,
909  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
910  errmsg("must be superuser to do CHECKPOINT")));
911 
914  break;
915 
916  case T_ReindexStmt:
917  {
918  ReindexStmt *stmt = (ReindexStmt *) parsetree;
919 
920  if (stmt->concurrent)
921  PreventInTransactionBlock(isTopLevel,
922  "REINDEX CONCURRENTLY");
923 
924  switch (stmt->kind)
925  {
927  ReindexIndex(stmt->relation, stmt->options, stmt->concurrent);
928  break;
930  ReindexTable(stmt->relation, stmt->options, stmt->concurrent);
931  break;
935 
936  /*
937  * This cannot run inside a user transaction block; if
938  * we were inside a transaction, then its commit- and
939  * start-transaction-command calls would not have the
940  * intended effect!
941  */
942  PreventInTransactionBlock(isTopLevel,
943  (stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
944  (stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
945  "REINDEX DATABASE");
946  ReindexMultipleTables(stmt->name, stmt->kind, stmt->options, stmt->concurrent);
947  break;
948  default:
949  elog(ERROR, "unrecognized object type: %d",
950  (int) stmt->kind);
951  break;
952  }
953  }
954  break;
955 
956  /*
957  * The following statements are supported by Event Triggers only
958  * in some cases, so we "fast path" them in the other cases.
959  */
960 
961  case T_GrantStmt:
962  {
963  GrantStmt *stmt = (GrantStmt *) parsetree;
964 
966  ProcessUtilitySlow(pstate, pstmt, queryString,
967  context, params, queryEnv,
968  dest, qc);
969  else
970  ExecuteGrantStmt(stmt);
971  }
972  break;
973 
974  case T_DropStmt:
975  {
976  DropStmt *stmt = (DropStmt *) parsetree;
977 
979  ProcessUtilitySlow(pstate, pstmt, queryString,
980  context, params, queryEnv,
981  dest, qc);
982  else
983  ExecDropStmt(stmt, isTopLevel);
984  }
985  break;
986 
987  case T_RenameStmt:
988  {
989  RenameStmt *stmt = (RenameStmt *) parsetree;
990 
992  ProcessUtilitySlow(pstate, pstmt, queryString,
993  context, params, queryEnv,
994  dest, qc);
995  else
996  ExecRenameStmt(stmt);
997  }
998  break;
999 
1001  {
1002  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
1003 
1005  ProcessUtilitySlow(pstate, pstmt, queryString,
1006  context, params, queryEnv,
1007  dest, qc);
1008  else
1009  ExecAlterObjectDependsStmt(stmt, NULL);
1010  }
1011  break;
1012 
1014  {
1015  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
1016 
1018  ProcessUtilitySlow(pstate, pstmt, queryString,
1019  context, params, queryEnv,
1020  dest, qc);
1021  else
1022  ExecAlterObjectSchemaStmt(stmt, NULL);
1023  }
1024  break;
1025 
1026  case T_AlterOwnerStmt:
1027  {
1028  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
1029 
1031  ProcessUtilitySlow(pstate, pstmt, queryString,
1032  context, params, queryEnv,
1033  dest, qc);
1034  else
1035  ExecAlterOwnerStmt(stmt);
1036  }
1037  break;
1038 
1039  case T_CommentStmt:
1040  {
1041  CommentStmt *stmt = (CommentStmt *) parsetree;
1042 
1044  ProcessUtilitySlow(pstate, pstmt, queryString,
1045  context, params, queryEnv,
1046  dest, qc);
1047  else
1048  CommentObject(stmt);
1049  break;
1050  }
1051 
1052  case T_SecLabelStmt:
1053  {
1054  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
1055 
1057  ProcessUtilitySlow(pstate, pstmt, queryString,
1058  context, params, queryEnv,
1059  dest, qc);
1060  else
1061  ExecSecLabelStmt(stmt);
1062  break;
1063  }
1064 
1065  default:
1066  /* All other statement types have event trigger support */
1067  ProcessUtilitySlow(pstate, pstmt, queryString,
1068  context, params, queryEnv,
1069  dest, qc);
1070  break;
1071  }
1072 
1073  free_parsestate(pstate);
1074 
1075  /*
1076  * Make effects of commands visible, for instance so that
1077  * PreCommit_on_commit_actions() can see them (see for example bug
1078  * #15631).
1079  */
1081 }
ObjectType objtype
Definition: parsenodes.h:2678
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest)
Definition: explain.c:155
CommandTag
Definition: cmdtag.h:20
void closeAllVfds(void)
Definition: fd.c:2758
ObjectType objtype
Definition: parsenodes.h:2690
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1878
void PerformPortalClose(const char *name)
Definition: portalcmds.c:215
bool EndTransactionBlock(bool chain)
Definition: xact.c:3709
void PreventCommandIfParallelMode(const char *cmdname)
Definition: utility.c:423
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
Oid ReindexTable(RangeVar *relation, int options, bool concurrent)
Definition: indexcmds.c:2491
ObjectType renameType
Definition: parsenodes.h:2912
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:44
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3391
#define castNode(_type_, nodeptr)
Definition: nodes.h:595
QueryEnvironment * p_queryEnv
Definition: parse_node.h:203
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:1650
ObjectType objectType
Definition: parsenodes.h:2957
void DefineSavepoint(const char *name)
Definition: xact.c:4038
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:4972
void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest)
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:460
Definition: nodes.h:526
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3657
int errcode(int sqlerrcode)
Definition: elog.c:610
bool superuser(void)
Definition: superuser.c:46
char * filename
Definition: parsenodes.h:3137
void PrepareQuery(ParseState *pstate, PrepareStmt *stmt, int stmt_location, int stmt_len)
Definition: prepare.c:58
void Async_Listen(const char *channel)
Definition: async.c:762