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_fn.h"
#include "catalog/toasting.h"
#include "commands/alter.h"
#include "commands/async.h"
#include "commands/cluster.h"
#include "commands/comment.h"
#include "commands/collationcmds.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/matview.h"
#include "commands/lockcmds.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/syscache.h"
Include dependency graph for utility.c:

Go to the source code of this file.

Functions

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)
 
static void check_xact_readonly (Node *parsetree)
 
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)
 
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 1922 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().

1923 {
1924  const char *tag;
1925 
1926  switch (objtype)
1927  {
1928  case OBJECT_AGGREGATE:
1929  tag = "ALTER AGGREGATE";
1930  break;
1931  case OBJECT_ATTRIBUTE:
1932  tag = "ALTER TYPE";
1933  break;
1934  case OBJECT_CAST:
1935  tag = "ALTER CAST";
1936  break;
1937  case OBJECT_COLLATION:
1938  tag = "ALTER COLLATION";
1939  break;
1940  case OBJECT_COLUMN:
1941  tag = "ALTER TABLE";
1942  break;
1943  case OBJECT_CONVERSION:
1944  tag = "ALTER CONVERSION";
1945  break;
1946  case OBJECT_DATABASE:
1947  tag = "ALTER DATABASE";
1948  break;
1949  case OBJECT_DOMAIN:
1950  case OBJECT_DOMCONSTRAINT:
1951  tag = "ALTER DOMAIN";
1952  break;
1953  case OBJECT_EXTENSION:
1954  tag = "ALTER EXTENSION";
1955  break;
1956  case OBJECT_FDW:
1957  tag = "ALTER FOREIGN DATA WRAPPER";
1958  break;
1959  case OBJECT_FOREIGN_SERVER:
1960  tag = "ALTER SERVER";
1961  break;
1962  case OBJECT_FOREIGN_TABLE:
1963  tag = "ALTER FOREIGN TABLE";
1964  break;
1965  case OBJECT_FUNCTION:
1966  tag = "ALTER FUNCTION";
1967  break;
1968  case OBJECT_INDEX:
1969  tag = "ALTER INDEX";
1970  break;
1971  case OBJECT_LANGUAGE:
1972  tag = "ALTER LANGUAGE";
1973  break;
1974  case OBJECT_LARGEOBJECT:
1975  tag = "ALTER LARGE OBJECT";
1976  break;
1977  case OBJECT_OPCLASS:
1978  tag = "ALTER OPERATOR CLASS";
1979  break;
1980  case OBJECT_OPERATOR:
1981  tag = "ALTER OPERATOR";
1982  break;
1983  case OBJECT_OPFAMILY:
1984  tag = "ALTER OPERATOR FAMILY";
1985  break;
1986  case OBJECT_POLICY:
1987  tag = "ALTER POLICY";
1988  break;
1989  case OBJECT_PROCEDURE:
1990  tag = "ALTER PROCEDURE";
1991  break;
1992  case OBJECT_ROLE:
1993  tag = "ALTER ROLE";
1994  break;
1995  case OBJECT_ROUTINE:
1996  tag = "ALTER ROUTINE";
1997  break;
1998  case OBJECT_RULE:
1999  tag = "ALTER RULE";
2000  break;
2001  case OBJECT_SCHEMA:
2002  tag = "ALTER SCHEMA";
2003  break;
2004  case OBJECT_SEQUENCE:
2005  tag = "ALTER SEQUENCE";
2006  break;
2007  case OBJECT_TABLE:
2008  case OBJECT_TABCONSTRAINT:
2009  tag = "ALTER TABLE";
2010  break;
2011  case OBJECT_TABLESPACE:
2012  tag = "ALTER TABLESPACE";
2013  break;
2014  case OBJECT_TRIGGER:
2015  tag = "ALTER TRIGGER";
2016  break;
2017  case OBJECT_EVENT_TRIGGER:
2018  tag = "ALTER EVENT TRIGGER";
2019  break;
2021  tag = "ALTER TEXT SEARCH CONFIGURATION";
2022  break;
2023  case OBJECT_TSDICTIONARY:
2024  tag = "ALTER TEXT SEARCH DICTIONARY";
2025  break;
2026  case OBJECT_TSPARSER:
2027  tag = "ALTER TEXT SEARCH PARSER";
2028  break;
2029  case OBJECT_TSTEMPLATE:
2030  tag = "ALTER TEXT SEARCH TEMPLATE";
2031  break;
2032  case OBJECT_TYPE:
2033  tag = "ALTER TYPE";
2034  break;
2035  case OBJECT_VIEW:
2036  tag = "ALTER VIEW";
2037  break;
2038  case OBJECT_MATVIEW:
2039  tag = "ALTER MATERIALIZED VIEW";
2040  break;
2041  case OBJECT_PUBLICATION:
2042  tag = "ALTER PUBLICATION";
2043  break;
2044  case OBJECT_SUBSCRIPTION:
2045  tag = "ALTER SUBSCRIPTION";
2046  break;
2047  case OBJECT_STATISTIC_EXT:
2048  tag = "ALTER STATISTICS";
2049  break;
2050  default:
2051  tag = "???";
2052  break;
2053  }
2054 
2055  return tag;
2056 }

◆ check_xact_readonly()

static void check_xact_readonly ( Node parsetree)
static

Definition at line 132 of file utility.c.

References CreateCommandTag(), IsInParallelMode(), nodeTag, PreventCommandIfParallelMode(), PreventCommandIfReadOnly(), 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_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterSubscriptionStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterUserMappingStmt, T_CommentStmt, T_CompositeTypeStmt, 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_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DefineStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_TruncateStmt, T_ViewStmt, and XactReadOnly.

Referenced by standard_ProcessUtility().

133 {
134  /* Only perform the check if we have a reason to do so. */
135  if (!XactReadOnly && !IsInParallelMode())
136  return;
137 
138  /*
139  * Note: Commands that need to do more complicated checking are handled
140  * elsewhere, in particular COPY and plannable statements do their own
141  * checking. However they should all call PreventCommandIfReadOnly or
142  * PreventCommandIfParallelMode to actually throw the error.
143  */
144 
145  switch (nodeTag(parsetree))
146  {
147  case T_AlterDatabaseStmt:
149  case T_AlterDomainStmt:
150  case T_AlterFunctionStmt:
151  case T_AlterRoleStmt:
152  case T_AlterRoleSetStmt:
155  case T_AlterOwnerStmt:
156  case T_AlterOperatorStmt:
157  case T_AlterSeqStmt:
159  case T_AlterTableStmt:
160  case T_RenameStmt:
161  case T_CommentStmt:
162  case T_DefineStmt:
163  case T_CreateCastStmt:
167  case T_CreatedbStmt:
168  case T_CreateDomainStmt:
170  case T_CreateRoleStmt:
171  case T_IndexStmt:
172  case T_CreatePLangStmt:
173  case T_CreateOpClassStmt:
175  case T_AlterOpFamilyStmt:
176  case T_RuleStmt:
177  case T_CreateSchemaStmt:
178  case T_CreateSeqStmt:
179  case T_CreateStmt:
180  case T_CreateTableAsStmt:
184  case T_CreateTrigStmt:
185  case T_CompositeTypeStmt:
186  case T_CreateEnumStmt:
187  case T_CreateRangeStmt:
188  case T_AlterEnumStmt:
189  case T_ViewStmt:
190  case T_DropStmt:
191  case T_DropdbStmt:
193  case T_DropRoleStmt:
194  case T_GrantStmt:
195  case T_GrantRoleStmt:
197  case T_TruncateStmt:
198  case T_DropOwnedStmt:
199  case T_ReassignOwnedStmt:
205  case T_CreateFdwStmt:
206  case T_AlterFdwStmt:
215  case T_SecLabelStmt:
223  break;
224  default:
225  /* do nothing */
226  break;
227  }
228 }
void PreventCommandIfParallelMode(const char *cmdname)
Definition: utility.c:255
bool IsInParallelMode(void)
Definition: xact.c:906
const char * CreateCommandTag(Node *parsetree)
Definition: utility.c:2071
bool XactReadOnly
Definition: xact.c:77
void PreventCommandIfReadOnly(const char *cmdname)
Definition: utility.c:237
#define nodeTag(nodeptr)
Definition: nodes.h:518

◆ CheckRestrictedOperation()

static void CheckRestrictedOperation ( const char *  cmdname)
static

Definition at line 292 of file utility.c.

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

Referenced by standard_ProcessUtility().

293 {
295  ereport(ERROR,
296  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
297  /* translator: %s is name of a SQL command, eg PREPARE */
298  errmsg("cannot execute %s within security-restricted operation",
299  cmdname)));
300 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool InSecurityRestrictedOperation(void)
Definition: miscinit.c:416
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

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

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

◆ CreateCommandTag()

const char* CreateCommandTag ( Node parsetree)

Definition at line 2071 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_CONVERSION, OBJECT_DOMAIN, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_TABLE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ClosePortalStmt::portalname, PlannedStmt::rowMarks, Query::rowMarks, T_AlterCollationStmt, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_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, VACOPT_VACUUM, 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(), check_xact_readonly(), CreateCommandTag(), EventTriggerCommonSetup(), exec_parse_message(), exec_simple_query(), ExecCheckXactReadOnly(), get_command_tag(), init_execution_state(), pg_event_trigger_ddl_commands(), PrepareQuery(), and SPI_cursor_open_internal().

