PostgreSQL Source Code  git master
utility.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/reloptions.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "catalog/catalog.h"
#include "catalog/namespace.h"
#include "catalog/pg_inherits.h"
#include "catalog/toasting.h"
#include "commands/alter.h"
#include "commands/async.h"
#include "commands/cluster.h"
#include "commands/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 "utils/rel.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 1907 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().

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

◆ check_xact_readonly()

static void check_xact_readonly ( Node parsetree)
static

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

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

◆ CheckRestrictedOperation()

static void CheckRestrictedOperation ( const char *  cmdname)
static

Definition at line 293 of file utility.c.

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

Referenced by standard_ProcessUtility().

294 {
296  ereport(ERROR,
297  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
298  /* translator: %s is name of a SQL command, eg PREPARE */
299  errmsg("cannot execute %s within security-restricted operation",
300  cmdname)));
301 }
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:511
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

Definition at line 99 of file utility.c.

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

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

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

◆ CreateCommandTag()

const char* CreateCommandTag ( Node parsetree)

Definition at line 2056 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, relkind, PlannedStmt::rowMarks, Query::rowMarks, T_AlterCollationStmt, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_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().

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

◆ ExecDropStmt()

static void ExecDropStmt ( DropStmt stmt,
bool  isTopLevel 
)
static

Definition at line 1696 of file utility.c.

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

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

1697 {
1698  switch (stmt->removeType)
1699  {
1700  case OBJECT_INDEX:
1701  if (stmt->concurrent)
1702  PreventInTransactionBlock(isTopLevel,
1703  "DROP INDEX CONCURRENTLY");
1704  /* fall through */
1705 
1706  case OBJECT_TABLE:
1707  case OBJECT_SEQUENCE:
1708  case OBJECT_VIEW:
1709  case OBJECT_MATVIEW:
1710  case OBJECT_FOREIGN_TABLE:
1711  RemoveRelations(stmt);
1712  break;
1713  default:
1714  RemoveObjects(stmt);
1715  break;
1716  }
1717 }
void RemoveObjects(DropStmt *stmt)
Definition: dropcmds.c:55
ObjectType removeType
Definition: parsenodes.h:2593
void RemoveRelations(DropStmt *drop)
Definition: tablecmds.c:1078
bool concurrent
Definition: parsenodes.h:2596
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3153

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

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

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

◆ PreventCommandDuringRecovery()

void PreventCommandDuringRecovery ( const char *  cmdname)

Definition at line 275 of file utility.c.

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

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

276 {
277  if (RecoveryInProgress())
278  ereport(ERROR,
279  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
280  /* translator: %s is name of a SQL command, eg CREATE */
281  errmsg("cannot execute %s during recovery",
282  cmdname)));
283 }
int errcode(int sqlerrcode)
Definition: elog.c:575
bool RecoveryInProgress(void)
Definition: xlog.c:7939
#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 256 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().

257 {
258  if (IsInParallelMode())
259  ereport(ERROR,
260  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
261  /* translator: %s is name of a SQL command, eg CREATE */
262  errmsg("cannot execute %s during a parallel operation",
263  cmdname)));
264 }
int errcode(int sqlerrcode)
Definition: elog.c:575
bool IsInParallelMode(void)
Definition: xact.c:905
#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 238 of file utility.c.

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

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

239 {
240  if (XactReadOnly)
241  ereport(ERROR,
242  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
243  /* translator: %s is name of a SQL command, eg CREATE */
244  errmsg("cannot execute %s in a read-only transaction",
245  cmdname)));
246 }
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:76
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 337 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().

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

◆ 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 934 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, PreventInTransactionBlock(), PROCESS_UTILITY_QUERY, PROCESS_UTILITY_SUBCOMMAND, PROCESS_UTILITY_TOPLEVEL, ProcessUtility(), RangeVarCallbackOwnsRelation(), RangeVarGetRelidExtended(), RelationData::rd_rel, AlterTableStmt::relation, IndexStmt::relation, 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().

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

◆ standard_ProcessUtility()

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

