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 2100 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().

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

◆ CheckRestrictedOperation()

static void CheckRestrictedOperation ( const char *  cmdname)
static

Definition at line 462 of file utility.c.

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

Referenced by standard_ProcessUtility().

463 {
465  ereport(ERROR,
466  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
467  /* translator: %s is name of a SQL command, eg PREPARE */
468  errmsg("cannot execute %s within security-restricted operation",
469  cmdname)));
470 }
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:580
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 of
228  * 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 run
275  * in a read-only transaction or on a standby. However, they
276  * are disallowed in parallel mode, because they either rely
277  * 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
289  * read-only, and running them in parallel workers isn't
290  * supported.
291  *
292  * However, they don't change the database state in a way that
293  * would affect pg_dump output, so it's fine to run them in a
294  * read-only transaction. (CLUSTER might change the order of
295  * rows on disk, which could affect the ordering of pg_dump
296  * output, but that's not semantically significant.)
297  */
299  }
300 
301  case T_CopyStmt:
302  {
303  CopyStmt *stmt = (CopyStmt *) parsetree;
304 
305  /*
306  * You might think that COPY FROM is not at all read only, but
307  * it's OK to copy into a temporary table, because that
308  * wouldn't change the output of pg_dump. If the target table
309  * turns out to be non-temporary, DoCopy itself will call
310  * PreventCommandIfReadOnly.
311  */
312  if (stmt->is_from)
314  else
316  }
317 
318  case T_ExplainStmt:
319  case T_VariableShowStmt:
320  {
321  /*
322  * These commands don't modify any data and are safe to run in
323  * a parallel worker.
324  */
326  }
327 
328  case T_ListenStmt:
329  case T_NotifyStmt:
330  {
331  /*
332  * NOTIFY requires an XID assignment, so it can't be permitted
333  * on a standby. Perhaps LISTEN could, since without NOTIFY it
334  * would be OK to just do nothing, at least until promotion,
335  * but we currently prohibit it lest the user get the wrong
336  * idea.
337  *
338  * (We do allow T_UnlistenStmt on a standby, though, because
339  * it's a no-op.)
340  */
342  }
343 
344  case T_LockStmt:
345  {
346  LockStmt *stmt = (LockStmt *) parsetree;
347 
348  /*
349  * Only weaker locker modes are allowed during recovery. The
350  * restrictions here must match those in
351  * LockAcquireExtended().
352  */
353  if (stmt->mode > RowExclusiveLock)
355  else
357  }
358 
359  case T_TransactionStmt:
360  {
361  TransactionStmt *stmt = (TransactionStmt *) parsetree;
362 
363  /*
364  * PREPARE, COMMIT PREPARED, and ROLLBACK PREPARED all write
365  * WAL, so they're not read-only in the strict sense; but the
366  * first and third do not change pg_dump output, so they're OK
367  * in a read-only transactions.
368  *
369  * We also consider COMMIT PREPARED to be OK in a read-only
370  * transaction environment, by way of exception.
371  */
372  switch (stmt->kind)
373  {
374  case TRANS_STMT_BEGIN:
375  case TRANS_STMT_START:
376  case TRANS_STMT_COMMIT:
377  case TRANS_STMT_ROLLBACK:
379  case TRANS_STMT_RELEASE:
382 
383  case TRANS_STMT_PREPARE:
387  }
388  elog(ERROR, "unrecognized TransactionStmtKind: %d",
389  (int) stmt->kind);
390  return 0; /* silence stupider compilers */
391  }
392 
393  default:
394  elog(ERROR, "unrecognized node type: %d",
395  (int) nodeTag(parsetree));
396  return 0; /* silence stupider compilers */
397  }
398 }
#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:534
#define COMMAND_IS_NOT_READ_ONLY
Definition: utility.h:68
bool is_from
Definition: parsenodes.h:2015
#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:3059

◆ 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:580
#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 2246 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().

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

◆ ExecDropStmt()

static void ExecDropStmt ( DropStmt stmt,
bool  isTopLevel 
)
static

Definition at line 1880 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().

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

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3121 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().

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

◆ PreventCommandDuringRecovery()

void PreventCommandDuringRecovery ( const char *  cmdname)

Definition at line 444 of file utility.c.

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

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

445 {
446  if (RecoveryInProgress())
447  ereport(ERROR,
448  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
449  /* translator: %s is name of a SQL command, eg CREATE */
450  errmsg("cannot execute %s during recovery",
451  cmdname)));
452 }
int errcode(int sqlerrcode)
Definition: elog.c:610
bool RecoveryInProgress(void)
Definition: xlog.c:8072
#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 425 of file utility.c.

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

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

426 {
427  if (IsInParallelMode())
428  ereport(ERROR,
429  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
430  /* translator: %s is name of a SQL command, eg CREATE */
431  errmsg("cannot execute %s during a parallel operation",
432  cmdname)));
433 }
int errcode(int sqlerrcode)
Definition: elog.c:610
bool IsInParallelMode(void)
Definition: xact.c:997
#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 407 of file utility.c.

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

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

408 {
409  if (XactReadOnly)
410  ereport(ERROR,
411  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
412  /* translator: %s is name of a SQL command, eg CREATE */
413  errmsg("cannot execute %s in a read-only transaction",
414  cmdname)));
415 }
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:78
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 501 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().

508 {
509  Assert(IsA(pstmt, PlannedStmt));
510  Assert(pstmt->commandType == CMD_UTILITY);
511  Assert(queryString != NULL); /* required as of 8.4 */
512  Assert(qc == NULL || qc->commandTag == CMDTAG_UNKNOWN);
513 
514  /*
515  * We provide a function hook variable that lets loadable plugins get
516  * control when ProcessUtility is called. Such a plugin would normally
517  * call standard_ProcessUtility().
518  */
520  (*ProcessUtility_hook) (pstmt, queryString,
521  context, params, queryEnv,
522  dest, qc);
523  else
524  standard_ProcessUtility(pstmt, queryString,
525  context, params, queryEnv,
526  dest, qc);
527 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
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:541
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 1845 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().

1846 {
1847  PlannedStmt *wrapper;
1848 
1849  /*
1850  * For event triggers, we must "close" the current complex-command set,
1851  * and start a new one afterwards; this is needed to ensure the ordering
1852  * of command events is consistent with the way they were executed.
1853  */
1855 
1856  /* Create a suitable wrapper */
1857  wrapper = makeNode(PlannedStmt);
1858  wrapper->commandType = CMD_UTILITY;
1859  wrapper->canSetTag = false;
1860  wrapper->utilityStmt = stmt;
1861  wrapper->stmt_location = context->pstmt->stmt_location;
1862  wrapper->stmt_len = context->pstmt->stmt_len;
1863 
1864  ProcessUtility(wrapper,
1865  context->queryString,
1867  context->params,
1868  context->queryEnv,
1869  None_Receiver,
1870  NULL);
1871 
1874 }
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:577
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:501
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 1091 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().

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

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