2072 {
2073  const char *tag;
2074 
2075  switch (nodeTag(parsetree))
2076  {
2077  /* recurse if we're given a RawStmt */
2078  case T_RawStmt:
2079  tag = CreateCommandTag(((RawStmt *) parsetree)->stmt);
2080  break;
2081 
2082  /* raw plannable queries */
2083  case T_InsertStmt:
2084  tag = "INSERT";
2085  break;
2086 
2087  case T_DeleteStmt:
2088  tag = "DELETE";
2089  break;
2090 
2091  case T_UpdateStmt:
2092  tag = "UPDATE";
2093  break;
2094 
2095  case T_SelectStmt:
2096  tag = "SELECT";
2097  break;
2098 
2099  /* utility statements --- same whether raw or cooked */
2100  case T_TransactionStmt:
2101  {
2102  TransactionStmt *stmt = (TransactionStmt *) parsetree;
2103 
2104  switch (stmt->kind)
2105  {
2106  case TRANS_STMT_BEGIN:
2107  tag = "BEGIN";
2108  break;
2109 
2110  case TRANS_STMT_START:
2111  tag = "START TRANSACTION";
2112  break;
2113 
2114  case TRANS_STMT_COMMIT:
2115  tag = "COMMIT";
2116  break;
2117 
2118  case TRANS_STMT_ROLLBACK:
2120  tag = "ROLLBACK";
2121  break;
2122 
2123  case TRANS_STMT_SAVEPOINT:
2124  tag = "SAVEPOINT";
2125  break;
2126 
2127  case TRANS_STMT_RELEASE:
2128  tag = "RELEASE";
2129  break;
2130 
2131  case TRANS_STMT_PREPARE:
2132  tag = "PREPARE TRANSACTION";
2133  break;
2134 
2136  tag = "COMMIT PREPARED";
2137  break;
2138 
2140  tag = "ROLLBACK PREPARED";
2141  break;
2142 
2143  default:
2144  tag = "???";
2145  break;
2146  }
2147  }
2148  break;
2149 
2150  case T_DeclareCursorStmt:
2151  tag = "DECLARE CURSOR";
2152  break;
2153 
2154  case T_ClosePortalStmt:
2155  {
2156  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
2157 
2158  if (stmt->portalname == NULL)
2159  tag = "CLOSE CURSOR ALL";
2160  else
2161  tag = "CLOSE CURSOR";
2162  }
2163  break;
2164 
2165  case T_FetchStmt:
2166  {
2167  FetchStmt *stmt = (FetchStmt *) parsetree;
2168 
2169  tag = (stmt->ismove) ? "MOVE" : "FETCH";
2170  }
2171  break;
2172 
2173  case T_CreateDomainStmt:
2174  tag = "CREATE DOMAIN";
2175  break;
2176 
2177  case T_CreateSchemaStmt:
2178  tag = "CREATE SCHEMA";
2179  break;
2180 
2181  case T_CreateStmt:
2182  tag = "CREATE TABLE";
2183  break;
2184 
2186  tag = "CREATE TABLESPACE";
2187  break;
2188 
2189  case T_DropTableSpaceStmt:
2190  tag = "DROP TABLESPACE";
2191  break;
2192 
2194  tag = "ALTER TABLESPACE";
2195  break;
2196 
2197  case T_CreateExtensionStmt:
2198  tag = "CREATE EXTENSION";
2199  break;
2200 
2201  case T_AlterExtensionStmt:
2202  tag = "ALTER EXTENSION";
2203  break;
2204 
2206  tag = "ALTER EXTENSION";
2207  break;
2208 
2209  case T_CreateFdwStmt:
2210  tag = "CREATE FOREIGN DATA WRAPPER";
2211  break;
2212 
2213  case T_AlterFdwStmt:
2214  tag = "ALTER FOREIGN DATA WRAPPER";
2215  break;
2216 
2218  tag = "CREATE SERVER";
2219  break;
2220 
2222  tag = "ALTER SERVER";
2223  break;
2224 
2226  tag = "CREATE USER MAPPING";
2227  break;
2228 
2230  tag = "ALTER USER MAPPING";
2231  break;
2232 
2233  case T_DropUserMappingStmt:
2234  tag = "DROP USER MAPPING";
2235  break;
2236 
2238  tag = "CREATE FOREIGN TABLE";
2239  break;
2240 
2242  tag = "IMPORT FOREIGN SCHEMA";
2243  break;
2244 
2245  case T_DropStmt:
2246  switch (((DropStmt *) parsetree)->removeType)
2247  {
2248  case OBJECT_TABLE:
2249  tag = "DROP TABLE";
2250  break;
2251  case OBJECT_SEQUENCE:
2252  tag = "DROP SEQUENCE";
2253  break;
2254  case OBJECT_VIEW:
2255  tag = "DROP VIEW";
2256  break;
2257  case OBJECT_MATVIEW:
2258  tag = "DROP MATERIALIZED VIEW";
2259  break;
2260  case OBJECT_INDEX:
2261  tag = "DROP INDEX";
2262  break;
2263  case OBJECT_TYPE:
2264  tag = "DROP TYPE";
2265  break;
2266  case OBJECT_DOMAIN:
2267  tag = "DROP DOMAIN";
2268  break;
2269  case OBJECT_COLLATION:
2270  tag = "DROP COLLATION";
2271  break;
2272  case OBJECT_CONVERSION:
2273  tag = "DROP CONVERSION";
2274  break;
2275  case OBJECT_SCHEMA:
2276  tag = "DROP SCHEMA";
2277  break;
2278  case OBJECT_TSPARSER:
2279  tag = "DROP TEXT SEARCH PARSER";
2280  break;
2281  case OBJECT_TSDICTIONARY:
2282  tag = "DROP TEXT SEARCH DICTIONARY";
2283  break;
2284  case OBJECT_TSTEMPLATE:
2285  tag = "DROP TEXT SEARCH TEMPLATE";
2286  break;
2288  tag = "DROP TEXT SEARCH CONFIGURATION";
2289  break;
2290  case OBJECT_FOREIGN_TABLE:
2291  tag = "DROP FOREIGN TABLE";
2292  break;
2293  case OBJECT_EXTENSION:
2294  tag = "DROP EXTENSION";
2295  break;
2296  case OBJECT_FUNCTION:
2297  tag = "DROP FUNCTION";
2298  break;
2299  case OBJECT_PROCEDURE:
2300  tag = "DROP PROCEDURE";
2301  break;
2302  case OBJECT_ROUTINE:
2303  tag = "DROP ROUTINE";
2304  break;
2305  case OBJECT_AGGREGATE:
2306  tag = "DROP AGGREGATE";
2307  break;
2308  case OBJECT_OPERATOR:
2309  tag = "DROP OPERATOR";
2310  break;
2311  case OBJECT_LANGUAGE:
2312  tag = "DROP LANGUAGE";
2313  break;
2314  case OBJECT_CAST:
2315  tag = "DROP CAST";
2316  break;
2317  case OBJECT_TRIGGER:
2318  tag = "DROP TRIGGER";
2319  break;
2320  case OBJECT_EVENT_TRIGGER:
2321  tag = "DROP EVENT TRIGGER";
2322  break;
2323  case OBJECT_RULE:
2324  tag = "DROP RULE";
2325  break;
2326  case OBJECT_FDW:
2327  tag = "DROP FOREIGN DATA WRAPPER";
2328  break;
2329  case OBJECT_FOREIGN_SERVER:
2330  tag = "DROP SERVER";
2331  break;
2332  case OBJECT_OPCLASS:
2333  tag = "DROP OPERATOR CLASS";
2334  break;
2335  case OBJECT_OPFAMILY:
2336  tag = "DROP OPERATOR FAMILY";
2337  break;
2338  case OBJECT_POLICY:
2339  tag = "DROP POLICY";
2340  break;
2341  case OBJECT_TRANSFORM:
2342  tag = "DROP TRANSFORM";
2343  break;
2344  case OBJECT_ACCESS_METHOD:
2345  tag = "DROP ACCESS METHOD";
2346  break;
2347  case OBJECT_PUBLICATION:
2348  tag = "DROP PUBLICATION";
2349  break;
2350  case OBJECT_STATISTIC_EXT:
2351  tag = "DROP STATISTICS";
2352  break;
2353  default:
2354  tag = "???";
2355  }
2356  break;
2357 
2358  case T_TruncateStmt:
2359  tag = "TRUNCATE TABLE";
2360  break;
2361 
2362  case T_CommentStmt:
2363  tag = "COMMENT";
2364  break;
2365 
2366  case T_SecLabelStmt:
2367  tag = "SECURITY LABEL";
2368  break;
2369 
2370  case T_CopyStmt:
2371  tag = "COPY";
2372  break;
2373 
2374  case T_RenameStmt:
2375  tag = AlterObjectTypeCommandTag(((RenameStmt *) parsetree)->renameType);
2376  break;
2377 
2379  tag = AlterObjectTypeCommandTag(((AlterObjectDependsStmt *) parsetree)->objectType);
2380  break;
2381 
2383  tag = AlterObjectTypeCommandTag(((AlterObjectSchemaStmt *) parsetree)->objectType);
2384  break;
2385 
2386  case T_AlterOwnerStmt:
2387  tag = AlterObjectTypeCommandTag(((AlterOwnerStmt *) parsetree)->objectType);
2388  break;
2389 
2391  tag = AlterObjectTypeCommandTag(((AlterTableMoveAllStmt *) parsetree)->objtype);
2392  break;
2393 
2394  case T_AlterTableStmt:
2395  tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->relkind);
2396  break;
2397 
2398  case T_AlterDomainStmt:
2399  tag = "ALTER DOMAIN";
2400  break;
2401 
2402  case T_AlterFunctionStmt:
2403  switch (((AlterFunctionStmt *) parsetree)->objtype)
2404  {
2405  case OBJECT_FUNCTION:
2406  tag = "ALTER FUNCTION";
2407  break;
2408  case OBJECT_PROCEDURE:
2409  tag = "ALTER PROCEDURE";
2410  break;
2411  case OBJECT_ROUTINE:
2412  tag = "ALTER ROUTINE";
2413  break;
2414  default:
2415  tag = "???";
2416  }
2417  break;
2418 
2419  case T_GrantStmt:
2420  {
2421  GrantStmt *stmt = (GrantStmt *) parsetree;
2422 
2423  tag = (stmt->is_grant) ? "GRANT" : "REVOKE";
2424  }
2425  break;
2426 
2427  case T_GrantRoleStmt:
2428  {
2429  GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;
2430 
2431  tag = (stmt->is_grant) ? "GRANT ROLE" : "REVOKE ROLE";
2432  }
2433  break;
2434 
2436  tag = "ALTER DEFAULT PRIVILEGES";
2437  break;
2438 
2439  case T_DefineStmt:
2440  switch (((DefineStmt *) parsetree)->kind)
2441  {
2442  case OBJECT_AGGREGATE:
2443  tag = "CREATE AGGREGATE";
2444  break;
2445  case OBJECT_OPERATOR:
2446  tag = "CREATE OPERATOR";
2447  break;
2448  case OBJECT_TYPE:
2449  tag = "CREATE TYPE";
2450  break;
2451  case OBJECT_TSPARSER:
2452  tag = "CREATE TEXT SEARCH PARSER";
2453  break;
2454  case OBJECT_TSDICTIONARY:
2455  tag = "CREATE TEXT SEARCH DICTIONARY";
2456  break;
2457  case OBJECT_TSTEMPLATE:
2458  tag = "CREATE TEXT SEARCH TEMPLATE";
2459  break;
2461  tag = "CREATE TEXT SEARCH CONFIGURATION";
2462  break;
2463  case OBJECT_COLLATION:
2464  tag = "CREATE COLLATION";
2465  break;
2466  case OBJECT_ACCESS_METHOD:
2467  tag = "CREATE ACCESS METHOD";
2468  break;
2469  default:
2470  tag = "???";
2471  }
2472  break;
2473 
2474  case T_CompositeTypeStmt:
2475  tag = "CREATE TYPE";
2476  break;
2477 
2478  case T_CreateEnumStmt:
2479  tag = "CREATE TYPE";
2480  break;
2481 
2482  case T_CreateRangeStmt:
2483  tag = "CREATE TYPE";
2484  break;
2485 
2486  case T_AlterEnumStmt:
2487  tag = "ALTER TYPE";
2488  break;
2489 
2490  case T_ViewStmt:
2491  tag = "CREATE VIEW";
2492  break;
2493 
2494  case T_CreateFunctionStmt:
2495  if (((CreateFunctionStmt *) parsetree)->is_procedure)
2496  tag = "CREATE PROCEDURE";
2497  else
2498  tag = "CREATE FUNCTION";
2499  break;
2500 
2501  case T_IndexStmt:
2502  tag = "CREATE INDEX";
2503  break;
2504 
2505  case T_RuleStmt:
2506  tag = "CREATE RULE";
2507  break;
2508 
2509  case T_CreateSeqStmt:
2510  tag = "CREATE SEQUENCE";
2511  break;
2512 
2513  case T_AlterSeqStmt:
2514  tag = "ALTER SEQUENCE";
2515  break;
2516 
2517  case T_DoStmt:
2518  tag = "DO";
2519  break;
2520 
2521  case T_CreatedbStmt:
2522  tag = "CREATE DATABASE";
2523  break;
2524 
2525  case T_AlterDatabaseStmt:
2526  tag = "ALTER DATABASE";
2527  break;
2528 
2530  tag = "ALTER DATABASE";
2531  break;
2532 
2533  case T_DropdbStmt:
2534  tag = "DROP DATABASE";
2535  break;
2536 
2537  case T_NotifyStmt:
2538  tag = "NOTIFY";
2539  break;
2540 
2541  case T_ListenStmt:
2542  tag = "LISTEN";
2543  break;
2544 
2545  case T_UnlistenStmt:
2546  tag = "UNLISTEN";
2547  break;
2548 
2549  case T_LoadStmt:
2550  tag = "LOAD";
2551  break;
2552 
2553  case T_CallStmt:
2554  tag = "CALL";
2555  break;
2556 
2557  case T_ClusterStmt:
2558  tag = "CLUSTER";
2559  break;
2560 
2561  case T_VacuumStmt:
2562  if (((VacuumStmt *) parsetree)->options & VACOPT_VACUUM)
2563  tag = "VACUUM";
2564  else
2565  tag = "ANALYZE";
2566  break;
2567 
2568  case T_ExplainStmt:
2569  tag = "EXPLAIN";
2570  break;
2571 
2572  case T_CreateTableAsStmt:
2573  switch (((CreateTableAsStmt *) parsetree)->relkind)
2574  {
2575  case OBJECT_TABLE:
2576  if (((CreateTableAsStmt *) parsetree)->is_select_into)
2577  tag = "SELECT INTO";
2578  else
2579  tag = "CREATE TABLE AS";
2580  break;
2581  case OBJECT_MATVIEW:
2582  tag = "CREATE MATERIALIZED VIEW";
2583  break;
2584  default:
2585  tag = "???";
2586  }
2587  break;
2588 
2589  case T_RefreshMatViewStmt:
2590  tag = "REFRESH MATERIALIZED VIEW";
2591  break;
2592 
2593  case T_AlterSystemStmt:
2594  tag = "ALTER SYSTEM";
2595  break;
2596 
2597  case T_VariableSetStmt:
2598  switch (((VariableSetStmt *) parsetree)->kind)
2599  {
2600  case VAR_SET_VALUE:
2601  case VAR_SET_CURRENT:
2602  case VAR_SET_DEFAULT:
2603  case VAR_SET_MULTI:
2604  tag = "SET";
2605  break;
2606  case VAR_RESET:
2607  case VAR_RESET_ALL:
2608  tag = "RESET";
2609  break;
2610  default:
2611  tag = "???";
2612  }
2613  break;
2614 
2615  case T_VariableShowStmt:
2616  tag = "SHOW";
2617  break;
2618 
2619  case T_DiscardStmt:
2620  switch (((DiscardStmt *) parsetree)->target)
2621  {
2622  case DISCARD_ALL:
2623  tag = "DISCARD ALL";
2624  break;
2625  case DISCARD_PLANS:
2626  tag = "DISCARD PLANS";
2627  break;
2628  case DISCARD_TEMP:
2629  tag = "DISCARD TEMP";
2630  break;
2631  case DISCARD_SEQUENCES:
2632  tag = "DISCARD SEQUENCES";
2633  break;
2634  default:
2635  tag = "???";
2636  }
2637  break;
2638 
2639  case T_CreateTransformStmt:
2640  tag = "CREATE TRANSFORM";
2641  break;
2642 
2643  case T_CreateTrigStmt:
2644  tag = "CREATE TRIGGER";
2645  break;
2646 
2647  case T_CreateEventTrigStmt:
2648  tag = "CREATE EVENT TRIGGER";
2649  break;
2650 
2651  case T_AlterEventTrigStmt:
2652  tag = "ALTER EVENT TRIGGER";
2653  break;
2654 
2655  case T_CreatePLangStmt:
2656  tag = "CREATE LANGUAGE";
2657  break;
2658 
2659  case T_CreateRoleStmt:
2660  tag = "CREATE ROLE";
2661  break;
2662 
2663  case T_AlterRoleStmt:
2664  tag = "ALTER ROLE";
2665  break;
2666 
2667  case T_AlterRoleSetStmt:
2668  tag = "ALTER ROLE";
2669  break;
2670 
2671  case T_DropRoleStmt:
2672  tag = "DROP ROLE";
2673  break;
2674 
2675  case T_DropOwnedStmt:
2676  tag = "DROP OWNED";
2677  break;
2678 
2679  case T_ReassignOwnedStmt:
2680  tag = "REASSIGN OWNED";
2681  break;
2682 
2683  case T_LockStmt:
2684  tag = "LOCK TABLE";
2685  break;
2686 
2687  case T_ConstraintsSetStmt:
2688  tag = "SET CONSTRAINTS";
2689  break;
2690 
2691  case T_CheckPointStmt:
2692  tag = "CHECKPOINT";
2693  break;
2694 
2695  case T_ReindexStmt:
2696  tag = "REINDEX";
2697  break;
2698 
2700  tag = "CREATE CONVERSION";
2701  break;
2702 
2703  case T_CreateCastStmt:
2704  tag = "CREATE CAST";
2705  break;
2706 
2707  case T_CreateOpClassStmt:
2708  tag = "CREATE OPERATOR CLASS";
2709  break;
2710 
2711  case T_CreateOpFamilyStmt:
2712  tag = "CREATE OPERATOR FAMILY";
2713  break;
2714 
2715  case T_AlterOpFamilyStmt:
2716  tag = "ALTER OPERATOR FAMILY";
2717  break;
2718 
2719  case T_AlterOperatorStmt:
2720  tag = "ALTER OPERATOR";
2721  break;
2722 
2724  tag = "ALTER TEXT SEARCH DICTIONARY";
2725  break;
2726 
2728  tag = "ALTER TEXT SEARCH CONFIGURATION";
2729  break;
2730 
2731  case T_CreatePolicyStmt:
2732  tag = "CREATE POLICY";
2733  break;
2734 
2735  case T_AlterPolicyStmt:
2736  tag = "ALTER POLICY";
2737  break;
2738 
2739  case T_CreateAmStmt:
2740  tag = "CREATE ACCESS METHOD";
2741  break;
2742 
2744  tag = "CREATE PUBLICATION";
2745  break;
2746 
2748  tag = "ALTER PUBLICATION";
2749  break;
2750 
2752  tag = "CREATE SUBSCRIPTION";
2753  break;
2754 
2756  tag = "ALTER SUBSCRIPTION";
2757  break;
2758 
2760  tag = "DROP SUBSCRIPTION";
2761  break;
2762 
2763  case T_AlterCollationStmt:
2764  tag = "ALTER COLLATION";
2765  break;
2766 
2767  case T_PrepareStmt:
2768  tag = "PREPARE";
2769  break;
2770 
2771  case T_ExecuteStmt:
2772  tag = "EXECUTE";
2773  break;
2774 
2775  case T_CreateStatsStmt:
2776  tag = "CREATE STATISTICS";
2777  break;
2778 
2779  case T_DeallocateStmt:
2780  {
2781  DeallocateStmt *stmt = (DeallocateStmt *) parsetree;
2782 
2783  if (stmt->name == NULL)
2784  tag = "DEALLOCATE ALL";
2785  else
2786  tag = "DEALLOCATE";
2787  }
2788  break;
2789 
2790  /* already-planned queries */
2791  case T_PlannedStmt:
2792  {
2793  PlannedStmt *stmt = (PlannedStmt *) parsetree;
2794 
2795  switch (stmt->commandType)
2796  {
2797  case CMD_SELECT:
2798 
2799  /*
2800  * We take a little extra care here so that the result
2801  * will be useful for complaints about read-only
2802  * statements
2803  */
2804  if (stmt->rowMarks != NIL)
2805  {
2806  /* not 100% but probably close enough */
2807  switch (((PlanRowMark *) linitial(stmt->rowMarks))->strength)
2808  {
2809  case LCS_FORKEYSHARE:
2810  tag = "SELECT FOR KEY SHARE";
2811  break;
2812  case LCS_FORSHARE:
2813  tag = "SELECT FOR SHARE";
2814  break;
2815  case LCS_FORNOKEYUPDATE:
2816  tag = "SELECT FOR NO KEY UPDATE";
2817  break;
2818  case LCS_FORUPDATE:
2819  tag = "SELECT FOR UPDATE";
2820  break;
2821  default:
2822  tag = "SELECT";
2823  break;
2824  }
2825  }
2826  else
2827  tag = "SELECT";
2828  break;
2829  case CMD_UPDATE:
2830  tag = "UPDATE";
2831  break;
2832  case CMD_INSERT:
2833  tag = "INSERT";
2834  break;
2835  case CMD_DELETE:
2836  tag = "DELETE";
2837  break;
2838  case CMD_UTILITY:
2839  tag = CreateCommandTag(stmt->utilityStmt);
2840  break;
2841  default:
2842  elog(WARNING, "unrecognized commandType: %d",
2843  (int) stmt->commandType);
2844  tag = "???";
2845  break;
2846  }
2847  }
2848  break;
2849 
2850  /* parsed-and-rewritten-but-not-planned queries */
2851  case T_Query:
2852  {
2853  Query *stmt = (Query *) parsetree;
2854 
2855  switch (stmt->commandType)
2856  {
2857  case CMD_SELECT:
2858 
2859  /*
2860  * We take a little extra care here so that the result
2861  * will be useful for complaints about read-only
2862  * statements
2863  */
2864  if (stmt->rowMarks != NIL)
2865  {
2866  /* not 100% but probably close enough */
2867  switch (((RowMarkClause *) linitial(stmt->rowMarks))->strength)
2868  {
2869  case LCS_FORKEYSHARE:
2870  tag = "SELECT FOR KEY SHARE";
2871  break;
2872  case LCS_FORSHARE:
2873  tag = "SELECT FOR SHARE";
2874  break;
2875  case LCS_FORNOKEYUPDATE:
2876  tag = "SELECT FOR NO KEY UPDATE";
2877  break;
2878  case LCS_FORUPDATE:
2879  tag = "SELECT FOR UPDATE";
2880  break;
2881  default:
2882  tag = "???";
2883  break;
2884  }
2885  }
2886  else
2887  tag = "SELECT";
2888  break;
2889  case CMD_UPDATE:
2890  tag = "UPDATE";
2891  break;
2892  case CMD_INSERT:
2893  tag = "INSERT";
2894  break;
2895  case CMD_DELETE:
2896  tag = "DELETE";
2897  break;
2898  case CMD_UTILITY:
2899  tag = CreateCommandTag(stmt->utilityStmt);
2900  break;
2901  default:
2902  elog(WARNING, "unrecognized commandType: %d",
2903  (int) stmt->commandType);
2904  tag = "???";
2905  break;
2906  }
2907  }
2908  break;
2909 
2910  default:
2911  elog(WARNING, "unrecognized node type: %d",
2912  (int) nodeTag(parsetree));
2913  tag = "???";
2914  break;
2915  }
2916 
2917  return tag;
2918 }
#define NIL
Definition: pg_list.h:69
List * rowMarks
Definition: parsenodes.h:161
Node * utilityStmt
Definition: parsenodes.h:118
#define linitial(l)
Definition: pg_list.h:111
Node * utilityStmt
Definition: plannodes.h:94
const char * CreateCommandTag(Node *parsetree)
Definition: utility.c:2071
bool is_grant
Definition: parsenodes.h:1867
#define WARNING
Definition: elog.h:40
Definition: nodes.h:305
bool ismove
Definition: parsenodes.h:2690
CmdType commandType
Definition: plannodes.h:45
List * rowMarks
Definition: plannodes.h:86
CmdType commandType
Definition: parsenodes.h:110
#define nodeTag(nodeptr)
Definition: nodes.h:518
#define elog
Definition: elog.h:219
static const char * AlterObjectTypeCommandTag(ObjectType objtype)
Definition: utility.c:1922
TransactionStmtKind kind
Definition: parsenodes.h:2965