Definition at line 376 of file utility.c.

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterSystemSetConfigFile(), AlterTableSpaceOptions(), DefElem::arg, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), BeginTransactionBlock(), castNode, 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, 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(), ClosePortalStmt::portalname, PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventInTransactionBlock(), PROCESS_UTILITY_QUERY_NONATOMIC, PROCESS_UTILITY_TOPLEVEL, ProcessUtilitySlow(), ReassignOwnedObjects(), RecoveryInProgress(), REINDEX_OBJECT_DATABASE, REINDEX_OBJECT_INDEX, REINDEX_OBJECT_SCHEMA, REINDEX_OBJECT_SYSTEM, REINDEX_OBJECT_TABLE, ReindexIndex(), ReindexMultipleTables(), ReindexTable(), ReindexStmt::relation, ReleaseSavepoint(), DropStmt::removeType, RenameStmt::renameType, RequestCheckpoint(), RequireTransactionBlock(), RollbackToSavepoint(), TransactionStmt::savepoint_name, SetPGVariable(), snprintf(), PlannedStmt::stmt_len, PlannedStmt::stmt_location, superuser(), T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterEventTrigStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOwnerStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSystemStmt, T_AlterTableSpaceOptionsStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreatedbStmt, T_CreateEventTrigStmt, T_CreateRoleStmt, T_CreateTableSpaceStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropRoleStmt, T_DropStmt, T_DropTableSpaceStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PrepareStmt, T_ReassignOwnedStmt, T_ReindexStmt, T_RenameStmt, T_SecLabelStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, UINT64_FORMAT, UserAbortTransactionBlock(), PlannedStmt::utilityStmt, VACOPT_VACUUM, and WarnNoTransactionBlock().

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

