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, char *completionTag)
 
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, char *completionTag)
 
void standard_ProcessUtility (PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
 
void ProcessUtilityForAlterTable (Node *stmt, AlterTableUtilityContext *context)
 
bool UtilityReturnsTuples (Node *parsetree)
 
TupleDesc UtilityTupleDescriptor (Node *parsetree)
 
QueryUtilityContainsQuery (Node *parsetree)
 
static const char * AlterObjectTypeCommandTag (ObjectType objtype)
 
const char * CreateCommandTag (Node *parsetree)
 
LogStmtLevel GetCommandLogLevel (Node *parsetree)
 

Variables

ProcessUtility_hook_type ProcessUtility_hook = NULL
 

Function Documentation

◆ AlterObjectTypeCommandTag()

static const char* AlterObjectTypeCommandTag ( ObjectType  objtype)
static

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

2104 {
2105  const char *tag;
2106 
2107  switch (objtype)
2108  {
2109  case OBJECT_AGGREGATE:
2110  tag = "ALTER AGGREGATE";
2111  break;
2112  case OBJECT_ATTRIBUTE:
2113  tag = "ALTER TYPE";
2114  break;
2115  case OBJECT_CAST:
2116  tag = "ALTER CAST";
2117  break;
2118  case OBJECT_COLLATION:
2119  tag = "ALTER COLLATION";
2120  break;
2121  case OBJECT_COLUMN:
2122  tag = "ALTER TABLE";
2123  break;
2124  case OBJECT_CONVERSION:
2125  tag = "ALTER CONVERSION";
2126  break;
2127  case OBJECT_DATABASE:
2128  tag = "ALTER DATABASE";
2129  break;
2130  case OBJECT_DOMAIN:
2131  case OBJECT_DOMCONSTRAINT:
2132  tag = "ALTER DOMAIN";
2133  break;
2134  case OBJECT_EXTENSION:
2135  tag = "ALTER EXTENSION";
2136  break;
2137  case OBJECT_FDW:
2138  tag = "ALTER FOREIGN DATA WRAPPER";
2139  break;
2140  case OBJECT_FOREIGN_SERVER:
2141  tag = "ALTER SERVER";
2142  break;
2143  case OBJECT_FOREIGN_TABLE:
2144  tag = "ALTER FOREIGN TABLE";
2145  break;
2146  case OBJECT_FUNCTION:
2147  tag = "ALTER FUNCTION";
2148  break;
2149  case OBJECT_INDEX:
2150  tag = "ALTER INDEX";
2151  break;
2152  case OBJECT_LANGUAGE:
2153  tag = "ALTER LANGUAGE";
2154  break;
2155  case OBJECT_LARGEOBJECT:
2156  tag = "ALTER LARGE OBJECT";
2157  break;
2158  case OBJECT_OPCLASS:
2159  tag = "ALTER OPERATOR CLASS";
2160  break;
2161  case OBJECT_OPERATOR:
2162  tag = "ALTER OPERATOR";
2163  break;
2164  case OBJECT_OPFAMILY:
2165  tag = "ALTER OPERATOR FAMILY";
2166  break;
2167  case OBJECT_POLICY:
2168  tag = "ALTER POLICY";
2169  break;
2170  case OBJECT_PROCEDURE:
2171  tag = "ALTER PROCEDURE";
2172  break;
2173  case OBJECT_ROLE:
2174  tag = "ALTER ROLE";
2175  break;
2176  case OBJECT_ROUTINE:
2177  tag = "ALTER ROUTINE";
2178  break;
2179  case OBJECT_RULE:
2180  tag = "ALTER RULE";
2181  break;
2182  case OBJECT_SCHEMA:
2183  tag = "ALTER SCHEMA";
2184  break;
2185  case OBJECT_SEQUENCE:
2186  tag = "ALTER SEQUENCE";
2187  break;
2188  case OBJECT_TABLE:
2189  case OBJECT_TABCONSTRAINT:
2190  tag = "ALTER TABLE";
2191  break;
2192  case OBJECT_TABLESPACE:
2193  tag = "ALTER TABLESPACE";
2194  break;
2195  case OBJECT_TRIGGER:
2196  tag = "ALTER TRIGGER";
2197  break;
2198  case OBJECT_EVENT_TRIGGER:
2199  tag = "ALTER EVENT TRIGGER";
2200  break;
2202  tag = "ALTER TEXT SEARCH CONFIGURATION";
2203  break;
2204  case OBJECT_TSDICTIONARY:
2205  tag = "ALTER TEXT SEARCH DICTIONARY";
2206  break;
2207  case OBJECT_TSPARSER:
2208  tag = "ALTER TEXT SEARCH PARSER";
2209  break;
2210  case OBJECT_TSTEMPLATE:
2211  tag = "ALTER TEXT SEARCH TEMPLATE";
2212  break;
2213  case OBJECT_TYPE:
2214  tag = "ALTER TYPE";
2215  break;
2216  case OBJECT_VIEW:
2217  tag = "ALTER VIEW";
2218  break;
2219  case OBJECT_MATVIEW:
2220  tag = "ALTER MATERIALIZED VIEW";
2221  break;
2222  case OBJECT_PUBLICATION:
2223  tag = "ALTER PUBLICATION";
2224  break;
2225  case OBJECT_SUBSCRIPTION:
2226  tag = "ALTER SUBSCRIPTION";
2227  break;
2228  case OBJECT_STATISTIC_EXT:
2229  tag = "ALTER STATISTICS";
2230  break;
2231  default:
2232  tag = "???";
2233  break;
2234  }
2235 
2236  return tag;
2237 }

◆ CheckRestrictedOperation()

static void CheckRestrictedOperation ( const char *  cmdname)
static

Definition at line 460 of file utility.c.

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

Referenced by standard_ProcessUtility().

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

◆ ClassifyUtilityCommandAsReadOnly()

static int ClassifyUtilityCommandAsReadOnly ( Node parsetree)
static

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

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

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

Definition at line 100 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(), init_execution_state(), and SPI_cursor_open_internal().

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

◆ CreateCommandTag()

const char* CreateCommandTag ( Node parsetree)

Definition at line 2252 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, relkind, 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_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_execute_plan(), _SPI_prepare_oneshot_plan(), _SPI_prepare_plan(), CreateCommandTag(), EventTriggerCommonSetup(), exec_parse_message(), exec_simple_query(), ExecCheckXactReadOnly(), get_command_tag(), init_execution_state(), pg_event_trigger_ddl_commands(), PrepareQuery(), SPI_cursor_open_internal(), and standard_ProcessUtility().

2253 {
2254  const char *tag;
2255 
2256  switch (nodeTag(parsetree))
2257  {
2258  /* recurse if we're given a RawStmt */
2259  case T_RawStmt:
2260  tag = CreateCommandTag(((RawStmt *) parsetree)->stmt);
2261  break;
2262 
2263  /* raw plannable queries */
2264  case T_InsertStmt:
2265  tag = "INSERT";
2266  break;
2267 
2268  case T_DeleteStmt:
2269  tag = "DELETE";
2270  break;
2271 
2272  case T_UpdateStmt:
2273  tag = "UPDATE";
2274  break;
2275 
2276  case T_SelectStmt:
2277  tag = "SELECT";
2278  break;
2279 
2280  /* utility statements --- same whether raw or cooked */
2281  case T_TransactionStmt:
2282  {
2283  TransactionStmt *stmt = (TransactionStmt *) parsetree;
2284 
2285  switch (stmt->kind)
2286  {
2287  case TRANS_STMT_BEGIN:
2288  tag = "BEGIN";
2289  break;
2290 
2291  case TRANS_STMT_START:
2292  tag = "START TRANSACTION";
2293  break;
2294 
2295  case TRANS_STMT_COMMIT:
2296  tag = "COMMIT";
2297  break;
2298 
2299  case TRANS_STMT_ROLLBACK:
2301  tag = "ROLLBACK";
2302  break;
2303 
2304  case TRANS_STMT_SAVEPOINT:
2305  tag = "SAVEPOINT";
2306  break;
2307 
2308  case TRANS_STMT_RELEASE:
2309  tag = "RELEASE";
2310  break;
2311 
2312  case TRANS_STMT_PREPARE:
2313  tag = "PREPARE TRANSACTION";
2314  break;
2315 
2317  tag = "COMMIT PREPARED";
2318  break;
2319 
2321  tag = "ROLLBACK PREPARED";
2322  break;
2323 
2324  default:
2325  tag = "???";
2326  break;
2327  }
2328  }
2329  break;
2330 
2331  case T_DeclareCursorStmt:
2332  tag = "DECLARE CURSOR";
2333  break;
2334 
2335  case T_ClosePortalStmt:
2336  {
2337  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
2338 
2339  if (stmt->portalname == NULL)
2340  tag = "CLOSE CURSOR ALL";
2341  else
2342  tag = "CLOSE CURSOR";
2343  }
2344  break;
2345 
2346  case T_FetchStmt:
2347  {
2348  FetchStmt *stmt = (FetchStmt *) parsetree;
2349 
2350  tag = (stmt->ismove) ? "MOVE" : "FETCH";
2351  }
2352  break;
2353 
2354  case T_CreateDomainStmt:
2355  tag = "CREATE DOMAIN";
2356  break;
2357 
2358  case T_CreateSchemaStmt:
2359  tag = "CREATE SCHEMA";
2360  break;
2361 
2362  case T_CreateStmt:
2363  tag = "CREATE TABLE";
2364  break;
2365 
2367  tag = "CREATE TABLESPACE";
2368  break;
2369 
2370  case T_DropTableSpaceStmt:
2371  tag = "DROP TABLESPACE";
2372  break;
2373 
2375  tag = "ALTER TABLESPACE";
2376  break;
2377 
2378  case T_CreateExtensionStmt:
2379  tag = "CREATE EXTENSION";
2380  break;
2381 
2382  case T_AlterExtensionStmt:
2383  tag = "ALTER EXTENSION";
2384  break;
2385 
2387  tag = "ALTER EXTENSION";
2388  break;
2389 
2390  case T_CreateFdwStmt:
2391  tag = "CREATE FOREIGN DATA WRAPPER";
2392  break;
2393 
2394  case T_AlterFdwStmt:
2395  tag = "ALTER FOREIGN DATA WRAPPER";
2396  break;
2397 
2399  tag = "CREATE SERVER";
2400  break;
2401 
2403  tag = "ALTER SERVER";
2404  break;
2405 
2407  tag = "CREATE USER MAPPING";
2408  break;
2409 
2411  tag = "ALTER USER MAPPING";
2412  break;
2413 
2414  case T_DropUserMappingStmt:
2415  tag = "DROP USER MAPPING";
2416  break;
2417 
2419  tag = "CREATE FOREIGN TABLE";
2420  break;
2421 
2423  tag = "IMPORT FOREIGN SCHEMA";
2424  break;
2425 
2426  case T_DropStmt:
2427  switch (((DropStmt *) parsetree)->removeType)
2428  {
2429  case OBJECT_TABLE:
2430  tag = "DROP TABLE";
2431  break;
2432  case OBJECT_SEQUENCE:
2433  tag = "DROP SEQUENCE";
2434  break;
2435  case OBJECT_VIEW:
2436  tag = "DROP VIEW";
2437  break;
2438  case OBJECT_MATVIEW:
2439  tag = "DROP MATERIALIZED VIEW";
2440  break;
2441  case OBJECT_INDEX:
2442  tag = "DROP INDEX";
2443  break;
2444  case OBJECT_TYPE:
2445  tag = "DROP TYPE";
2446  break;
2447  case OBJECT_DOMAIN:
2448  tag = "DROP DOMAIN";
2449  break;
2450  case OBJECT_COLLATION:
2451  tag = "DROP COLLATION";
2452  break;
2453  case OBJECT_CONVERSION:
2454  tag = "DROP CONVERSION";
2455  break;
2456  case OBJECT_SCHEMA:
2457  tag = "DROP SCHEMA";
2458  break;
2459  case OBJECT_TSPARSER:
2460  tag = "DROP TEXT SEARCH PARSER";
2461  break;
2462  case OBJECT_TSDICTIONARY:
2463  tag = "DROP TEXT SEARCH DICTIONARY";
2464  break;
2465  case OBJECT_TSTEMPLATE:
2466  tag = "DROP TEXT SEARCH TEMPLATE";
2467  break;
2469  tag = "DROP TEXT SEARCH CONFIGURATION";
2470  break;
2471  case OBJECT_FOREIGN_TABLE:
2472  tag = "DROP FOREIGN TABLE";
2473  break;
2474  case OBJECT_EXTENSION:
2475  tag = "DROP EXTENSION";
2476  break;
2477  case OBJECT_FUNCTION:
2478  tag = "DROP FUNCTION";
2479  break;
2480  case OBJECT_PROCEDURE:
2481  tag = "DROP PROCEDURE";
2482  break;
2483  case OBJECT_ROUTINE:
2484  tag = "DROP ROUTINE";
2485  break;
2486  case OBJECT_AGGREGATE:
2487  tag = "DROP AGGREGATE";
2488  break;
2489  case OBJECT_OPERATOR:
2490  tag = "DROP OPERATOR";
2491  break;
2492  case OBJECT_LANGUAGE:
2493  tag = "DROP LANGUAGE";
2494  break;
2495  case OBJECT_CAST:
2496  tag = "DROP CAST";
2497  break;
2498  case OBJECT_TRIGGER:
2499  tag = "DROP TRIGGER";
2500  break;
2501  case OBJECT_EVENT_TRIGGER:
2502  tag = "DROP EVENT TRIGGER";
2503  break;
2504  case OBJECT_RULE:
2505  tag = "DROP RULE";
2506  break;
2507  case OBJECT_FDW:
2508  tag = "DROP FOREIGN DATA WRAPPER";
2509  break;
2510  case OBJECT_FOREIGN_SERVER:
2511  tag = "DROP SERVER";
2512  break;
2513  case OBJECT_OPCLASS:
2514  tag = "DROP OPERATOR CLASS";
2515  break;
2516  case OBJECT_OPFAMILY:
2517  tag = "DROP OPERATOR FAMILY";
2518  break;
2519  case OBJECT_POLICY:
2520  tag = "DROP POLICY";
2521  break;
2522  case OBJECT_TRANSFORM:
2523  tag = "DROP TRANSFORM";
2524  break;
2525  case OBJECT_ACCESS_METHOD:
2526  tag = "DROP ACCESS METHOD";
2527  break;
2528  case OBJECT_PUBLICATION:
2529  tag = "DROP PUBLICATION";
2530  break;
2531  case OBJECT_STATISTIC_EXT:
2532  tag = "DROP STATISTICS";
2533  break;
2534  default:
2535  tag = "???";
2536  }
2537  break;
2538 
2539  case T_TruncateStmt:
2540  tag = "TRUNCATE TABLE";
2541  break;
2542 
2543  case T_CommentStmt:
2544  tag = "COMMENT";
2545  break;
2546 
2547  case T_SecLabelStmt:
2548  tag = "SECURITY LABEL";
2549  break;
2550 
2551  case T_CopyStmt:
2552  tag = "COPY";
2553  break;
2554 
2555  case T_RenameStmt:
2556 
2557  /*
2558  * When the column is renamed, the command tag is created from its
2559  * relation type
2560  */
2562  ((RenameStmt *) parsetree)->renameType == OBJECT_COLUMN ?
2563  ((RenameStmt *) parsetree)->relationType :
2564  ((RenameStmt *) parsetree)->renameType);
2565  break;
2566 
2568  tag = AlterObjectTypeCommandTag(((AlterObjectDependsStmt *) parsetree)->objectType);
2569  break;
2570 
2572  tag = AlterObjectTypeCommandTag(((AlterObjectSchemaStmt *) parsetree)->objectType);
2573  break;
2574 
2575  case T_AlterOwnerStmt:
2576  tag = AlterObjectTypeCommandTag(((AlterOwnerStmt *) parsetree)->objectType);
2577  break;
2578 
2580  tag = AlterObjectTypeCommandTag(((AlterTableMoveAllStmt *) parsetree)->objtype);
2581  break;
2582 
2583  case T_AlterTableStmt:
2584  tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->relkind);
2585  break;
2586 
2587  case T_AlterDomainStmt:
2588  tag = "ALTER DOMAIN";
2589  break;
2590 
2591  case T_AlterFunctionStmt:
2592  switch (((AlterFunctionStmt *) parsetree)->objtype)
2593  {
2594  case OBJECT_FUNCTION:
2595  tag = "ALTER FUNCTION";
2596  break;
2597  case OBJECT_PROCEDURE:
2598  tag = "ALTER PROCEDURE";
2599  break;
2600  case OBJECT_ROUTINE:
2601  tag = "ALTER ROUTINE";
2602  break;
2603  default:
2604  tag = "???";
2605  }
2606  break;
2607 
2608  case T_GrantStmt:
2609  {
2610  GrantStmt *stmt = (GrantStmt *) parsetree;
2611 
2612  tag = (stmt->is_grant) ? "GRANT" : "REVOKE";
2613  }
2614  break;
2615 
2616  case T_GrantRoleStmt:
2617  {
2618  GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;
2619 
2620  tag = (stmt->is_grant) ? "GRANT ROLE" : "REVOKE ROLE";
2621  }
2622  break;
2623 
2625  tag = "ALTER DEFAULT PRIVILEGES";
2626  break;
2627 
2628  case T_DefineStmt:
2629  switch (((DefineStmt *) parsetree)->kind)
2630  {
2631  case OBJECT_AGGREGATE:
2632  tag = "CREATE AGGREGATE";
2633  break;
2634  case OBJECT_OPERATOR:
2635  tag = "CREATE OPERATOR";
2636  break;
2637  case OBJECT_TYPE:
2638  tag = "CREATE TYPE";
2639  break;
2640  case OBJECT_TSPARSER:
2641  tag = "CREATE TEXT SEARCH PARSER";
2642  break;
2643  case OBJECT_TSDICTIONARY:
2644  tag = "CREATE TEXT SEARCH DICTIONARY";
2645  break;
2646  case OBJECT_TSTEMPLATE:
2647  tag = "CREATE TEXT SEARCH TEMPLATE";
2648  break;
2650  tag = "CREATE TEXT SEARCH CONFIGURATION";
2651  break;
2652  case OBJECT_COLLATION:
2653  tag = "CREATE COLLATION";
2654  break;
2655  case OBJECT_ACCESS_METHOD:
2656  tag = "CREATE ACCESS METHOD";
2657  break;
2658  default:
2659  tag = "???";
2660  }
2661  break;
2662 
2663  case T_CompositeTypeStmt:
2664  tag = "CREATE TYPE";
2665  break;
2666 
2667  case T_CreateEnumStmt:
2668  tag = "CREATE TYPE";
2669  break;
2670 
2671  case T_CreateRangeStmt:
2672  tag = "CREATE TYPE";
2673  break;
2674 
2675  case T_AlterEnumStmt:
2676  tag = "ALTER TYPE";
2677  break;
2678 
2679  case T_ViewStmt:
2680  tag = "CREATE VIEW";
2681  break;
2682 
2683  case T_CreateFunctionStmt:
2684  if (((CreateFunctionStmt *) parsetree)->is_procedure)
2685  tag = "CREATE PROCEDURE";
2686  else
2687  tag = "CREATE FUNCTION";
2688  break;
2689 
2690  case T_IndexStmt:
2691  tag = "CREATE INDEX";
2692  break;
2693 
2694  case T_RuleStmt:
2695  tag = "CREATE RULE";
2696  break;
2697 
2698  case T_CreateSeqStmt:
2699  tag = "CREATE SEQUENCE";
2700  break;
2701 
2702  case T_AlterSeqStmt:
2703  tag = "ALTER SEQUENCE";
2704  break;
2705 
2706  case T_DoStmt:
2707  tag = "DO";
2708  break;
2709 
2710  case T_CreatedbStmt:
2711  tag = "CREATE DATABASE";
2712  break;
2713 
2714  case T_AlterDatabaseStmt:
2715  tag = "ALTER DATABASE";
2716  break;
2717 
2719  tag = "ALTER DATABASE";
2720  break;
2721 
2722  case T_DropdbStmt:
2723  tag = "DROP DATABASE";
2724  break;
2725 
2726  case T_NotifyStmt:
2727  tag = "NOTIFY";
2728  break;
2729 
2730  case T_ListenStmt:
2731  tag = "LISTEN";
2732  break;
2733 
2734  case T_UnlistenStmt:
2735  tag = "UNLISTEN";
2736  break;
2737 
2738  case T_LoadStmt:
2739  tag = "LOAD";
2740  break;
2741 
2742  case T_CallStmt:
2743  tag = "CALL";
2744  break;
2745 
2746  case T_ClusterStmt:
2747  tag = "CLUSTER";
2748  break;
2749 
2750  case T_VacuumStmt:
2751  if (((VacuumStmt *) parsetree)->is_vacuumcmd)
2752  tag = "VACUUM";
2753  else
2754  tag = "ANALYZE";
2755  break;
2756 
2757  case T_ExplainStmt:
2758  tag = "EXPLAIN";
2759  break;
2760 
2761  case T_CreateTableAsStmt:
2762  switch (((CreateTableAsStmt *) parsetree)->relkind)
2763  {
2764  case OBJECT_TABLE:
2765  if (((CreateTableAsStmt *) parsetree)->is_select_into)
2766  tag = "SELECT INTO";
2767  else
2768  tag = "CREATE TABLE AS";
2769  break;
2770  case OBJECT_MATVIEW:
2771  tag = "CREATE MATERIALIZED VIEW";
2772  break;
2773  default:
2774  tag = "???";
2775  }
2776  break;
2777 
2778  case T_RefreshMatViewStmt:
2779  tag = "REFRESH MATERIALIZED VIEW";
2780  break;
2781 
2782  case T_AlterSystemStmt:
2783  tag = "ALTER SYSTEM";
2784  break;
2785 
2786  case T_VariableSetStmt:
2787  switch (((VariableSetStmt *) parsetree)->kind)
2788  {
2789  case VAR_SET_VALUE:
2790  case VAR_SET_CURRENT:
2791  case VAR_SET_DEFAULT:
2792  case VAR_SET_MULTI:
2793  tag = "SET";
2794  break;
2795  case VAR_RESET:
2796  case VAR_RESET_ALL:
2797  tag = "RESET";
2798  break;
2799  default:
2800  tag = "???";
2801  }
2802  break;
2803 
2804  case T_VariableShowStmt:
2805  tag = "SHOW";
2806  break;
2807 
2808  case T_DiscardStmt:
2809  switch (((DiscardStmt *) parsetree)->target)
2810  {
2811  case DISCARD_ALL:
2812  tag = "DISCARD ALL";
2813  break;
2814  case DISCARD_PLANS:
2815  tag = "DISCARD PLANS";
2816  break;
2817  case DISCARD_TEMP:
2818  tag = "DISCARD TEMP";
2819  break;
2820  case DISCARD_SEQUENCES:
2821  tag = "DISCARD SEQUENCES";
2822  break;
2823  default:
2824  tag = "???";
2825  }
2826  break;
2827 
2828  case T_CreateTransformStmt:
2829  tag = "CREATE TRANSFORM";
2830  break;
2831 
2832  case T_CreateTrigStmt:
2833  tag = "CREATE TRIGGER";
2834  break;
2835 
2836  case T_CreateEventTrigStmt:
2837  tag = "CREATE EVENT TRIGGER";
2838  break;
2839 
2840  case T_AlterEventTrigStmt:
2841  tag = "ALTER EVENT TRIGGER";
2842  break;
2843 
2844  case T_CreatePLangStmt:
2845  tag = "CREATE LANGUAGE";
2846  break;
2847 
2848  case T_CreateRoleStmt:
2849  tag = "CREATE ROLE";
2850  break;
2851 
2852  case T_AlterRoleStmt:
2853  tag = "ALTER ROLE";
2854  break;
2855 
2856  case T_AlterRoleSetStmt:
2857  tag = "ALTER ROLE";
2858  break;
2859 
2860  case T_DropRoleStmt:
2861  tag = "DROP ROLE";
2862  break;
2863 
2864  case T_DropOwnedStmt:
2865  tag = "DROP OWNED";
2866  break;
2867 
2868  case T_ReassignOwnedStmt:
2869  tag = "REASSIGN OWNED";
2870  break;
2871 
2872  case T_LockStmt:
2873  tag = "LOCK TABLE";
2874  break;
2875 
2876  case T_ConstraintsSetStmt:
2877  tag = "SET CONSTRAINTS";
2878  break;
2879 
2880  case T_CheckPointStmt:
2881  tag = "CHECKPOINT";
2882  break;
2883 
2884  case T_ReindexStmt:
2885  tag = "REINDEX";
2886  break;
2887 
2889  tag = "CREATE CONVERSION";
2890  break;
2891 
2892  case T_CreateCastStmt:
2893  tag = "CREATE CAST";
2894  break;
2895 
2896  case T_CreateOpClassStmt:
2897  tag = "CREATE OPERATOR CLASS";
2898  break;
2899 
2900  case T_CreateOpFamilyStmt:
2901  tag = "CREATE OPERATOR FAMILY";
2902  break;
2903 
2904  case T_AlterOpFamilyStmt:
2905  tag = "ALTER OPERATOR FAMILY";
2906  break;
2907 
2908  case T_AlterOperatorStmt:
2909  tag = "ALTER OPERATOR";
2910  break;
2911 
2913  tag = "ALTER TEXT SEARCH DICTIONARY";
2914  break;
2915 
2917  tag = "ALTER TEXT SEARCH CONFIGURATION";
2918  break;
2919 
2920  case T_CreatePolicyStmt:
2921  tag = "CREATE POLICY";
2922  break;
2923 
2924  case T_AlterPolicyStmt:
2925  tag = "ALTER POLICY";
2926  break;
2927 
2928  case T_CreateAmStmt:
2929  tag = "CREATE ACCESS METHOD";
2930  break;
2931 
2933  tag = "CREATE PUBLICATION";
2934  break;
2935 
2937  tag = "ALTER PUBLICATION";
2938  break;
2939 
2941  tag = "CREATE SUBSCRIPTION";
2942  break;
2943 
2945  tag = "ALTER SUBSCRIPTION";
2946  break;
2947 
2949  tag = "DROP SUBSCRIPTION";
2950  break;
2951 
2952  case T_AlterCollationStmt:
2953  tag = "ALTER COLLATION";
2954  break;
2955 
2956  case T_PrepareStmt:
2957  tag = "PREPARE";
2958  break;
2959 
2960  case T_ExecuteStmt:
2961  tag = "EXECUTE";
2962  break;
2963 
2964  case T_CreateStatsStmt:
2965  tag = "CREATE STATISTICS";
2966  break;
2967 
2968  case T_AlterStatsStmt:
2969  tag = "ALTER STATISTICS";
2970  break;
2971 
2972  case T_DeallocateStmt:
2973  {
2974  DeallocateStmt *stmt = (DeallocateStmt *) parsetree;
2975 
2976  if (stmt->name == NULL)
2977  tag = "DEALLOCATE ALL";
2978  else
2979  tag = "DEALLOCATE";
2980  }
2981  break;
2982 
2983  /* already-planned queries */
2984  case T_PlannedStmt:
2985  {
2986  PlannedStmt *stmt = (PlannedStmt *) parsetree;
2987 
2988  switch (stmt->commandType)
2989  {
2990  case CMD_SELECT:
2991 
2992  /*
2993  * We take a little extra care here so that the result
2994  * will be useful for complaints about read-only
2995  * statements
2996  */
2997  if (stmt->rowMarks != NIL)
2998  {
2999  /* not 100% but probably close enough */
3000  switch (((PlanRowMark *) linitial(stmt->rowMarks))->strength)
3001  {
3002  case LCS_FORKEYSHARE:
3003  tag = "SELECT FOR KEY SHARE";
3004  break;
3005  case LCS_FORSHARE:
3006  tag = "SELECT FOR SHARE";
3007  break;
3008  case LCS_FORNOKEYUPDATE:
3009  tag = "SELECT FOR NO KEY UPDATE";
3010  break;
3011  case LCS_FORUPDATE:
3012  tag = "SELECT FOR UPDATE";
3013  break;
3014  default:
3015  tag = "SELECT";
3016  break;
3017  }
3018  }
3019  else
3020  tag = "SELECT";
3021  break;
3022  case CMD_UPDATE:
3023  tag = "UPDATE";
3024  break;
3025  case CMD_INSERT:
3026  tag = "INSERT";
3027  break;
3028  case CMD_DELETE:
3029  tag = "DELETE";
3030  break;
3031  case CMD_UTILITY:
3032  tag = CreateCommandTag(stmt->utilityStmt);
3033  break;
3034  default:
3035  elog(WARNING, "unrecognized commandType: %d",
3036  (int) stmt->commandType);
3037  tag = "???";
3038  break;
3039  }
3040  }
3041  break;
3042 
3043  /* parsed-and-rewritten-but-not-planned queries */
3044  case T_Query:
3045  {
3046  Query *stmt = (Query *) parsetree;
3047 
3048  switch (stmt->commandType)
3049  {
3050  case CMD_SELECT:
3051 
3052  /*
3053  * We take a little extra care here so that the result
3054  * will be useful for complaints about read-only
3055  * statements
3056  */
3057  if (stmt->rowMarks != NIL)
3058  {
3059  /* not 100% but probably close enough */
3060  switch (((RowMarkClause *) linitial(stmt->rowMarks))->strength)
3061  {
3062  case LCS_FORKEYSHARE:
3063  tag = "SELECT FOR KEY SHARE";
3064  break;
3065  case LCS_FORSHARE:
3066  tag = "SELECT FOR SHARE";
3067  break;
3068  case LCS_FORNOKEYUPDATE:
3069  tag = "SELECT FOR NO KEY UPDATE";
3070  break;
3071  case LCS_FORUPDATE:
3072  tag = "SELECT FOR UPDATE";
3073  break;
3074  default:
3075  tag = "???";
3076  break;
3077  }
3078  }
3079  else
3080  tag = "SELECT";
3081  break;
3082  case CMD_UPDATE:
3083  tag = "UPDATE";
3084  break;
3085  case CMD_INSERT:
3086  tag = "INSERT";
3087  break;
3088  case CMD_DELETE:
3089  tag = "DELETE";
3090  break;
3091  case CMD_UTILITY:
3092  tag = CreateCommandTag(stmt->utilityStmt);
3093  break;
3094  default:
3095  elog(WARNING, "unrecognized commandType: %d",
3096  (int) stmt->commandType);
3097  tag = "???";
3098  break;
3099  }
3100  }
3101  break;
3102 
3103  default:
3104  elog(WARNING, "unrecognized node type: %d",
3105  (int) nodeTag(parsetree));
3106  tag = "???";
3107  break;
3108  }
3109 
3110  return tag;
3111 }
#define NIL
Definition: pg_list.h:65
List * rowMarks
Definition: parsenodes.h:163
Node * utilityStmt
Definition: parsenodes.h:120
char relkind
Definition: pg_class.h:81
#define linitial(l)
Definition: pg_list.h:195
Node * utilityStmt
Definition: plannodes.h:92
const char * CreateCommandTag(Node *parsetree)
Definition: utility.c:2252
bool is_grant
Definition: parsenodes.h:1924
#define WARNING
Definition: elog.h:40
Definition: nodes.h:310
bool ismove
Definition: parsenodes.h:2755
CmdType commandType
Definition: plannodes.h:46
List * rowMarks
Definition: plannodes.h:84
CmdType commandType
Definition: parsenodes.h:112
#define nodeTag(nodeptr)
Definition: nodes.h:530
#define elog(elevel,...)
Definition: elog.h:228
static const char * AlterObjectTypeCommandTag(ObjectType objtype)
Definition: utility.c:2103
TransactionStmtKind kind
Definition: parsenodes.h:3043