◆ ExecDropStmt()

static void ExecDropStmt ( DropStmt stmt,
bool  isTopLevel 
)
static

Definition at line 1711 of file utility.c.

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

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

1712 {
1713  switch (stmt->removeType)
1714  {
1715  case OBJECT_INDEX:
1716  if (stmt->concurrent)
1717  PreventTransactionChain(isTopLevel,
1718  "DROP INDEX CONCURRENTLY");
1719  /* fall through */
1720 
1721  case OBJECT_TABLE:
1722  case OBJECT_SEQUENCE:
1723  case OBJECT_VIEW:
1724  case OBJECT_MATVIEW:
1725  case OBJECT_FOREIGN_TABLE:
1726  RemoveRelations(stmt);
1727  break;
1728  default:
1729  RemoveObjects(stmt);
1730  break;
1731  }
1732 }
void RemoveObjects(DropStmt *stmt)
Definition: dropcmds.c:55
ObjectType removeType
Definition: parsenodes.h:2587
void RemoveRelations(DropStmt *drop)
Definition: tablecmds.c:1069
bool concurrent
Definition: parsenodes.h:2590
void PreventTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3154

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

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

2932 {
2933  LogStmtLevel lev;
2934 
2935  switch (nodeTag(parsetree))
2936  {
2937  /* recurse if we're given a RawStmt */
2938  case T_RawStmt:
2939  lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
2940  break;
2941 
2942  /* raw plannable queries */
2943  case T_InsertStmt:
2944  case T_DeleteStmt:
2945  case T_UpdateStmt:
2946  lev = LOGSTMT_MOD;
2947  break;
2948 
2949  case T_SelectStmt:
2950  if (((SelectStmt *) parsetree)->intoClause)
2951  lev = LOGSTMT_DDL; /* SELECT INTO */
2952  else
2953  lev = LOGSTMT_ALL;
2954  break;
2955 
2956  /* utility statements --- same whether raw or cooked */
2957  case T_TransactionStmt:
2958  lev = LOGSTMT_ALL;
2959  break;
2960 
2961  case T_DeclareCursorStmt:
2962  lev = LOGSTMT_ALL;
2963  break;
2964 
2965  case T_ClosePortalStmt:
2966  lev = LOGSTMT_ALL;
2967  break;
2968 
2969  case T_FetchStmt:
2970  lev = LOGSTMT_ALL;
2971  break;
2972 
2973  case T_CreateSchemaStmt:
2974  lev = LOGSTMT_DDL;
2975  break;
2976 
2977  case T_CreateStmt:
2979  lev = LOGSTMT_DDL;
2980  break;
2981 
2983  case T_DropTableSpaceStmt:
2985  lev = LOGSTMT_DDL;
2986  break;
2987 
2988  case T_CreateExtensionStmt:
2989  case T_AlterExtensionStmt:
2991  lev = LOGSTMT_DDL;
2992  break;
2993 
2994  case T_CreateFdwStmt:
2995  case T_AlterFdwStmt:
3000  case T_DropUserMappingStmt:
3002  lev = LOGSTMT_DDL;
3003  break;
3004 
3005  case T_DropStmt:
3006  lev = LOGSTMT_DDL;
3007  break;
3008 
3009  case T_TruncateStmt:
3010  lev = LOGSTMT_MOD;
3011  break;
3012 
3013  case T_CommentStmt:
3014  lev = LOGSTMT_DDL;
3015  break;
3016 
3017  case T_SecLabelStmt:
3018  lev = LOGSTMT_DDL;
3019  break;
3020 
3021  case T_CopyStmt:
3022  if (((CopyStmt *) parsetree)->is_from)
3023  lev = LOGSTMT_MOD;
3024  else
3025  lev = LOGSTMT_ALL;
3026  break;
3027 
3028  case T_PrepareStmt:
3029  {
3030  PrepareStmt *stmt = (PrepareStmt *) parsetree;
3031 
3032  /* Look through a PREPARE to the contained stmt */
3033  lev = GetCommandLogLevel(stmt->query);
3034  }
3035  break;
3036 
3037  case T_ExecuteStmt:
3038  {
3039  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
3040  PreparedStatement *ps;
3041 
3042  /* Look through an EXECUTE to the referenced stmt */
3043  ps = FetchPreparedStatement(stmt->name, false);
3044  if (ps && ps->plansource->raw_parse_tree)
3046  else
3047  lev = LOGSTMT_ALL;
3048  }
3049  break;
3050 
3051  case T_DeallocateStmt:
3052  lev = LOGSTMT_ALL;
3053  break;
3054 
3055  case T_RenameStmt:
3056  lev = LOGSTMT_DDL;
3057  break;
3058 
3060  lev = LOGSTMT_DDL;
3061  break;
3062 
3064  lev = LOGSTMT_DDL;
3065  break;
3066 
3067  case T_AlterOwnerStmt:
3068  lev = LOGSTMT_DDL;
3069  break;
3070 
3071  case T_AlterOperatorStmt:
3072  lev = LOGSTMT_DDL;
3073  break;
3074 
3076  case T_AlterTableStmt:
3077  lev = LOGSTMT_DDL;
3078  break;
3079 
3080  case T_AlterDomainStmt:
3081  lev = LOGSTMT_DDL;
3082  break;
3083 
3084  case T_GrantStmt:
3085  lev = LOGSTMT_DDL;
3086  break;
3087 
3088  case T_GrantRoleStmt:
3089  lev = LOGSTMT_DDL;
3090  break;
3091 
3093  lev = LOGSTMT_DDL;
3094  break;
3095 
3096  case T_DefineStmt:
3097  lev = LOGSTMT_DDL;
3098  break;
3099 
3100  case T_CompositeTypeStmt:
3101  lev = LOGSTMT_DDL;
3102  break;
3103 
3104  case T_CreateEnumStmt:
3105  lev = LOGSTMT_DDL;
3106  break;
3107 
3108  case T_CreateRangeStmt:
3109  lev = LOGSTMT_DDL;
3110  break;
3111 
3112  case T_AlterEnumStmt:
3113  lev = LOGSTMT_DDL;
3114  break;
3115 
3116  case T_ViewStmt:
3117  lev = LOGSTMT_DDL;
3118  break;
3119 
3120  case T_CreateFunctionStmt:
3121  lev = LOGSTMT_DDL;
3122  break;
3123 
3124  case T_AlterFunctionStmt:
3125  lev = LOGSTMT_DDL;
3126  break;
3127 
3128  case T_IndexStmt:
3129  lev = LOGSTMT_DDL;
3130  break;
3131 
3132  case T_RuleStmt:
3133  lev = LOGSTMT_DDL;
3134  break;
3135 
3136  case T_CreateSeqStmt:
3137  lev = LOGSTMT_DDL;
3138  break;
3139 
3140  case T_AlterSeqStmt:
3141  lev = LOGSTMT_DDL;
3142  break;
3143 
3144  case T_DoStmt:
3145  lev = LOGSTMT_ALL;
3146  break;
3147 
3148  case T_CreatedbStmt:
3149  lev = LOGSTMT_DDL;
3150  break;
3151 
3152  case T_AlterDatabaseStmt:
3153  lev = LOGSTMT_DDL;
3154  break;
3155 
3157  lev = LOGSTMT_DDL;
3158  break;
3159 
3160  case T_DropdbStmt:
3161  lev = LOGSTMT_DDL;
3162  break;
3163 
3164  case T_NotifyStmt:
3165  lev = LOGSTMT_ALL;
3166  break;
3167 
3168  case T_ListenStmt:
3169  lev = LOGSTMT_ALL;
3170  break;
3171 
3172  case T_UnlistenStmt:
3173  lev = LOGSTMT_ALL;
3174  break;
3175 
3176  case T_LoadStmt:
3177  lev = LOGSTMT_ALL;
3178  break;
3179 
3180  case T_CallStmt:
3181  lev = LOGSTMT_ALL;
3182  break;
3183 
3184  case T_ClusterStmt:
3185  lev = LOGSTMT_DDL;
3186  break;
3187 
3188  case T_VacuumStmt:
3189  lev = LOGSTMT_ALL;
3190  break;
3191 
3192  case T_ExplainStmt:
3193  {
3194  ExplainStmt *stmt = (ExplainStmt *) parsetree;
3195  bool analyze = false;
3196  ListCell *lc;
3197 
3198  /* Look through an EXPLAIN ANALYZE to the contained stmt */
3199  foreach(lc, stmt->options)
3200  {
3201  DefElem *opt = (DefElem *) lfirst(lc);
3202 
3203  if (strcmp(opt->defname, "analyze") == 0)
3204  analyze = defGetBoolean(opt);
3205  /* don't "break", as explain.c will use the last value */
3206  }
3207  if (analyze)
3208  return GetCommandLogLevel(stmt->query);
3209 
3210  /* Plain EXPLAIN isn't so interesting */
3211  lev = LOGSTMT_ALL;
3212  }
3213  break;
3214 
3215  case T_CreateTableAsStmt:
3216  lev = LOGSTMT_DDL;
3217  break;
3218 
3219  case T_RefreshMatViewStmt:
3220  lev = LOGSTMT_DDL;
3221  break;
3222 
3223  case T_AlterSystemStmt:
3224  lev = LOGSTMT_DDL;
3225  break;
3226 
3227  case T_VariableSetStmt:
3228  lev = LOGSTMT_ALL;
3229  break;
3230 
3231  case T_VariableShowStmt:
3232  lev = LOGSTMT_ALL;
3233  break;
3234 
3235  case T_DiscardStmt:
3236  lev = LOGSTMT_ALL;
3237  break;
3238 
3239  case T_CreateTrigStmt:
3240  lev = LOGSTMT_DDL;
3241  break;
3242 
3243  case T_CreateEventTrigStmt:
3244  lev = LOGSTMT_DDL;
3245  break;
3246 
3247  case T_AlterEventTrigStmt:
3248  lev = LOGSTMT_DDL;
3249  break;
3250 
3251  case T_CreatePLangStmt:
3252  lev = LOGSTMT_DDL;
3253  break;
3254 
3255  case T_CreateDomainStmt:
3256  lev = LOGSTMT_DDL;
3257  break;
3258 
3259  case T_CreateRoleStmt:
3260  lev = LOGSTMT_DDL;
3261  break;
3262 
3263  case T_AlterRoleStmt:
3264  lev = LOGSTMT_DDL;
3265  break;
3266 
3267  case T_AlterRoleSetStmt:
3268  lev = LOGSTMT_DDL;
3269  break;
3270 
3271  case T_DropRoleStmt:
3272  lev = LOGSTMT_DDL;
3273  break;
3274 
3275  case T_DropOwnedStmt:
3276  lev = LOGSTMT_DDL;
3277  break;
3278 
3279  case T_ReassignOwnedStmt:
3280  lev = LOGSTMT_DDL;
3281  break;
3282 
3283  case T_LockStmt:
3284  lev = LOGSTMT_ALL;
3285  break;
3286 
3287  case T_ConstraintsSetStmt:
3288  lev = LOGSTMT_ALL;
3289  break;
3290 
3291  case T_CheckPointStmt:
3292  lev = LOGSTMT_ALL;
3293  break;
3294 
3295  case T_ReindexStmt:
3296  lev = LOGSTMT_ALL; /* should this be DDL? */
3297  break;
3298 
3300  lev = LOGSTMT_DDL;
3301  break;
3302 
3303  case T_CreateCastStmt:
3304  lev = LOGSTMT_DDL;
3305  break;
3306 
3307  case T_CreateOpClassStmt:
3308  lev = LOGSTMT_DDL;
3309  break;
3310 
3311  case T_CreateOpFamilyStmt:
3312  lev = LOGSTMT_DDL;
3313  break;
3314 
3315  case T_CreateTransformStmt:
3316  lev = LOGSTMT_DDL;
3317  break;
3318 
3319  case T_AlterOpFamilyStmt:
3320  lev = LOGSTMT_DDL;
3321  break;
3322 
3323  case T_CreatePolicyStmt:
3324  lev = LOGSTMT_DDL;
3325  break;
3326 
3327  case T_AlterPolicyStmt:
3328  lev = LOGSTMT_DDL;
3329  break;
3330 
3332  lev = LOGSTMT_DDL;
3333  break;
3334 
3336  lev = LOGSTMT_DDL;
3337  break;
3338 
3339  case T_CreateAmStmt:
3340  lev = LOGSTMT_DDL;
3341  break;
3342 
3344  lev = LOGSTMT_DDL;
3345  break;
3346 
3348  lev = LOGSTMT_DDL;
3349  break;
3350 
3352  lev = LOGSTMT_DDL;
3353  break;
3354 
3356  lev = LOGSTMT_DDL;
3357  break;
3358 
3360  lev = LOGSTMT_DDL;
3361  break;
3362 
3363  case T_CreateStatsStmt:
3364  lev = LOGSTMT_DDL;
3365  break;
3366 
3367  case T_AlterCollationStmt:
3368  lev = LOGSTMT_DDL;
3369  break;
3370 
3371  /* already-planned queries */
3372  case T_PlannedStmt:
3373  {
3374  PlannedStmt *stmt = (PlannedStmt *) parsetree;
3375 
3376  switch (stmt->commandType)
3377  {
3378  case CMD_SELECT:
3379  lev = LOGSTMT_ALL;
3380  break;
3381 
3382  case CMD_UPDATE:
3383  case CMD_INSERT:
3384  case CMD_DELETE:
3385  lev = LOGSTMT_MOD;
3386  break;
3387 
3388  case CMD_UTILITY:
3389  lev = GetCommandLogLevel(stmt->utilityStmt);
3390  break;
3391 
3392  default:
3393  elog(WARNING, "unrecognized commandType: %d",
3394  (int) stmt->commandType);
3395  lev = LOGSTMT_ALL;
3396  break;
3397  }
3398  }
3399  break;
3400 
3401  /* parsed-and-rewritten-but-not-planned queries */
3402  case T_Query:
3403  {
3404  Query *stmt = (Query *) parsetree;
3405 
3406  switch (stmt->commandType)
3407  {
3408  case CMD_SELECT:
3409  lev = LOGSTMT_ALL;
3410  break;
3411 
3412  case CMD_UPDATE:
3413  case CMD_INSERT:
3414  case CMD_DELETE:
3415  lev = LOGSTMT_MOD;
3416  break;
3417 
3418  case CMD_UTILITY:
3419  lev = GetCommandLogLevel(stmt->utilityStmt);
3420  break;
3421 
3422  default:
3423  elog(WARNING, "unrecognized commandType: %d",
3424  (int) stmt->commandType);
3425  lev = LOGSTMT_ALL;
3426  break;
3427  }
3428 
3429  }
3430  break;
3431 
3432  default:
3433  elog(WARNING, "unrecognized node type: %d",
3434  (int) nodeTag(parsetree));
3435  lev = LOGSTMT_ALL;
3436  break;
3437  }
3438 
3439  return lev;
3440 }
CachedPlanSource * plansource
Definition: prepare.h:31
LogStmtLevel
Definition: tcopprot.h:40
List * options
Definition: parsenodes.h:3166
Node * utilityStmt
Definition: parsenodes.h:118
Node * query
Definition: parsenodes.h:3165
bool defGetBoolean(DefElem *def)
Definition: define.c:111
Node * stmt
Definition: parsenodes.h:1447
Node * utilityStmt
Definition: plannodes.h:94
#define WARNING
Definition: elog.h:40
Definition: nodes.h:305
CmdType commandType
Definition: plannodes.h:45
CmdType commandType
Definition: parsenodes.h:110
#define lfirst(lc)
Definition: pg_list.h:106
Node * query
Definition: parsenodes.h:3333
struct RawStmt * raw_parse_tree
Definition: plancache.h:83
#define nodeTag(nodeptr)
Definition: nodes.h:518
char * name
Definition: parsenodes.h:3345
char * defname
Definition: parsenodes.h:727
#define elog
Definition: elog.h:219
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:495
static long analyze(struct nfa *nfa)
Definition: regc_nfa.c:2816
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:2931