383 {
384  Node *parsetree = pstmt->utilityStmt;
385  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
386  bool isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
387  ParseState *pstate;
388 
389  check_xact_readonly(parsetree);
390 
391  if (completionTag)
392  completionTag[0] = '\0';
393 
394  pstate = make_parsestate(NULL);
395  pstate->p_sourcetext = queryString;
396 
397  switch (nodeTag(parsetree))
398  {
399  /*
400  * ******************** transactions ********************
401  */
402  case T_TransactionStmt:
403  {
404  TransactionStmt *stmt = (TransactionStmt *) parsetree;
405 
406  switch (stmt->kind)
407  {
408  /*
409  * START TRANSACTION, as defined by SQL99: Identical
410  * to BEGIN. Same code for both.
411  */
412  case TRANS_STMT_BEGIN:
413  case TRANS_STMT_START:
414  {
415  ListCell *lc;
416 
418  foreach(lc, stmt->options)
419  {
420  DefElem *item = (DefElem *) lfirst(lc);
421 
422  if (strcmp(item->defname, "transaction_isolation") == 0)
423  SetPGVariable("transaction_isolation",
424  list_make1(item->arg),
425  true);
426  else if (strcmp(item->defname, "transaction_read_only") == 0)
427  SetPGVariable("transaction_read_only",
428  list_make1(item->arg),
429  true);
430  else if (strcmp(item->defname, "transaction_deferrable") == 0)
431  SetPGVariable("transaction_deferrable",
432  list_make1(item->arg),
433  true);
434  }
435  }
436  break;
437 
438  case TRANS_STMT_COMMIT:
439  if (!EndTransactionBlock())
440  {
441  /* report unsuccessful commit in completionTag */
442  if (completionTag)
443  strcpy(completionTag, "ROLLBACK");
444  }
445  break;
446 
447  case TRANS_STMT_PREPARE:
448  PreventCommandDuringRecovery("PREPARE TRANSACTION");
449  if (!PrepareTransactionBlock(stmt->gid))
450  {
451  /* report unsuccessful commit in completionTag */
452  if (completionTag)
453  strcpy(completionTag, "ROLLBACK");
454  }
455  break;
456 
458  PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
459  PreventCommandDuringRecovery("COMMIT PREPARED");
460  FinishPreparedTransaction(stmt->gid, true);
461  break;
462 
464  PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
465  PreventCommandDuringRecovery("ROLLBACK PREPARED");
466  FinishPreparedTransaction(stmt->gid, false);
467  break;
468 
469  case TRANS_STMT_ROLLBACK:
471  break;
472 
474  RequireTransactionBlock(isTopLevel, "SAVEPOINT");
476  break;
477 
478  case TRANS_STMT_RELEASE:
479  RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
481  break;
482 
484  RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
486 
487  /*
488  * CommitTransactionCommand is in charge of
489  * re-defining the savepoint again
490  */
491  break;
492  }
493  }
494  break;
495 
496  /*
497  * Portal (cursor) manipulation
498  */
499  case T_DeclareCursorStmt:
500  PerformCursorOpen((DeclareCursorStmt *) parsetree, params,
501  queryString, isTopLevel);
502  break;
503 
504  case T_ClosePortalStmt:
505  {
506  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
507 
508  CheckRestrictedOperation("CLOSE");
510  }
511  break;
512 
513  case T_FetchStmt:
514  PerformPortalFetch((FetchStmt *) parsetree, dest,
515  completionTag);
516  break;
517 
518  case T_DoStmt:
519  ExecuteDoStmt((DoStmt *) parsetree, isAtomicContext);
520  break;
521 
523  /* no event triggers for global objects */
524  PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
525  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
526  break;
527 
529  /* no event triggers for global objects */
530  PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
531  DropTableSpace((DropTableSpaceStmt *) parsetree);
532  break;
533 
535  /* no event triggers for global objects */
537  break;
538 
539  case T_TruncateStmt:
540  ExecuteTruncate((TruncateStmt *) parsetree);
541  break;
542 
543  case T_CopyStmt:
544  {
545  uint64 processed;
546 
547  DoCopy(pstate, (CopyStmt *) parsetree,
548  pstmt->stmt_location, pstmt->stmt_len,
549  &processed);
550  if (completionTag)
551  snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
552  "COPY " UINT64_FORMAT, processed);
553  }
554  break;
555 
556  case T_PrepareStmt:
557  CheckRestrictedOperation("PREPARE");
558  PrepareQuery((PrepareStmt *) parsetree, queryString,
559  pstmt->stmt_location, pstmt->stmt_len);
560  break;
561 
562  case T_ExecuteStmt:
563  ExecuteQuery((ExecuteStmt *) parsetree, NULL,
564  queryString, params,
565  dest, completionTag);
566  break;
567 
568  case T_DeallocateStmt:
569  CheckRestrictedOperation("DEALLOCATE");
570  DeallocateQuery((DeallocateStmt *) parsetree);
571  break;
572 
573  case T_GrantRoleStmt:
574  /* no event triggers for global objects */
575  GrantRole((GrantRoleStmt *) parsetree);
576  break;
577 
578  case T_CreatedbStmt:
579  /* no event triggers for global objects */
580  PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
581  createdb(pstate, (CreatedbStmt *) parsetree);
582  break;
583 
584  case T_AlterDatabaseStmt:
585  /* no event triggers for global objects */
586  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
587  break;
588 
590  /* no event triggers for global objects */
591  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
592  break;
593 
594  case T_DropdbStmt:
595  {
596  DropdbStmt *stmt = (DropdbStmt *) parsetree;
597 
598  /* no event triggers for global objects */
599  PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
600  dropdb(stmt->dbname, stmt->missing_ok);
601  }
602  break;
603 
604  /* Query-level asynchronous notification */
605  case T_NotifyStmt:
606  {
607  NotifyStmt *stmt = (NotifyStmt *) parsetree;
608 
610  Async_Notify(stmt->conditionname, stmt->payload);
611  }
612  break;
613 
614  case T_ListenStmt:
615  {
616  ListenStmt *stmt = (ListenStmt *) parsetree;
617 
619  CheckRestrictedOperation("LISTEN");
621  }
622  break;
623 
624  case T_UnlistenStmt:
625  {
626  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
627 
628  PreventCommandDuringRecovery("UNLISTEN");
629  CheckRestrictedOperation("UNLISTEN");
630  if (stmt->conditionname)
632  else
634  }
635  break;
636 
637  case T_LoadStmt:
638  {
639  LoadStmt *stmt = (LoadStmt *) parsetree;
640 
641  closeAllVfds(); /* probably not necessary... */
642  /* Allowed names are restricted if you're not superuser */
643  load_file(stmt->filename, !superuser());
644  }
645  break;
646 
647  case T_CallStmt:
648  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
649  break;
650 
651  case T_ClusterStmt:
652  /* we choose to allow this during "read only" transactions */
653  PreventCommandDuringRecovery("CLUSTER");
654  /* forbidden in parallel mode due to CommandIsReadOnly */
655  cluster((ClusterStmt *) parsetree, isTopLevel);
656  break;
657 
658  case T_VacuumStmt:
659  {
660  VacuumStmt *stmt = (VacuumStmt *) parsetree;
661 
662  /* we choose to allow this during "read only" transactions */
664  "VACUUM" : "ANALYZE");
665  /* forbidden in parallel mode due to CommandIsReadOnly */
666  ExecVacuum(stmt, isTopLevel);
667  }
668  break;
669 
670  case T_ExplainStmt:
671  ExplainQuery(pstate, (ExplainStmt *) parsetree, queryString, params,
672  queryEnv, dest);
673  break;
674 
675  case T_AlterSystemStmt:
676  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
678  break;
679 
680  case T_VariableSetStmt:
681  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
682  break;
683 
684  case T_VariableShowStmt:
685  {
686  VariableShowStmt *n = (VariableShowStmt *) parsetree;
687 
688  GetPGVariable(n->name, dest);
689  }
690  break;
691 
692  case T_DiscardStmt:
693  /* should we allow DISCARD PLANS? */
694  CheckRestrictedOperation("DISCARD");
695  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
696  break;
697 
699  /* no event triggers on event triggers */
701  break;
702 
704  /* no event triggers on event triggers */
705  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
706  break;
707 
708  /*
709  * ******************************** ROLE statements ****
710  */
711  case T_CreateRoleStmt:
712  /* no event triggers for global objects */
713  CreateRole(pstate, (CreateRoleStmt *) parsetree);
714  break;
715 
716  case T_AlterRoleStmt:
717  /* no event triggers for global objects */
718  AlterRole((AlterRoleStmt *) parsetree);
719  break;
720 
721  case T_AlterRoleSetStmt:
722  /* no event triggers for global objects */
723  AlterRoleSet((AlterRoleSetStmt *) parsetree);
724  break;
725 
726  case T_DropRoleStmt:
727  /* no event triggers for global objects */
728  DropRole((DropRoleStmt *) parsetree);
729  break;
730 
731  case T_ReassignOwnedStmt:
732  /* no event triggers for global objects */
734  break;
735 
736  case T_LockStmt:
737 
738  /*
739  * Since the lock would just get dropped immediately, LOCK TABLE
740  * outside a transaction block is presumed to be user error.
741  */
742  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
743  /* forbidden in parallel mode due to CommandIsReadOnly */
744  LockTableCommand((LockStmt *) parsetree);
745  break;
746 
748  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
750  break;
751 
752  case T_CheckPointStmt:
753  if (!superuser())
754  ereport(ERROR,
755  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
756  errmsg("must be superuser to do CHECKPOINT")));
757 
758  /*
759  * You might think we should have a PreventCommandDuringRecovery()
760  * here, but we interpret a CHECKPOINT command during recovery as
761  * a request for a restartpoint instead. We allow this since it
762  * can be a useful way of reducing switchover time when using
763  * various forms of replication.
764  */
767  break;
768 
769  case T_ReindexStmt:
770  {
771  ReindexStmt *stmt = (ReindexStmt *) parsetree;
772 
773  /* we choose to allow this during "read only" transactions */
774  PreventCommandDuringRecovery("REINDEX");
775  /* forbidden in parallel mode due to CommandIsReadOnly */
776  switch (stmt->kind)
777  {
779  ReindexIndex(stmt->relation, stmt->options);
780  break;
782  ReindexTable(stmt->relation, stmt->options);
783  break;
787 
788  /*
789  * This cannot run inside a user transaction block; if
790  * we were inside a transaction, then its commit- and
791  * start-transaction-command calls would not have the
792  * intended effect!
793  */
794  PreventInTransactionBlock(isTopLevel,
795  (stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
796  (stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
797  "REINDEX DATABASE");
798  ReindexMultipleTables(stmt->name, stmt->kind, stmt->options);
799  break;
800  default:
801  elog(ERROR, "unrecognized object type: %d",
802  (int) stmt->kind);
803  break;
804  }
805  }
806  break;
807 
808  /*
809  * The following statements are supported by Event Triggers only
810  * in some cases, so we "fast path" them in the other cases.
811  */
812 
813  case T_GrantStmt:
814  {
815  GrantStmt *stmt = (GrantStmt *) parsetree;
816 
818  ProcessUtilitySlow(pstate, pstmt, queryString,
819  context, params, queryEnv,
820  dest, completionTag);
821  else
822  ExecuteGrantStmt(stmt);
823  }
824  break;
825 
826  case T_DropStmt:
827  {
828  DropStmt *stmt = (DropStmt *) parsetree;
829 
831  ProcessUtilitySlow(pstate, pstmt, queryString,
832  context, params, queryEnv,
833  dest, completionTag);
834  else
835  ExecDropStmt(stmt, isTopLevel);
836  }
837  break;
838 
839  case T_RenameStmt:
840  {
841  RenameStmt *stmt = (RenameStmt *) parsetree;
842 
844  ProcessUtilitySlow(pstate, pstmt, queryString,
845  context, params, queryEnv,
846  dest, completionTag);
847  else
848  ExecRenameStmt(stmt);
849  }
850  break;
851 
853  {
854  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
855 
857  ProcessUtilitySlow(pstate, pstmt, queryString,
858  context, params, queryEnv,
859  dest, completionTag);
860  else
861  ExecAlterObjectDependsStmt(stmt, NULL);
862  }
863  break;
864 
866  {
867  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
868 
870  ProcessUtilitySlow(pstate, pstmt, queryString,
871  context, params, queryEnv,
872  dest, completionTag);
873  else
874  ExecAlterObjectSchemaStmt(stmt, NULL);
875  }
876  break;
877 
878  case T_AlterOwnerStmt:
879  {
880  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
881 
883  ProcessUtilitySlow(pstate, pstmt, queryString,
884  context, params, queryEnv,
885  dest, completionTag);
886  else
887  ExecAlterOwnerStmt(stmt);
888  }
889  break;
890 
891  case T_CommentStmt:
892  {
893  CommentStmt *stmt = (CommentStmt *) parsetree;
894 
896  ProcessUtilitySlow(pstate, pstmt, queryString,
897  context, params, queryEnv,
898  dest, completionTag);
899  else
900  CommentObject(stmt);
901  break;
902  }
903 
904  case T_SecLabelStmt:
905  {
906  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
907 
909  ProcessUtilitySlow(pstate, pstmt, queryString,
910  context, params, queryEnv,
911  dest, completionTag);
912  else
913  ExecSecLabelStmt(stmt);
914  break;
915  }
916 
917  default:
918  /* All other statement types have event trigger support */
919  ProcessUtilitySlow(pstate, pstmt, queryString,
920  context, params, queryEnv,
921  dest, completionTag);
922  break;
923  }
924 
925  free_parsestate(pstate);
926 }
ObjectType objtype
Definition: parsenodes.h:2618
void closeAllVfds(void)
Definition: fd.c:2777
ObjectType objtype
Definition: parsenodes.h:2630
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1696
void PerformPortalClose(const char *name)
Definition: portalcmds.c:216
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectType renameType
Definition: parsenodes.h:2843
Oid ReindexTable(RangeVar *relation, int options)
Definition: indexcmds.c:2259
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:44
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3213
#define castNode(_type_, nodeptr)
Definition: nodes.h:586
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:1575
ObjectType objectType
Definition: parsenodes.h:2888
void DefineSavepoint(const char *name)
Definition: xact.c:3825
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:5305
void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest)
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:293
Definition: nodes.h:517
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3480
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:3058
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:234
bool RecoveryInProgress(void)
Definition: xlog.c:7939
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1322
bool EndTransactionBlock(void)
Definition: xact.c:3532
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:100
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Definition: user.c:72
ObjectType removeType
Definition: parsenodes.h:2593
void RollbackToSavepoint(const char *name)
Definition: xact.c:4019
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc.c:8157
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:44
void ReindexIndex(RangeVar *indexRelation, int options)
Definition: indexcmds.c:2159
#define list_make1(x1)
Definition: pg_list.h:139
bool IsTransactionBlock(void)
Definition: xact.c:4422
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:934
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:275
char * savepoint_name
Definition: parsenodes.h:2977
void GrantRole(GrantRoleStmt *stmt)
Definition: user.c:1274
void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest, char *completionTag)
Definition: portalcmds.c:168
RangeVar * relation
Definition: parsenodes.h:3288
void UserAbortTransactionBlock(void)
Definition: xact.c:3668
void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
Definition: guc.c:7539
int stmt_location
Definition: plannodes.h:99
void ExecVacuum(VacuumStmt *vacstmt, bool isTopLevel)
Definition: vacuum.c:87
Node * utilityStmt
Definition: plannodes.h:96
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3153
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:402
void PrepareQuery(PrepareStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: prepare.c:57
char * conditionname
Definition: parsenodes.h:2941
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:731
void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind, int options)
Definition: indexcmds.c:2287
bool missing_ok
Definition: parsenodes.h:3098
void BeginTransactionBlock(void)
Definition: xact.c:3412
Oid AlterRole(AlterRoleStmt *stmt)
Definition: user.c:504
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:7325
void ReleaseSavepoint(const char *name)
Definition: xact.c:3910
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:886
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
char * conditionname
Definition: parsenodes.h:2930
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:1433
#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:782
#define lfirst(lc)
Definition: pg_list.h:106
ReindexObjectType kind
Definition: parsenodes.h:3286
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
#define nodeTag(nodeptr)
Definition: nodes.h:522
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest)
Definition: explain.c:143
void Async_Notify(const char *channel, const char *payload)
Definition: async.c:543
void LockTableCommand(LockStmt *lockstmt)
Definition: lockcmds.c:40
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:1872
#define CHECKPOINT_IMMEDIATE
Definition: xlog.h:179
static void check_xact_readonly(Node *parsetree)
Definition: utility.c:133
void DropRole(DropRoleStmt *stmt)
Definition: user.c:966
const char * name
Definition: parsenodes.h:3289
char * defname
Definition: parsenodes.h:730
#define elog
Definition: elog.h:219
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:77
#define UINT64_FORMAT
Definition: c.h:368
char * dbname
Definition: parsenodes.h:3097
void DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
Definition: discard.c:31
void RequireTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3219
void Async_Unlisten(const char *channel)
Definition: async.c:652
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7683
void RequestCheckpoint(int flags)
Definition: checkpointer.c:967
char * payload
Definition: parsenodes.h:2931
TransactionStmtKind kind
Definition: parsenodes.h:2975
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:385
char * conditionname
Definition: parsenodes.h:2951
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:988

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

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

1871 {
1872  Query *qry;
1873 
1874  switch (nodeTag(parsetree))
1875  {
1876  case T_DeclareCursorStmt:
1877  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
1878  if (qry->commandType == CMD_UTILITY)
1879  return UtilityContainsQuery(qry->utilityStmt);
1880  return qry;
1881 
1882  case T_ExplainStmt:
1883  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
1884  if (qry->commandType == CMD_UTILITY)
1885  return UtilityContainsQuery(qry->utilityStmt);
1886  return qry;
1887 
1888  case T_CreateTableAsStmt:
1889  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
1890  if (qry->commandType == CMD_UTILITY)
1891  return UtilityContainsQuery(qry->utilityStmt);
1892  return qry;
1893 
1894  default:
1895  return NULL;
1896  }
1897 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:586
Node * utilityStmt
Definiti