◆ ExecDropStmt()

static void ExecDropStmt ( DropStmt stmt,
bool  isTopLevel 
)
static

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

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

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 3124 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_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(), and GetCommandLogLevel().

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

◆ PreventCommandDuringRecovery()

void PreventCommandDuringRecovery ( const char *  cmdname)

Definition at line 442 of file utility.c.

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

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

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

◆ PreventCommandIfParallelMode()

void PreventCommandIfParallelMode ( const char *  cmdname)

Definition at line 423 of file utility.c.

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

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

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

◆ PreventCommandIfReadOnly()

void PreventCommandIfReadOnly ( const char *  cmdname)

Definition at line 405 of file utility.c.

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

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

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

◆ ProcessUtility()

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

Definition at line 504 of file utility.c.

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

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

511 {
512  Assert(IsA(pstmt, PlannedStmt));
513  Assert(pstmt->commandType == CMD_UTILITY);
514  Assert(queryString != NULL); /* required as of 8.4 */
515 
516  /*
517  * We provide a function hook variable that lets loadable plugins get
518  * control when ProcessUtility is called. Such a plugin would normally
519  * call standard_ProcessUtility().
520  */
522  (*ProcessUtility_hook) (pstmt, queryString,
523  context, params, queryEnv,
524  dest, completionTag);
525  else
526  standard_ProcessUtility(pstmt, queryString,
527  context, params, queryEnv,
528  dest, completionTag);
529 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
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, char *completionTag)
Definition: utility.c:543
CmdType commandType
Definition: plannodes.h:46
#define Assert(condition)
Definition: c.h:739