◆ PreventCommandDuringRecovery()

void PreventCommandDuringRecovery ( const char *  cmdname)

Definition at line 274 of file utility.c.

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

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

275 {
276  if (RecoveryInProgress())
277  ereport(ERROR,
278  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
279  /* translator: %s is name of a SQL command, eg CREATE */
280  errmsg("cannot execute %s during recovery",
281  cmdname)));
282 }
int errcode(int sqlerrcode)
Definition: elog.c:575
bool RecoveryInProgress(void)
Definition: xlog.c:7919
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ PreventCommandIfParallelMode()

void PreventCommandIfParallelMode ( const char *  cmdname)

Definition at line 255 of file utility.c.

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

Referenced by _SPI_execute_plan(), check_xact_readonly(), do_setval(), DoCopy(), ExecCheckXactReadOnly(), init_execution_state(), nextval_internal(), and SPI_cursor_open_internal().

256 {
257  if (IsInParallelMode())
258  ereport(ERROR,
259  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
260  /* translator: %s is name of a SQL command, eg CREATE */
261  errmsg("cannot execute %s during a parallel operation",
262  cmdname)));
263 }
int errcode(int sqlerrcode)
Definition: elog.c:575
bool IsInParallelMode(void)
Definition: xact.c:906
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ PreventCommandIfReadOnly()

void PreventCommandIfReadOnly ( const char *  cmdname)

Definition at line 237 of file utility.c.

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

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

238 {
239  if (XactReadOnly)
240  ereport(ERROR,
241  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
242  /* translator: %s is name of a SQL command, eg CREATE */
243  errmsg("cannot execute %s in a read-only transaction",
244  cmdname)));
245 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool XactReadOnly
Definition: xact.c:77
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ ProcessUtility()

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

Definition at line 336 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(), and ProcessUtilitySlow().

343 {
344  Assert(IsA(pstmt, PlannedStmt));
345  Assert(pstmt->commandType == CMD_UTILITY);
346  Assert(queryString != NULL); /* required as of 8.4 */
347 
348  /*
349  * We provide a function hook variable that lets loadable plugins get
350  * control when ProcessUtility is called. Such a plugin would normally
351  * call standard_ProcessUtility().
352  */
354  (*ProcessUtility_hook) (pstmt, queryString,
355  context, params, queryEnv,
356  dest, completionTag);
357  else
358  standard_ProcessUtility(pstmt, queryString,
359  context, params, queryEnv,
360  dest, completionTag);
361 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:564
ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:74
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.c:375
CmdType commandType
Definition: plannodes.h:45
#define Assert(condition)
Definition: c.h:688

◆ 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 950 of file utility.c.

References AlterCollation(), AlterDomainAddConstraint(), AlterDomainDefault(), AlterDomainDropConstraint(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEnum(), AlterForeignDataWrapper(), AlterForeignServer(), AlterFunction(), AlterOperator(), AlterOpFamily(), AlterPolicy(), AlterPublication(), AlterSequence(), 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, 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(), heap_close, heap_open(), HEAP_RELOPT_NAMESPACES, heap_reloptions(), DefineStmt::if_not_exists, ImportForeignSchema(), RangeVar::inh, InvalidObjectAddress, InvalidOid, IsA, DefineStmt::kind, lfirst, list_free(), lnext, makeNode, AlterDomainStmt::missing_ok, AlterDomainStmt::name, NewRelationCreateToastTable(), NIL, nodeTag, NoLock, None_Receiver, NOTICE, OBJECT_AGGREGATE, OBJECT_COLLATION, OBJECT_OPERATOR, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, ObjectAddress::objectId, OidIsValid, DefineStmt::oldstyle, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PreventTransactionChain(), PROCESS_UTILITY_QUERY, PROCESS_UTILITY_SUBCOMMAND, PROCESS_UTILITY_TOPLEVEL, ProcessUtility(), RangeVarCallbackOwnsRelation(), RangeVarGetRelidExtended(), RelationData::rd_rel, AlterTableStmt::relation, IndexStmt::relation, RELKIND_FOREIGN_TABLE, RELKIND_PARTITIONED_TABLE, RELKIND_RELATION, RELKIND_TOASTVALUE, RangeVar::relname, RemoveUserMapping(), 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_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, transformAlterTableStmt(), transformCreateStmt(), transformIndexStmt(), transformRelOptions(), AlterDomainStmt::typeName, CompositeTypeStmt::typevar, and PlannedStmt::utilityStmt.

Referenced by standard_ProcessUtility().

958 {
959  Node *parsetree = pstmt->utilityStmt;
960  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
961  bool isCompleteQuery = (context <= PROCESS_UTILITY_QUERY);
962  bool needCleanup;
963  bool commandCollected = false;
964  ObjectAddress address;
965  ObjectAddress secondaryObject = InvalidObjectAddress;
966 
967  /* All event trigger calls are done only when isCompleteQuery is true */
968  needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
969 
970  /* PG_TRY block is to ensure we call EventTriggerEndCompleteQuery */
971  PG_TRY();
972  {
973  if (isCompleteQuery)
974  EventTriggerDDLCommandStart(parsetree);
975 
976  switch (nodeTag(parsetree))
977  {
978  /*
979  * relation and attribute manipulation
980  */
981  case T_CreateSchemaStmt:
983  queryString,
984  pstmt->stmt_location,
985  pstmt->stmt_len);
986 
987  /*
988  * EventTriggerCollectSimpleCommand called by
989  * CreateSchemaCommand
990  */
991  commandCollected = true;
992  break;
993 
994  case T_CreateStmt:
996  {
997  List *stmts;
998  ListCell *l;
999 
1000  /* Run parse analysis ... */
1001  stmts = transformCreateStmt((CreateStmt *) parsetree,
1002  queryString);
1003 
1004  /* ... and do it */
1005  foreach(l, stmts)
1006  {
1007  Node *stmt = (Node *) lfirst(l);
1008 
1009  if (IsA(stmt, CreateStmt))
1010  {
1011  Datum toast_options;
1012  static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
1013 
1014  /* Create the table itself */
1015  address = DefineRelation((CreateStmt *) stmt,
1017  InvalidOid, NULL,
1018  queryString);
1020  secondaryObject,
1021  stmt);
1022 
1023  /*
1024  * Let NewRelationCreateToastTable decide if this
1025  * one needs a secondary relation too.
1026  */
1028 
1029  /*
1030  * parse and validate reloptions for the toast
1031  * table
1032  */
1033  toast_options = transformRelOptions((Datum) 0,
1034  ((CreateStmt *) stmt)->options,
1035  "toast",
1036  validnsps,
1037  true,
1038  false);
1040  toast_options,
1041  true);
1042 
1044  toast_options);
1045  }
1046  else if (IsA(stmt, CreateForeignTableStmt))
1047  {
1048  /* Create the table itself */
1049  address = DefineRelation((CreateStmt *) stmt,
1051  InvalidOid, NULL,
1052  queryString);
1054  address.objectId);
1056  secondaryObject,
1057  stmt);
1058  }
1059  else
1060  {
1061  /*
1062  * Recurse for anything else. Note the recursive
1063  * call will stash the objects so created into our
1064  * event trigger context.
1065  */
1066  PlannedStmt *wrapper;
1067 
1068  wrapper = makeNode(PlannedStmt);
1069  wrapper->commandType = CMD_UTILITY;
1070  wrapper->canSetTag = false;
1071  wrapper->utilityStmt = stmt;
1072  wrapper->stmt_location = pstmt->stmt_location;
1073  wrapper->stmt_len = pstmt->stmt_len;
1074 
1075  ProcessUtility(wrapper,
1076  queryString,
1078  params,
1079  NULL,
1080  None_Receiver,
1081  NULL);
1082  }
1083 
1084  /* Need CCI between commands */
1085  if (lnext(l) != NULL)
1087  }
1088 
1089  /*
1090  * The multiple commands generated here are stashed
1091  * individually, so disable collection below.
1092  */
1093  commandCollected = true;
1094  }
1095  break;
1096 
1097  case T_AlterTableStmt:
1098  {
1099  AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
1100  Oid relid;
1101  List *stmts;
1102  ListCell *l;
1103  LOCKMODE lockmode;
1104 
1105  /*
1106  * Figure out lock mode, and acquire lock. This also does
1107  * basic permissions checks, so that we won't wait for a
1108  * lock on (for example) a relation on which we have no
1109  * permissions.
1110  */
1111  lockmode = AlterTableGetLockLevel(atstmt->cmds);
1112  relid = AlterTableLookupRelation(atstmt, lockmode);
1113 
1114  if (OidIsValid(relid))
1115  {
1116  /* Run parse analysis ... */
1117  stmts = transformAlterTableStmt(relid, atstmt,
1118  queryString);
1119 
1120  /* ... ensure we have an event trigger context ... */
1121  EventTriggerAlterTableStart(parsetree);
1123 
1124  /* ... and do it */
1125  foreach(l, stmts)
1126  {
1127  Node *stmt = (Node *) lfirst(l);
1128 
1129  if (IsA(stmt, AlterTableStmt))
1130  {
1131  /* Do the table alteration proper */
1132  AlterTable(relid, lockmode,
1133  (AlterTableStmt *) stmt);
1134  }
1135  else
1136  {
1137  /*
1138  * Recurse for anything else. If we need to
1139  * do so, "close" the current complex-command
1140  * set, and start a new one at the bottom;
1141  * this is needed to ensure the ordering of
1142  * queued commands is consistent with the way
1143  * they are executed here.
1144  */
1145  PlannedStmt *wrapper;
1146 
1148  wrapper = makeNode(PlannedStmt);
1149  wrapper->commandType = CMD_UTILITY;
1150  wrapper->canSetTag = false;
1151  wrapper->utilityStmt = stmt;
1152  wrapper->stmt_location = pstmt->stmt_location;
1153  wrapper->stmt_len = pstmt->stmt_len;
1154  ProcessUtility(wrapper,
1155  queryString,
1157  params,
1158  NULL,
1159  None_Receiver,
1160  NULL);
1161  EventTriggerAlterTableStart(parsetree);
1163  }
1164 
1165  /* Need CCI between commands */
1166  if (lnext(l) != NULL)
1168  }
1169 
1170  /* done */
1172  }
1173  else
1174  ereport(NOTICE,
1175  (errmsg("relation \"%s\" does not exist, skipping",
1176  atstmt->relation->relname)));
1177  }
1178 
1179  /* ALTER TABLE stashes commands internally */
1180  commandCollected = true;
1181  break;
1182 
1183  case T_AlterDomainStmt:
1184  {
1185  AlterDomainStmt *stmt = (AlterDomainStmt *) parsetree;
1186 
1187  /*
1188  * Some or all of these functions are recursive to cover
1189  * inherited things, so permission checks are done there.
1190  */
1191  switch (stmt->subtype)
1192  {
1193  case 'T': /* ALTER DOMAIN DEFAULT */
1194 
1195  /*
1196  * Recursively alter column default for table and,
1197  * if requested, for descendants
1198  */
1199  address =
1201  stmt->def);
1202  break;
1203  case 'N': /* ALTER DOMAIN DROP NOT NULL */
1204  address =
1206  false);
1207  break;
1208  case 'O': /* ALTER DOMAIN SET NOT NULL */
1209  address =
1211  true);
1212  break;
1213  case 'C': /* ADD CONSTRAINT */
1214  address =
1216  stmt->def,
1217  &secondaryObject);
1218  break;
1219  case 'X': /* DROP CONSTRAINT */
1220  address =
1222  stmt->name,
1223  stmt->behavior,
1224  stmt->missing_ok);
1225  break;
1226  case 'V': /* VALIDATE CONSTRAINT */
1227  address =
1229  stmt->name);
1230  break;
1231  default: /* oops */
1232  elog(ERROR, "unrecognized alter domain type: %d",
1233  (int) stmt->subtype);
1234  break;
1235  }
1236  }
1237  break;
1238 
1239  /*
1240  * ************* object creation / destruction **************
1241  */
1242  case T_DefineStmt:
1243  {
1244  DefineStmt *stmt = (DefineStmt *) parsetree;
1245 
1246  switch (stmt->kind)
1247  {
1248  case OBJECT_AGGREGATE:
1249  address =
1250  DefineAggregate(pstate, stmt->defnames, stmt->args,
1251  stmt->oldstyle,
1252  stmt->definition);
1253  break;
1254  case OBJECT_OPERATOR:
1255  Assert(stmt->args == NIL);
1256  address = DefineOperator(stmt->defnames,
1257  stmt->definition);
1258  break;
1259  case OBJECT_TYPE:
1260  Assert(stmt->args == NIL);
1261  address = DefineType(pstate,
1262  stmt->defnames,
1263  stmt->definition);
1264  break;
1265  case OBJECT_TSPARSER:
1266  Assert(stmt->args == NIL);
1267  address = DefineTSParser(stmt->defnames,
1268  stmt->definition);
1269  break;
1270  case OBJECT_TSDICTIONARY:
1271  Assert(stmt->args == NIL);
1272  address = DefineTSDictionary(stmt->defnames,
1273  stmt->definition);
1274  break;
1275  case OBJECT_TSTEMPLATE:
1276  Assert(stmt->args == NIL);
1277  address = DefineTSTemplate(stmt->defnames,
1278  stmt->definition);
1279  break;
1281  Assert(stmt->args == NIL);
1282  address = DefineTSConfiguration(stmt->defnames,
1283  stmt->definition,
1284  &secondaryObject);
1285  break;
1286  case OBJECT_COLLATION:
1287  Assert(stmt->args == NIL);
1288  address = DefineCollation(pstate,
1289  stmt->defnames,
1290  stmt->definition,
1291  stmt->if_not_exists);
1292  break;
1293  default:
1294  elog(ERROR, "unrecognized define stmt type: %d",
1295  (int) stmt->kind);
1296  break;
1297  }
1298  }
1299  break;
1300 
1301  case T_IndexStmt: /* CREATE INDEX */
1302  {
1303  IndexStmt *stmt = (IndexStmt *) parsetree;
1304  Oid relid;
1305  LOCKMODE lockmode;
1306  List *inheritors = NIL;
1307 
1308  if (stmt->concurrent)
1309  PreventTransactionChain(isTopLevel,
1310  "CREATE INDEX CONCURRENTLY");
1311 
1312  /*
1313  * Look up the relation OID just once, right here at the
1314  * beginning, so that we don't end up repeating the name
1315  * lookup later and latching onto a different relation
1316  * partway through. To avoid lock upgrade hazards, it's
1317  * important that we take the strongest lock that will
1318  * eventually be needed here, so the lockmode calculation
1319  * needs to match what DefineIndex() does.
1320  */
1321  lockmode = stmt->concurrent ? ShareUpdateExclusiveLock
1322  : ShareLock;
1323  relid =
1324  RangeVarGetRelidExtended(stmt->relation, lockmode,
1325  false, false,
1327  NULL);
1328 
1329  /*
1330  * CREATE INDEX on partitioned tables (but not regular
1331  * inherited tables) recurses to partitions, so we must
1332  * acquire locks early to avoid deadlocks.
1333  */
1334  if (stmt->relation->inh)
1335  {
1336  Relation rel;
1337 
1338  /* already locked by RangeVarGetRelidExtended */
1339  rel = heap_open(relid, NoLock);
1340  if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
1341  inheritors = find_all_inheritors(relid, lockmode,
1342  NULL);
1343  heap_close(rel, NoLock);
1344  }
1345 
1346  /* Run parse analysis ... */
1347  stmt = transformIndexStmt(relid, stmt, queryString);
1348 
1349  /* ... and do it */
1350  EventTriggerAlterTableStart(parsetree);
1351  address =
1352  DefineIndex(relid, /* OID of heap relation */
1353  stmt,
1354  InvalidOid, /* no predefined OID */
1355  InvalidOid, /* no parent index */
1356  InvalidOid, /* no parent constraint */
1357  false, /* is_alter_table */
1358  true, /* check_rights */
1359  true, /* check_not_in_use */
1360  false, /* skip_build */
1361  false); /* quiet */
1362 
1363  /*
1364  * Add the CREATE INDEX node itself to stash right away;
1365  * if there were any commands stashed in the ALTER TABLE
1366  * code, we need them to appear after this one.
1367  */
1368  EventTriggerCollectSimpleCommand(address, secondaryObject,
1369  parsetree);
1370  commandCollected = true;
1372 
1373  list_free(inheritors);
1374  }
1375  break;
1376 
1377  case T_CreateExtensionStmt:
1378  address = CreateExtension(pstate, (CreateExtensionStmt *) parsetree);
1379  break;
1380 
1381  case T_AlterExtensionStmt:
1382  address = ExecAlterExtensionStmt(pstate, (AlterExtensionStmt *) parsetree);
1383  break;
1384 
1387  &secondaryObject);
1388  break;
1389 
1390  case T_CreateFdwStmt:
1391  address = CreateForeignDataWrapper((CreateFdwStmt *) parsetree);
1392  break;
1393 
1394  case T_AlterFdwStmt:
1395  address = AlterForeignDataWrapper((AlterFdwStmt *) parsetree);
1396  break;
1397 
1399  address = CreateForeignServer((CreateForeignServerStmt *) parsetree);
1400  break;
1401 
1403  address = AlterForeignServer((AlterForeignServerStmt *) parsetree);
1404  break;
1405 
1407  address = CreateUserMapping((CreateUserMappingStmt *) parsetree);
1408  break;
1409 
1411  address = AlterUserMapping((AlterUserMappingStmt *) parsetree);
1412  break;
1413 
1414  case T_DropUserMappingStmt:
1415  RemoveUserMapping((DropUserMappingStmt *) parsetree);
1416  /* no commands stashed for DROP */
1417  commandCollected = true;
1418  break;
1419 
1422  /* commands are stashed inside ImportForeignSchema */
1423  commandCollected = true;
1424  break;
1425 
1426  case T_CompositeTypeStmt: /* CREATE TYPE (composite) */
1427  {
1428  CompositeTypeStmt *stmt = (CompositeTypeStmt *) parsetree;
1429 
1430  address = DefineCompositeType(stmt->typevar,
1431  stmt->coldeflist);
1432  }
1433  break;
1434 
1435  case T_CreateEnumStmt: /* CREATE TYPE AS ENUM */
1436  address = DefineEnum((CreateEnumStmt *) parsetree);
1437  break;
1438 
1439  case T_CreateRangeStmt: /* CREATE TYPE AS RANGE */
1440  address = DefineRange((CreateRangeStmt *) parsetree);
1441  break;
1442 
1443  case T_AlterEnumStmt: /* ALTER TYPE (enum) */
1444  address = AlterEnum((AlterEnumStmt *) parsetree, isTopLevel);
1445  break;
1446 
1447  case T_ViewStmt: /* CREATE VIEW */
1448  EventTriggerAlterTableStart(parsetree);
1449  address = DefineView((ViewStmt *) parsetree, queryString,
1450  pstmt->stmt_location, pstmt->stmt_len);
1451  EventTriggerCollectSimpleCommand(address, secondaryObject,
1452  parsetree);
1453  /* stashed internally */
1454  commandCollected = true;
1456  break;
1457 
1458  case T_CreateFunctionStmt: /* CREATE FUNCTION */
1459  address = CreateFunction(pstate, (CreateFunctionStmt *) parsetree);
1460  break;
1461 
1462  case T_AlterFunctionStmt: /* ALTER FUNCTION */
1463  address = AlterFunction(pstate, (AlterFunctionStmt *) parsetree);
1464  break;
1465 
1466  case T_RuleStmt: /* CREATE RULE */
1467  address = DefineRule((RuleStmt *) parsetree, queryString);
1468  break;
1469 
1470  case T_CreateSeqStmt:
1471  address = DefineSequence(pstate, (CreateSeqStmt *) parsetree);
1472  break;
1473 
1474  case T_AlterSeqStmt:
1475  address = AlterSequence(pstate, (AlterSeqStmt *) parsetree);
1476  break;
1477 
1478  case T_CreateTableAsStmt:
1479  address = ExecCreateTableAs((CreateTableAsStmt *) parsetree,
1480  queryString, params, queryEnv,
1481  completionTag);
1482  break;
1483 
1484  case T_RefreshMatViewStmt:
1485 
1486  /*
1487  * REFRESH CONCURRENTLY executes some DDL commands internally.
1488  * Inhibit DDL command collection here to avoid those commands
1489  * from showing up in the deparsed command queue. The refresh
1490  * command itself is queued, which is enough.
1491  */
1493  PG_TRY();
1494  {
1495  address = ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
1496  queryString, params, completionTag);
1497  }
1498  PG_CATCH();
1499  {
1501  PG_RE_THROW();
1502  }
1503  PG_END_TRY();
1505  break;
1506 
1507  case T_CreateTrigStmt:
1508  address = CreateTrigger((CreateTrigStmt *) parsetree,
1509  queryString, InvalidOid, InvalidOid,
1510  InvalidOid, InvalidOid, false);
1511  break;
1512 
1513  case T_CreatePLangStmt:
1514  address = CreateProceduralLanguage((CreatePLangStmt *) parsetree);
1515  break;
1516 
1517  case T_CreateDomainStmt:
1518  address = DefineDomain((CreateDomainStmt *) parsetree);
1519  break;
1520 
1522  address = CreateConversionCommand((CreateConversionStmt *) parsetree);
1523  break;
1524 
1525  case T_CreateCastStmt:
1526  address = CreateCast((CreateCastStmt *) parsetree);
1527  break;
1528 
1529  case T_CreateOpClassStmt:
1530  DefineOpClass((CreateOpClassStmt *) parsetree);
1531  /* command is stashed in DefineOpClass */
1532  commandCollected = true;
1533  break;
1534 
1535  case T_CreateOpFamilyStmt:
1536  address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1537  break;
1538 
1539  case T_CreateTransformStmt:
1540  address = CreateTransform((CreateTransformStmt *) parsetree);
1541  break;
1542 
1543  case T_AlterOpFamilyStmt:
1544  AlterOpFamily((AlterOpFamilyStmt *) parsetree);
1545  /* commands are stashed in AlterOpFamily */
1546  commandCollected = true;
1547  break;
1548 
1550  address = AlterTSDictionary((AlterTSDictionaryStmt *) parsetree);
1551  break;
1552 
1555 
1556  /*
1557  * Commands are stashed in MakeConfigurationMapping and
1558  * DropConfigurationMapping, which are called from
1559  * AlterTSConfiguration
1560  */
1561  commandCollected = true;
1562  break;
1563 
1566  /* commands are stashed in AlterTableMoveAll */
1567  commandCollected = true;
1568  break;
1569 
1570  case T_DropStmt:
1571  ExecDropStmt((DropStmt *) parsetree, isTopLevel);
1572  /* no commands stashed for DROP */
1573  commandCollected = true;
1574  break;
1575 
1576  case T_RenameStmt:
1577  address = ExecRenameStmt((RenameStmt *) parsetree);
1578  break;
1579 
1581  address =
1583  &secondaryObject);
1584  break;
1585 
1587  address =
1589  &secondaryObject);
1590  break;
1591 
1592  case T_AlterOwnerStmt:
1593  address = ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
1594  break;
1595 
1596  case T_AlterOperatorStmt:
1597  address = AlterOperator((AlterOperatorStmt *) parsetree);
1598  break;
1599 
1600  case T_CommentStmt:
1601  address = CommentObject((CommentStmt *) parsetree);
1602  break;
1603 
1604  case T_GrantStmt:
1605  ExecuteGrantStmt((GrantStmt *) parsetree);
1606  /* commands are stashed in ExecGrantStmt_oids */
1607  commandCollected = true;
1608  break;
1609 
1610  case T_DropOwnedStmt:
1611  DropOwnedObjects((DropOwnedStmt *) parsetree);
1612  /* no commands stashed for DROP */
1613  commandCollected = true;
1614  break;
1615 
1619  commandCollected = true;
1620  break;
1621 
1622  case T_CreatePolicyStmt: /* CREATE POLICY */
1623  address = CreatePolicy((CreatePolicyStmt *) parsetree);
1624  break;
1625 
1626  case T_AlterPolicyStmt: /* ALTER POLICY */
1627  address = AlterPolicy((AlterPolicyStmt *) parsetree);
1628  break;
1629 
1630  case T_SecLabelStmt:
1631  address = ExecSecLabelStmt((SecLabelStmt *) parsetree);
1632  break;
1633 
1634  case T_CreateAmStmt:
1635  address = CreateAccessMethod((CreateAmStmt *) parsetree);
1636  break;
1637 
1639  address = CreatePublication((CreatePublicationStmt *) parsetree);
1640  break;
1641 
1643  AlterPublication((AlterPublicationStmt *) parsetree);
1644 
1645  /*
1646  * AlterPublication calls EventTriggerCollectSimpleCommand
1647  * directly
1648  */
1649  commandCollected = true;
1650  break;
1651 
1653  address = CreateSubscription((CreateSubscriptionStmt *) parsetree,
1654  isTopLevel);
1655  break;
1656 
1658  address = AlterSubscription((AlterSubscriptionStmt *) parsetree);
1659  break;
1660 
1662  DropSubscription((DropSubscriptionStmt *) parsetree, isTopLevel);
1663  /* no commands stashed for DROP */
1664  commandCollected = true;
1665  break;
1666 
1667  case T_CreateStatsStmt:
1668  address = CreateStatistics((CreateStatsStmt *) parsetree);
1669  break;
1670 
1671  case T_AlterCollationStmt:
1672  address = AlterCollation((AlterCollationStmt *) parsetree);
1673  break;
1674 
1675  default:
1676  elog(ERROR, "unrecognized node type: %d",
1677  (int) nodeTag(parsetree));
1678  break;
1679  }
1680 
1681  /*
1682  * Remember the object so that ddl_command_end event triggers have
1683  * access to it.
1684  */
1685  if (!commandCollected)
1686  EventTriggerCollectSimpleCommand(address, secondaryObject,
1687  parsetree);
1688 
1689  if (isCompleteQuery)
1690  {
1691  EventTriggerSQLDrop(parsetree);
1692  EventTriggerDDLCommandEnd(parsetree);
1693  }
1694  }
1695  PG_CATCH();
1696  {
1697  if (needCleanup)
1699  PG_RE_THROW();
1700  }
1701  PG_END_TRY();
1702 
1703  if (needCleanup)
1705 }
ObjectAddress AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
Definition: sequence.c:416
ObjectAddress DefineTSParser(List *names, List *parameters)
Definition: tsearchcmds.c:176
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1420
#define NIL
Definition: pg_list.h:69
ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt)
Definition: foreigncmds.c:985
void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid)
Definition: foreigncmds.c:1446
void DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
ObjectAddress DefineOperator(List *names, List *parameters)
Definition: operatorcmds.c:68
ObjectAddress AlterSubscription(AlterSubscriptionStmt *stmt)
#define IsA(nodeptr, _type_)
Definition: nodes.h:564
ObjectAddress DefineTSConfiguration(List *names, List *parameters, ObjectAddress *copied)
Definition: tsearchcmds.c:960
ObjectAddress CreateTransform(CreateTransformStmt *stmt)
ObjectAddress AlterEnum(AlterEnumStmt *stmt, bool isTopLevel)
Definition: typecmds.c:1279
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1711
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:319
ObjectAddress AlterDomainAddConstraint(List *names, Node *newConstraint, ObjectAddress *constrAddr)
Definition: typecmds.c:2543
ObjectAddress CreateForeignDataWrapper(CreateFdwStmt *stmt)
Definition: foreigncmds.c:560
DropBehavior behavior
Definition: parsenodes.h:1848
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
Definition: functioncmds.c:862
int LOCKMODE
Definition: lockdefs.h:26
ObjectAddress CreatePublication(CreatePublicationStmt *stmt)
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:44
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok, bool nowait, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:218
Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
Definition: tablecmds.c:3145
ObjectAddress AlterDomainValidateConstraint(List *names, const char *constrName)
Definition: typecmds.c:2652
ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, bool isInternal)
Definition: trigger.c:141
void DropOwnedObjects(DropOwnedStmt *stmt)
Definition: user.c:1333
RangeVar * typevar
Definition: parsenodes.h:2977
void EventTriggerDDLCommandEnd(Node *parsetree)
Definition: nodes.h:513
ObjectAddress ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt, ObjectAddress *objAddr)
Definition: extension.c:3171
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.c:336
ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt)
Definition: proclang.c:64
void EventTriggerInhibitCommandCollection(void)
ObjectAddress DefineDomain(CreateDomainStmt *stmt)
Definition: typecmds.c:729
ObjectAddress DefineCompositeType(RangeVar *typevar, List *coldeflist)
Definition: typecmds.c:2140
#define heap_close(r, l)
Definition: heapam.h:97
void AlterTable(Oid relid, LOCKMODE lockmode, AlterTableStmt *stmt)
Definition: tablecmds.c:3195
Form_pg_class rd_rel
Definition: rel.h:114
unsigned int Oid
Definition: postgres_ext.h:31
ObjectAddress DefineOpClass(CreateOpClassStmt *stmt)
Definition: opclasscmds.c:324
DestReceiver * None_Receiver
Definition: dest.c:91
ObjectAddress CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
void NewRelationCreateToastTable(Oid relOid, Datum reloptions)
Definition: toasting.c:71
#define OidIsValid(objectId)
Definition: c.h:594
int stmt_len
Definition: plannodes.h:98
Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, char *validnsps[], bool ignoreOids, bool isReset)
Definition: reloptions.c:755
void EventTriggerAlterTableStart(Node *parsetree)
char * relname
Definition: primnodes.h:68
ObjectAddress DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List *parameters)
Definition: aggregatecmds.c:58
RangeVar * relation
Definition: parsenodes.h:2712
ObjectAddress AlterPolicy(AlterPolicyStmt *stmt)
Definition: policy.c:878
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
Definition: tablecmds.c:13202
List * args
Definition: parsenodes.h:2504
#define ERROR
Definition: elog.h:43
ObjectAddress AlterDomainDefault(List *names, Node *defaultRaw)
Definition: typecmds.c:2198
ObjectAddress AlterOperator(AlterOperatorStmt *stmt)
Definition: operatorcmds.c:385
void EventTriggerDDLCommandStart(Node *parsetree)
ObjectAddress CreatePolicy(CreatePolicyStmt *stmt)
Definition: policy.c:683
void EventTriggerSQLDrop(Node *parsetree)
ObjectAddress AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
Definition: tsearchcmds.c:1173
ObjectAddress AlterDomainNotNull(List *names, bool notNull)
Definition: typecmds.c:2337
Oid RemoveUserMapping(DropUserMappingStmt *stmt)
Definition: foreigncmds.c:1345
ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt)
Definition: foreigncmds.c:1135
int stmt_location
Definition: plannodes.h:97
#define NoLock
Definition: lockdefs.h:34
List * transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, const char *queryString)
ObjectAddress AlterTSDictionary(AlterTSDictionaryStmt *stmt)
Definition: tsearchcmds.c:525
Node * utilityStmt
Definition: plannodes.h:94
ObjectAddress DefineRange(CreateRangeStmt *stmt)
Definition: typecmds.c:1370
ObjectAddress DefineEnum(CreateEnumStmt *stmt)
Definition: typecmds.c:1157
ObjectAddress DefineView(ViewStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: view.c:417
Oid CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: schemacmds.c:51
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
#define HEAP_RELOPT_NAMESPACES
Definition: reloptions.h:59
ObjectAddress AlterUserMapping(AlterUserMappingStmt *stmt)
Definition: foreigncmds.c:1250
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition: alter.c:325
ObjectAddress DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
Definition: sequence.c:116
#define lnext(lc)
Definition: pg_list.h:105
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
Definition: tablecmds.c:517
#define ereport(elevel, rest)
Definition: elog.h:122
void ExecAlterDefaultPrivilegesStmt(ParseState *pstate, AlterDefaultPrivilegesStmt *stmt)
Definition: aclchk.c:913
ObjectAddress DefineType(ParseState *pstate, List *names, List *parameters)
Definition: typecmds.c:116
bool inh
Definition: primnodes.h:69
ObjectAddress CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt)
Definition: extension.c:1621
void EventTriggerEndCompleteQuery(void)
LOCKMODE AlterTableGetLockLevel(List *cmds)
Definition: tablecmds.c:3264
ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt)
Definition: foreigncmds.c:861
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
bool canSetTag
Definition: plannodes.h:53
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
void EventTriggerUndoInhibitCommandCollection(void)
uintptr_t Datum
Definition: postgres.h:365
CmdType commandType
Definition: plannodes.h:45
void CommandCounterIncrement(void)
Definition: xact.c:915
ObjectType kind
Definition: parsenodes.h:2501
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1290
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:425
void EventTriggerCollectAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt)
#define InvalidOid
Definition: postgres_ext.h:36
ObjectAddress DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_exists)
Definition: collationcmds.c:52
List * defnames
Definition: parsenodes.h:2503
#define NOTICE
Definition: elog.h:37
ObjectAddress CreateCast(CreateCastStmt *stmt)
ObjectAddress ExecAlterExtensionStmt(ParseState *pstate, AlterExtensionStmt *stmt)
Definition: extension.c:2863
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:463
#define PG_CATCH()
Definition: elog.h:293
#define makeNode(_type_)
Definition: nodes.h:561
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
ObjectAddress DefineTSDictionary(List *names, List *parameters)
Definition: tsearchcmds.c:409
#define Assert(condition)
Definition: c.h:688
#define lfirst(lc)
Definition: pg_list.h:106
ObjectAddress CreateConversionCommand(CreateConversionStmt *stmt)
Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
Definition: tablecmds.c:10861
ObjectAddress AlterForeignDataWrapper(AlterFdwStmt *stmt)
Definition: foreigncmds.c:673
List * transformCreateStmt(CreateStmt *stmt, const char *queryString)
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition: alter.c:802
#define PG_RE_THROW()
Definition: elog.h:314
#define nodeTag(nodeptr)
Definition: nodes.h:518
void EventTriggerAlterTableRelid(Oid objectId)
Oid AlterOpFamily(AlterOpFamilyStmt *stmt)
Definition: opclasscmds.c:764
ObjectAddress DefineOpFamily(CreateOpFamilyStmt *stmt)
Definition: opclasscmds.c:719
ObjectAddress AlterDomainDropConstraint(List *names, const char *constrName, DropBehavior behavior, bool missing_ok)
Definition: typecmds.c:2453
bool concurrent
Definition: parsenodes.h:2729
ObjectAddress DefineRule(RuleStmt *stmt, const char *queryString)
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
Definition: pg_inherits.c:167
const ObjectAddress InvalidObjectAddress
void ImportForeignSchema(ImportForeignSchemaStmt *stmt)
Definition: foreigncmds.c:1526
int errmsg(const char *fmt,...)
Definition: elog.c:797
RangeVar * relation
Definition: parsenodes.h:1715
void list_free(List *list)
Definition: list.c:1133
ObjectAddress AlterCollation(AlterCollationStmt *stmt)
#define ShareLock
Definition: lockdefs.h:41
ObjectAddress DefineTSTemplate(List *names, List *parameters)
Definition: tsearchcmds.c:729
bool if_not_exists
Definition: parsenodes.h:2506
ObjectAddress ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, ParamListInfo params, char *completionTag)
Definition: matview.c:137
ObjectAddress CreateAccessMethod(CreateAmStmt *stmt)
Definition: amcmds.c:41
ObjectAddress ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, char *completionTag)
Definition: createas.c:224
List * definition
Definition: parsenodes.h:2505
#define elog
Definition: elog.h:219
void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
#define PG_TRY()
Definition: elog.h:284
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
#define RELKIND_RELATION
Definition: pg_class.h:160
Definition: pg_list.h:45
ObjectAddress AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt)
bool oldstyle
Definition: parsenodes.h:2502
#define PG_END_TRY()
Definition: elog.h:300
void AlterPublication(AlterPublicationStmt *stmt)
bool EventTriggerBeginCompleteQuery(void)
void PreventTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3154
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:385
void EventTriggerAlterTableEnd(void)
ObjectAddress CreateStatistics(CreateStatsStmt *stmt)
Definition: statscmds.c:49