◆ ProcessUtilityForAlterTable()

void ProcessUtilityForAlterTable ( Node stmt,
AlterTableUtilityContext context 
)

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

1849 {
1850  PlannedStmt *wrapper;
1851 
1852  /*
1853  * For event triggers, we must "close" the current complex-command set,
1854  * and start a new one afterwards; this is needed to ensure the ordering
1855  * of command events is consistent with the way they were executed.
1856  */
1858 
1859  /* Create a suitable wrapper */
1860  wrapper = makeNode(PlannedStmt);
1861  wrapper->commandType = CMD_UTILITY;
1862  wrapper->canSetTag = false;
1863  wrapper->utilityStmt = stmt;
1864  wrapper->stmt_location = context->pstmt->stmt_location;
1865  wrapper->stmt_len = context->pstmt->stmt_len;
1866 
1867  ProcessUtility(wrapper,
1868  context->queryString,
1870  context->params,
1871  context->queryEnv,
1872  None_Receiver,
1873  NULL);
1874 
1877 }
PlannedStmt * pstmt
Definition: utility.h:31
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.c:504
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:32
QueryEnvironment * queryEnv
Definition: utility.h:35
bool canSetTag
Definition: plannodes.h:54
CmdType commandType
Definition: plannodes.h:46
#define makeNode(_type_)
Definition: nodes.h:573
void EventTriggerAlterTableRelid(Oid objectId)
ParamListInfo params
Definition: utility.h:34
void EventTriggerAlterTableEnd(void)

◆ ProcessUtilitySlow()

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

Definition at line 1098 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(), 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, relkind, 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_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().

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

◆ standard_ProcessUtility()

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

Definition at line 543 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(), COMPLETION_TAG_BUFSIZE, 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(), 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(), snprintf, 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, UINT64_FORMAT, UserAbortTransactionBlock(), PlannedStmt::utilityStmt, WarnNoTransactionBlock(), and XactReadOnly.

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

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