◆ standard_ProcessUtility()

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

Definition at line 375 of file utility.c.

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterSystemSetConfigFile(), AlterTableSpaceOptions(), DefElem::arg, Assert, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), BeginTransactionBlock(), castNode, check_xact_readonly(), CHECKPOINT_FORCE, CHECKPOINT_IMMEDIATE, CHECKPOINT_WAIT, CheckRestrictedOperation(), closeAllVfds(), cluster(), CommentObject(), COMPLETION_TAG_BUFSIZE, NotifyStmt::conditionname, ListenStmt::conditionname, UnlistenStmt::conditionname, createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DropdbStmt::dbname, DeallocateQuery(), DefineSavepoint(), DefElem::defname, DiscardCommand(), DoCopy(), dropdb(), 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(), IsTransactionBlock(), TransactionStmt::kind, ReindexStmt::kind, lfirst, list_make1, load_file(), LockTableCommand(), make_parsestate(), DropdbStmt::missing_ok, name, VariableShowStmt::name, ReindexStmt::name, nodeTag, AlterObjectDependsStmt::objectType, AlterObjectSchemaStmt::objectType, AlterOwnerStmt::objectType, GrantStmt::objtype, CommentStmt::objtype, SecLabelStmt::objtype, TransactionStmt::options, VacuumStmt::options, ReindexStmt::options, ParseState::p_sourcetext, NotifyStmt::payload, PerformCursorOpen(), PerformPortalClose(), PerformPortalFetch(), PointerIsValid, ClosePortalStmt::portalname, PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventTransactionChain(), 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(), RequireTransactionChain(), RollbackToSavepoint(), SetPGVariable(), snprintf(), PlannedStmt::stmt_len, PlannedStmt::stmt_location, strVal, 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, VACOPT_VACUUM, and WarnNoTransactionChain().

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

382 {
383  Node *parsetree = pstmt->utilityStmt;
384  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
385  ParseState *pstate;
386 
387  check_xact_readonly(parsetree);
388 
389  if (completionTag)
390  completionTag[0] = '\0';
391 
392  pstate = make_parsestate(NULL);
393  pstate->p_sourcetext = queryString;
394 
395  switch (nodeTag(parsetree))
396  {
397  /*
398  * ******************** transactions ********************
399  */
400  case T_TransactionStmt:
401  {
402  TransactionStmt *stmt = (TransactionStmt *) parsetree;
403 
404  switch (stmt->kind)
405  {
406  /*
407  * START TRANSACTION, as defined by SQL99: Identical
408  * to BEGIN. Same code for both.
409  */
410  case TRANS_STMT_BEGIN:
411  case TRANS_STMT_START:
412  {
413  ListCell *lc;
414 
416  foreach(lc, stmt->options)
417  {
418  DefElem *item = (DefElem *) lfirst(lc);
419 
420  if (strcmp(item->defname, "transaction_isolation") == 0)
421  SetPGVariable("transaction_isolation",
422  list_make1(item->arg),
423  true);
424  else if (strcmp(item->defname, "transaction_read_only") == 0)
425  SetPGVariable("transaction_read_only",
426  list_make1(item->arg),
427  true);
428  else if (strcmp(item->defname, "transaction_deferrable") == 0)
429  SetPGVariable("transaction_deferrable",
430  list_make1(item->arg),
431  true);
432  }
433  }
434  break;
435 
436  case TRANS_STMT_COMMIT:
437  if (!EndTransactionBlock())
438  {
439  /* report unsuccessful commit in completionTag */
440  if (completionTag)
441  strcpy(completionTag, "ROLLBACK");
442  }
443  break;
444 
445  case TRANS_STMT_PREPARE:
446  PreventCommandDuringRecovery("PREPARE TRANSACTION");
447  if (!PrepareTransactionBlock(stmt->gid))
448  {
449  /* report unsuccessful commit in completionTag */
450  if (completionTag)
451  strcpy(completionTag, "ROLLBACK");
452  }
453  break;
454 
456  PreventTransactionChain(isTopLevel, "COMMIT PREPARED");
457  PreventCommandDuringRecovery("COMMIT PREPARED");
458  FinishPreparedTransaction(stmt->gid, true);
459  break;
460 
462  PreventTransactionChain(isTopLevel, "ROLLBACK PREPARED");
463  PreventCommandDuringRecovery("ROLLBACK PREPARED");
464  FinishPreparedTransaction(stmt->gid, false);
465  break;
466 
467  case TRANS_STMT_ROLLBACK:
469  break;
470 
472  {
473  ListCell *cell;
474  char *name = NULL;
475 
476  RequireTransactionChain(isTopLevel, "SAVEPOINT");
477 
478  foreach(cell, stmt->options)
479  {
480  DefElem *elem = lfirst(cell);
481 
482  if (strcmp(elem->defname, "savepoint_name") == 0)
483  name = strVal(elem->arg);
484  }
485 
486  Assert(PointerIsValid(name));
487 
488  DefineSavepoint(name);
489  }
490  break;
491 
492  case TRANS_STMT_RELEASE:
493  RequireTransactionChain(isTopLevel, "RELEASE SAVEPOINT");
494  ReleaseSavepoint(stmt->options);
495  break;
496 
498  RequireTransactionChain(isTopLevel, "ROLLBACK TO SAVEPOINT");
500 
501  /*
502  * CommitTransactionCommand is in charge of
503  * re-defining the savepoint again
504  */
505  break;
506  }
507  }
508  break;
509 
510  /*
511  * Portal (cursor) manipulation
512  */
513  case T_DeclareCursorStmt:
514  PerformCursorOpen((DeclareCursorStmt *) parsetree, params,
515  queryString, isTopLevel);
516  break;
517 
518  case T_ClosePortalStmt:
519  {
520  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
521 
522  CheckRestrictedOperation("CLOSE");
524  }
525  break;
526 
527  case T_FetchStmt:
528  PerformPortalFetch((FetchStmt *) parsetree, dest,
529  completionTag);
530  break;
531 
532  case T_DoStmt:
533  ExecuteDoStmt((DoStmt *) parsetree,
534  (context != PROCESS_UTILITY_TOPLEVEL || IsTransactionBlock()));
535  break;
536 
538  /* no event triggers for global objects */
539  PreventTransactionChain(isTopLevel, "CREATE TABLESPACE");
540  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
541  break;
542 
544  /* no event triggers for global objects */
545  PreventTransactionChain(isTopLevel, "DROP TABLESPACE");
546  DropTableSpace((DropTableSpaceStmt *) parsetree);
547  break;
548 
550  /* no event triggers for global objects */
552  break;
553 
554  case T_TruncateStmt:
555  ExecuteTruncate((TruncateStmt *) parsetree);
556  break;
557 
558  case T_CopyStmt:
559  {
560  uint64 processed;
561 
562  DoCopy(pstate, (CopyStmt *) parsetree,
563  pstmt->stmt_location, pstmt->stmt_len,
564  &processed);
565  if (completionTag)
566  snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
567  "COPY " UINT64_FORMAT, processed);
568  }
569  break;
570 
571  case T_PrepareStmt:
572  CheckRestrictedOperation("PREPARE");
573  PrepareQuery((PrepareStmt *) parsetree, queryString,
574  pstmt->stmt_location, pstmt->stmt_len);
575  break;
576 
577  case T_ExecuteStmt:
578  ExecuteQuery((ExecuteStmt *) parsetree, NULL,
579  queryString, params,
580  dest, completionTag);
581  break;
582 
583  case T_DeallocateStmt:
584  CheckRestrictedOperation("DEALLOCATE");
585  DeallocateQuery((DeallocateStmt *) parsetree);
586  break;
587 
588  case T_GrantRoleStmt:
589  /* no event triggers for global objects */
590  GrantRole((GrantRoleStmt *) parsetree);
591  break;
592 
593  case T_CreatedbStmt:
594  /* no event triggers for global objects */
595  PreventTransactionChain(isTopLevel, "CREATE DATABASE");
596  createdb(pstate, (CreatedbStmt *) parsetree);
597  break;
598 
599  case T_AlterDatabaseStmt:
600  /* no event triggers for global objects */
601  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
602  break;
603 
605  /* no event triggers for global objects */
606  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
607  break;
608 
609  case T_DropdbStmt:
610  {
611  DropdbStmt *stmt = (DropdbStmt *) parsetree;
612 
613  /* no event triggers for global objects */
614  PreventTransactionChain(isTopLevel, "DROP DATABASE");
615  dropdb(stmt->dbname, stmt->missing_ok);
616  }
617  break;
618 
619  /* Query-level asynchronous notification */
620  case T_NotifyStmt:
621  {
622  NotifyStmt *stmt = (NotifyStmt *) parsetree;
623 
625  Async_Notify(stmt->conditionname, stmt->payload);
626  }
627  break;
628 
629  case T_ListenStmt:
630  {
631  ListenStmt *stmt = (ListenStmt *) parsetree;
632 
634  CheckRestrictedOperation("LISTEN");
636  }
637  break;
638 
639  case T_UnlistenStmt:
640  {
641  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
642 
643  PreventCommandDuringRecovery("UNLISTEN");
644  CheckRestrictedOperation("UNLISTEN");
645  if (stmt->conditionname)
647  else
649  }
650  break;
651 
652  case T_LoadStmt:
653  {
654  LoadStmt *stmt = (LoadStmt *) parsetree;
655 
656  closeAllVfds(); /* probably not necessary... */
657  /* Allowed names are restricted if you're not superuser */
658  load_file(stmt->filename, !superuser());
659  }
660  break;
661 
662  case T_CallStmt:
663  ExecuteCallStmt(pstate, castNode(CallStmt, parsetree),
664  (context != PROCESS_UTILITY_TOPLEVEL || IsTransactionBlock()));
665  break;
666 
667  case T_ClusterStmt:
668  /* we choose to allow this during "read only" transactions */
669  PreventCommandDuringRecovery("CLUSTER");
670  /* forbidden in parallel mode due to CommandIsReadOnly */
671  cluster((ClusterStmt *) parsetree, isTopLevel);
672  break;
673 
674  case T_VacuumStmt:
675  {
676  VacuumStmt *stmt = (VacuumStmt *) parsetree;
677 
678  /* we choose to allow this during "read only" transactions */
680  "VACUUM" : "ANALYZE");
681  /* forbidden in parallel mode due to CommandIsReadOnly */
682  ExecVacuum(stmt, isTopLevel);
683  }
684  break;
685 
686  case T_ExplainStmt:
687  ExplainQuery(pstate, (ExplainStmt *) parsetree, queryString, params,
688  queryEnv, dest);
689  break;
690 
691  case T_AlterSystemStmt:
692  PreventTransactionChain(isTopLevel, "ALTER SYSTEM");
694  break;
695 
696  case T_VariableSetStmt:
697  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
698  break;
699 
700  case T_VariableShowStmt:
701  {
702  VariableShowStmt *n = (VariableShowStmt *) parsetree;
703 
704  GetPGVariable(n->name, dest);
705  }
706  break;
707 
708  case T_DiscardStmt:
709  /* should we allow DISCARD PLANS? */
710  CheckRestrictedOperation("DISCARD");
711  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
712  break;
713 
715  /* no event triggers on event triggers */
717  break;
718 
720  /* no event triggers on event triggers */
721  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
722  break;
723 
724  /*
725  * ******************************** ROLE statements ****
726  */
727  case T_CreateRoleStmt:
728  /* no event triggers for global objects */
729  CreateRole(pstate, (CreateRoleStmt *) parsetree);
730  break;
731 
732  case T_AlterRoleStmt:
733  /* no event triggers for global objects */
734  AlterRole((AlterRoleStmt *) parsetree);
735  break;
736 
737  case T_AlterRoleSetStmt:
738  /* no event triggers for global objects */
739  AlterRoleSet((AlterRoleSetStmt *) parsetree);
740  break;
741 
742  case T_DropRoleStmt:
743  /* no event triggers for global objects */
744  DropRole((DropRoleStmt *) parsetree);
745  break;
746 
747  case T_ReassignOwnedStmt:
748  /* no event triggers for global objects */
750  break;
751 
752  case T_LockStmt:
753 
754  /*
755  * Since the lock would just get dropped immediately, LOCK TABLE
756  * outside a transaction block is presumed to be user error.
757  */
758  RequireTransactionChain(isTopLevel, "LOCK TABLE");
759  /* forbidden in parallel mode due to CommandIsReadOnly */
760  LockTableCommand((LockStmt *) parsetree);
761  break;
762 
764  WarnNoTransactionChain(isTopLevel, "SET CONSTRAINTS");
766  break;
767 
768  case T_CheckPointStmt:
769  if (!superuser())
770  ereport(ERROR,
771  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
772  errmsg("must be superuser to do CHECKPOINT")));
773 
774  /*
775  * You might think we should have a PreventCommandDuringRecovery()
776  * here, but we interpret a CHECKPOINT command during recovery as
777  * a request for a restartpoint instead. We allow this since it
778  * can be a useful way of reducing switchover time when using
779  * various forms of replication.
780  */
783  break;
784 
785  case T_ReindexStmt:
786  {
787  ReindexStmt *stmt = (ReindexStmt *) parsetree;
788 
789  /* we choose to allow this during "read only" transactions */
790  PreventCommandDuringRecovery("REINDEX");
791  /* forbidden in parallel mode due to CommandIsReadOnly */
792  switch (stmt->kind)
793  {
795  ReindexIndex(stmt->relation, stmt->options);
796  break;
798  ReindexTable(stmt->relation, stmt->options);
799  break;
803 
804  /*
805  * This cannot run inside a user transaction block; if
806  * we were inside a transaction, then its commit- and
807  * start-transaction-command calls would not have the
808  * intended effect!
809  */
810  PreventTransactionChain(isTopLevel,
811  (stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
812  (stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
813  "REINDEX DATABASE");
814  ReindexMultipleTables(stmt->name, stmt->kind, stmt->options);
815  break;
816  default:
817  elog(ERROR, "unrecognized object type: %d",
818  (int) stmt->kind);
819  break;
820  }
821  }
822  break;
823 
824  /*
825  * The following statements are supported by Event Triggers only
826  * in some cases, so we "fast path" them in the other cases.
827  */
828 
829  case T_GrantStmt:
830  {
831  GrantStmt *stmt = (GrantStmt *) parsetree;
832 
834  ProcessUtilitySlow(pstate, pstmt, queryString,
835  context, params, queryEnv,
836  dest, completionTag);
837  else
838  ExecuteGrantStmt(stmt);
839  }
840  break;
841 
842  case T_DropStmt:
843  {
844  DropStmt *stmt = (DropStmt *) parsetree;
845 
847  ProcessUtilitySlow(pstate, pstmt, queryString,
848  context, params, queryEnv,
849  dest, completionTag);
850  else
851  ExecDropStmt(stmt, isTopLevel);
852  }
853  break;
854 
855  case T_RenameStmt:
856  {
857  RenameStmt *stmt = (RenameStmt *) parsetree;
858 
860  ProcessUtilitySlow(pstate, pstmt, queryString,
861  context, params, queryEnv,
862  dest, completionTag);
863  else
864  ExecRenameStmt(stmt);
865  }
866  break;
867 
869  {
870  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
871 
873  ProcessUtilitySlow(pstate, pstmt, queryString,
874  context, params, queryEnv,
875  dest, completionTag);
876  else
877  ExecAlterObjectDependsStmt(stmt, NULL);
878  }
879  break;
880 
882  {
883  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
884 
886  ProcessUtilitySlow(pstate, pstmt, queryString,
887  context, params, queryEnv,
888  dest, completionTag);
889  else
890  ExecAlterObjectSchemaStmt(stmt, NULL);
891  }
892  break;
893 
894  case T_AlterOwnerStmt:
895  {
896  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
897 
899  ProcessUtilitySlow(pstate, pstmt, queryString,
900  context, params, queryEnv,
901  dest, completionTag);
902  else
903  ExecAlterOwnerStmt(stmt);
904  }
905  break;
906 
907  case T_CommentStmt:
908  {
909  CommentStmt *stmt = (CommentStmt *) parsetree;
910 
912  ProcessUtilitySlow(pstate, pstmt, queryString,
913  context, params, queryEnv,
914  dest, completionTag);
915  else
916  CommentObject(stmt);
917  break;
918  }
919 
920  case T_SecLabelStmt:
921  {
922  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
923 
925  ProcessUtilitySlow(pstate, pstmt, queryString,
926  context, params, queryEnv,
927  dest, completionTag);
928  else
929  ExecSecLabelStmt(stmt);
930  break;
931  }
932 
933  default:
934  /* All other statement types have event trigger support */
935  ProcessUtilitySlow(pstate, pstmt, queryString,
936  context, params, queryEnv,
937  dest, completionTag);
938  break;
939  }
940 
941  free_parsestate(pstate);
942 }
ObjectType objtype
Definition: parsenodes.h:2612
void closeAllVfds(void)
Definition: fd.c:2784
ObjectType objtype
Definition: parsenodes.h:2624
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1711
void PerformPortalClose(const char *name)
Definition: portalcmds.c:216
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectType renameType
Definition: parsenodes.h:2833
Oid ReindexTable(RangeVar *relation, int options)
Definition: indexcmds.c:2178
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:44
#define castNode(_type_, nodeptr)
Definition: nodes.h:582
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:1575
ObjectType objectType
Definition: parsenodes.h:2878
void DefineSavepoint(const char *name)
Definition: xact.c:3827
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:5073
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:292
Definition: nodes.h:513
#define strVal(v)
Definition: value.h:54
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3482
int errcode(int sqlerrcode)
Definition: elog.c:575
void PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params, const char *queryString, bool isTopLevel)
Definition: portalcmds.c:42
bool superuser(void)
Definition: superuser.c:47
char * filename
Definition: parsenodes.h:3047
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
void Async_Listen(const char *channel)
Definition: async.c:638
Oid CreateTableSpace(CreateTableSpaceStmt *stmt)
Definition: tablespace.c:233
bool RecoveryInProgress(void)
Definition: xlog.c:7919
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1314
bool EndTransactionBlock(void)
Definition: xact.c:3534
void ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause, const char *queryString, ParamListInfo params, DestReceiver *dest, char *completionTag)
Definition: prepare.c:200
int stmt_len
Definition: plannodes.h:98
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Definition: user.c:72
ObjectType removeType
Definition: parsenodes.h:2587
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc.c:7941
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:44
void ReindexIndex(RangeVar *indexRelation, int options)
Definition: indexcmds.c:2078
#define list_make1(x1)
Definition: pg_list.h:139
bool IsTransactionBlock(void)
Definition: xact.c:4448
void DeallocateQuery(DeallocateStmt *stmt)
Definition: prepare.c:566
#define ERROR
Definition: elog.h:43
static void ProcessUtilitySlow(ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
Definition: utility.c:950
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:274
void GrantRole(GrantRoleStmt *stmt)
Definition: user.c:1274
void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest, char *completionTag)
Definition: portalcmds.c:168
void ExecuteCallStmt(ParseState *pstate, CallStmt *stmt, bool atomic)
RangeVar * relation
Definition: parsenodes.h:3277
void UserAbortTransactionBlock(void)
Definition: xact.c:3670
void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
Definition: guc.c:7332
int stmt_location
Definition: plannodes.h:97
void ExecVacuum(VacuumStmt *vacstmt, bool isTopLevel)
Definition: vacuum.c:87
Node * utilityStmt
Definition: plannodes.h:94
void cluster(ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:106
void ExecuteDoStmt(DoStmt *stmt, bool atomic)
const char * p_sourcetext
Definition: parse_node.h:173
void DropTableSpace(DropTableSpaceStmt *stmt)
Definition: tablespace.c:400
void PrepareQuery(PrepareStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: prepare.c:57
char * conditionname
Definition: parsenodes.h:2931
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition: alter.c:325
#define CHECKPOINT_FORCE
Definition: xlog.h:180
#define ereport(elevel, rest)
Definition: elog.h:122
Oid AlterEventTrigger(AlterEventTrigStmt *stmt)
Node * arg
Definition: parsenodes.h:728
void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind, int options)
Definition: indexcmds.c:2206
bool missing_ok
Definition: parsenodes.h:3087
void BeginTransactionBlock(void)
Definition: xact.c:3414
Oid AlterRole(AlterRoleStmt *stmt)
Definition: user.c:504
void WarnNoTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3201
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:7118
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:886
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
char * conditionname
Definition: parsenodes.h:2920
void dropdb(const char *dbname, bool missing_ok)
Definition: dbcommands.c:780
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:425
bool EventTriggerSupportsObjectType(ObjectType obtype)
Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
Definition: dbcommands.c:1397
void FinishPreparedTransaction(const char *gid, bool isCommit)
Definition: twophase.c:1368
void RequireTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3207
#define CHECKPOINT_WAIT
Definition: xlog.h:184
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:463
#define COMPLETION_TAG_BUFSIZE
Definition: dest.h:74
void DoCopy(ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
Definition: copy.c:779
#define Assert(condition)
Definition: c.h:688
#define lfirst(lc)
Definition: pg_list.h:106
ReindexObjectType kind
Definition: parsenodes.h:3275
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:137
void Async_UnlistenAll(void)
Definition: async.c:670
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition: alter.c:802
void ReleaseSavepoint(List *options)
Definition: xact.c:3912
const char * name
Definition: encode.c:521
void RollbackToSavepoint(List *options)
Definition: xact.c:4033
#define nodeTag(nodeptr)
Definition: nodes.h:518
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest)
Definition: explain.c:142
void Async_Notify(const char *channel, const char *payload)
Definition: async.c:543
void LockTableCommand(LockStmt *lockstmt)
Definition: lockcmds.c:36
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
Definition: dbcommands.c:99
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ReassignOwnedObjects(ReassignOwnedStmt *stmt)
Definition: user.c:1359
ObjectType objtype
Definition: parsenodes.h:1869
#define CHECKPOINT_IMMEDIATE
Definition: xlog.h:179
static void check_xact_readonly(Node *parsetree)
Definition: utility.c:132
void DropRole(DropRoleStmt *stmt)
Definition: user.c:966
const char * name
Definition: parsenodes.h:3278
char * defname
Definition: parsenodes.h:727
#define elog
Definition: elog.h:219
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:77
#define PointerIsValid(pointer)
Definition: c.h:582
#define UINT64_FORMAT
Definition: c.h:357
char * dbname
Definition: parsenodes.h:3086
void DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
Definition: discard.c:31
void Async_Unlisten(const char *channel)
Definition: async.c:652
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7476
void RequestCheckpoint(int flags)
Definition: checkpointer.c:967
void PreventTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3154
char * payload
Definition: parsenodes.h:2921
TransactionStmtKind kind
Definition: parsenodes.h:2965
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:385
char * conditionname
Definition: parsenodes.h:2941
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:986

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

Definition at line 1885 of file utility.c.

References castNode, CMD_UTILITY, Query::commandType, nodeTag, T_CreateTableAsStmt, T_DeclareCursorStmt, T_ExplainStmt, UtilityContainsQuery(), and Query::utilityStmt.

Referenced by AcquireExecutorLocks(), AcquirePlannerLocks(), extract_query_dependencies_walker(), ResetPlanCache(), and UtilityContainsQuery().

1886 {
1887  Query *qry;
1888 
1889  switch (nodeTag(parsetree))
1890  {
1891  case T_DeclareCursorStmt:
1892  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
1893  if (qry->commandType == CMD_UTILITY)
1894  return UtilityContainsQuery(qry->utilityStmt);
1895  return qry;
1896 
1897  case