PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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/toasting.h"
#include "commands/alter.h"
#include "commands/async.h"
#include "commands/cluster.h"
#include "commands/comment.h"
#include "commands/collationcmds.h"
#include "commands/conversioncmds.h"
#include "commands/copy.h"
#include "commands/createas.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/discard.h"
#include "commands/event_trigger.h"
#include "commands/explain.h"
#include "commands/extension.h"
#include "commands/matview.h"
#include "commands/lockcmds.h"
#include "commands/policy.h"
#include "commands/portalcmds.h"
#include "commands/prepare.h"
#include "commands/proclang.h"
#include "commands/publicationcmds.h"
#include "commands/schemacmds.h"
#include "commands/seclabel.h"
#include "commands/sequence.h"
#include "commands/subscriptioncmds.h"
#include "commands/tablecmds.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "commands/typecmds.h"
#include "commands/user.h"
#include "commands/vacuum.h"
#include "commands/view.h"
#include "miscadmin.h"
#include "parser/parse_utilcmd.h"
#include "postmaster/bgwriter.h"
#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteRemove.h"
#include "storage/fd.h"
#include "tcop/pquery.h"
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/guc.h"
#include "utils/syscache.h"
Include dependency graph for utility.c:

Go to the source code of this file.

Functions

static void ProcessUtilitySlow (ParseState *pstate, PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, 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, DestReceiver *dest, char *completionTag)
 
void standard_ProcessUtility (PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, 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

static const char* AlterObjectTypeCommandTag ( ObjectType  objtype)
static

Definition at line 1881 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_PUBLICATION, OBJECT_ROLE, 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().

1882 {
1883  const char *tag;
1884 
1885  switch (objtype)
1886  {
1887  case OBJECT_AGGREGATE:
1888  tag = "ALTER AGGREGATE";
1889  break;
1890  case OBJECT_ATTRIBUTE:
1891  tag = "ALTER TYPE";
1892  break;
1893  case OBJECT_CAST:
1894  tag = "ALTER CAST";
1895  break;
1896  case OBJECT_COLLATION:
1897  tag = "ALTER COLLATION";
1898  break;
1899  case OBJECT_COLUMN:
1900  tag = "ALTER TABLE";
1901  break;
1902  case OBJECT_CONVERSION:
1903  tag = "ALTER CONVERSION";
1904  break;
1905  case OBJECT_DATABASE:
1906  tag = "ALTER DATABASE";
1907  break;
1908  case OBJECT_DOMAIN:
1909  case OBJECT_DOMCONSTRAINT:
1910  tag = "ALTER DOMAIN";
1911  break;
1912  case OBJECT_EXTENSION:
1913  tag = "ALTER EXTENSION";
1914  break;
1915  case OBJECT_FDW:
1916  tag = "ALTER FOREIGN DATA WRAPPER";
1917  break;
1918  case OBJECT_FOREIGN_SERVER:
1919  tag = "ALTER SERVER";
1920  break;
1921  case OBJECT_FOREIGN_TABLE:
1922  tag = "ALTER FOREIGN TABLE";
1923  break;
1924  case OBJECT_FUNCTION:
1925  tag = "ALTER FUNCTION";
1926  break;
1927  case OBJECT_INDEX:
1928  tag = "ALTER INDEX";
1929  break;
1930  case OBJECT_LANGUAGE:
1931  tag = "ALTER LANGUAGE";
1932  break;
1933  case OBJECT_LARGEOBJECT:
1934  tag = "ALTER LARGE OBJECT";
1935  break;
1936  case OBJECT_OPCLASS:
1937  tag = "ALTER OPERATOR CLASS";
1938  break;
1939  case OBJECT_OPERATOR:
1940  tag = "ALTER OPERATOR";
1941  break;
1942  case OBJECT_OPFAMILY:
1943  tag = "ALTER OPERATOR FAMILY";
1944  break;
1945  case OBJECT_POLICY:
1946  tag = "ALTER POLICY";
1947  break;
1948  case OBJECT_ROLE:
1949  tag = "ALTER ROLE";
1950  break;
1951  case OBJECT_RULE:
1952  tag = "ALTER RULE";
1953  break;
1954  case OBJECT_SCHEMA:
1955  tag = "ALTER SCHEMA";
1956  break;
1957  case OBJECT_SEQUENCE:
1958  tag = "ALTER SEQUENCE";
1959  break;
1960  case OBJECT_TABLE:
1961  case OBJECT_TABCONSTRAINT:
1962  tag = "ALTER TABLE";
1963  break;
1964  case OBJECT_TABLESPACE:
1965  tag = "ALTER TABLESPACE";
1966  break;
1967  case OBJECT_TRIGGER:
1968  tag = "ALTER TRIGGER";
1969  break;
1970  case OBJECT_EVENT_TRIGGER:
1971  tag = "ALTER EVENT TRIGGER";
1972  break;
1974  tag = "ALTER TEXT SEARCH CONFIGURATION";
1975  break;
1976  case OBJECT_TSDICTIONARY:
1977  tag = "ALTER TEXT SEARCH DICTIONARY";
1978  break;
1979  case OBJECT_TSPARSER:
1980  tag = "ALTER TEXT SEARCH PARSER";
1981  break;
1982  case OBJECT_TSTEMPLATE:
1983  tag = "ALTER TEXT SEARCH TEMPLATE";
1984  break;
1985  case OBJECT_TYPE:
1986  tag = "ALTER TYPE";
1987  break;
1988  case OBJECT_VIEW:
1989  tag = "ALTER VIEW";
1990  break;
1991  case OBJECT_MATVIEW:
1992  tag = "ALTER MATERIALIZED VIEW";
1993  break;
1994  case OBJECT_PUBLICATION:
1995  tag = "ALTER PUBLICATION";
1996  break;
1997  case OBJECT_SUBSCRIPTION:
1998  tag = "ALTER SUBSCRIPTION";
1999  case OBJECT_STATISTIC_EXT:
2000  tag = "ALTER STATISTICS";
2001  break;
2002  default:
2003  tag = "???";
2004  break;
2005  }
2006 
2007  return tag;
2008 }
static void check_xact_readonly ( Node parsetree)
static

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

131 {
132  /* Only perform the check if we have a reason to do so. */
133  if (!XactReadOnly && !IsInParallelMode())
134  return;
135 
136  /*
137  * Note: Commands that need to do more complicated checking are handled
138  * elsewhere, in particular COPY and plannable statements do their own
139  * checking. However they should all call PreventCommandIfReadOnly or
140  * PreventCommandIfParallelMode to actually throw the error.
141  */
142 
143  switch (nodeTag(parsetree))
144  {
145  case T_AlterDatabaseStmt:
147  case T_AlterDomainStmt:
148  case T_AlterFunctionStmt:
149  case T_AlterRoleStmt:
150  case T_AlterRoleSetStmt:
153  case T_AlterOwnerStmt:
154  case T_AlterOperatorStmt:
155  case T_AlterSeqStmt:
157  case T_AlterTableStmt:
158  case T_RenameStmt:
159  case T_CommentStmt:
160  case T_DefineStmt:
161  case T_CreateCastStmt:
165  case T_CreatedbStmt:
166  case T_CreateDomainStmt:
168  case T_CreateRoleStmt:
169  case T_IndexStmt:
170  case T_CreatePLangStmt:
171  case T_CreateOpClassStmt:
173  case T_AlterOpFamilyStmt:
174  case T_RuleStmt:
175  case T_CreateSchemaStmt:
176  case T_CreateSeqStmt:
177  case T_CreateStmt:
178  case T_CreateTableAsStmt:
182  case T_CreateTrigStmt:
183  case T_CompositeTypeStmt:
184  case T_CreateEnumStmt:
185  case T_CreateRangeStmt:
186  case T_AlterEnumStmt:
187  case T_ViewStmt:
188  case T_DropStmt:
189  case T_DropdbStmt:
191  case T_DropRoleStmt:
192  case T_GrantStmt:
193  case T_GrantRoleStmt:
195  case T_TruncateStmt:
196  case T_DropOwnedStmt:
197  case T_ReassignOwnedStmt:
203  case T_CreateFdwStmt:
204  case T_AlterFdwStmt:
213  case T_SecLabelStmt:
221  break;
222  default:
223  /* do nothing */
224  break;
225  }
226 }
void PreventCommandIfParallelMode(const char *cmdname)
Definition: utility.c:253
bool IsInParallelMode(void)
Definition: xact.c:913
const char * CreateCommandTag(Node *parsetree)
Definition: utility.c:2023
bool XactReadOnly
Definition: xact.c:77
void PreventCommandIfReadOnly(const char *cmdname)
Definition: utility.c:235
#define nodeTag(nodeptr)
Definition: nodes.h:509
static void CheckRestrictedOperation ( const char *  cmdname)
static

Definition at line 290 of file utility.c.

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

Referenced by standard_ProcessUtility().

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

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

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

Definition at line 2023 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, NULL, 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_PUBLICATION, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_TABLE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ClosePortalStmt::portalname, PlannedStmt::rowMarks, Query::rowMarks, T_AlterCollationStmt, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterSubscriptionStmt, T_AlterSystemStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterUserMappingStmt, T_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().

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

Definition at line 1670 of file utility.c.

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

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

1671 {
1672  switch (stmt->removeType)
1673  {
1674  case OBJECT_INDEX:
1675  if (stmt->concurrent)
1676  PreventTransactionChain(isTopLevel,
1677  "DROP INDEX CONCURRENTLY");
1678  /* fall through */
1679 
1680  case OBJECT_TABLE:
1681  case OBJECT_SEQUENCE:
1682  case OBJECT_VIEW:
1683  case OBJECT_MATVIEW:
1684  case OBJECT_FOREIGN_TABLE:
1685  RemoveRelations(stmt);
1686  break;
1687  default:
1688  RemoveObjects(stmt);
1689  break;
1690  }
1691 }
void RemoveObjects(DropStmt *stmt)
Definition: dropcmds.c:54
ObjectType removeType
Definition: parsenodes.h:2519
void RemoveRelations(DropStmt *drop)
Definition: tablecmds.c:955
bool concurrent
Definition: parsenodes.h:2522
void PreventTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3154
LogStmtLevel GetCommandLogLevel ( Node parsetree)

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

2858 {
2859  LogStmtLevel lev;
2860 
2861  switch (nodeTag(parsetree))
2862  {
2863  /* recurse if we're given a RawStmt */
2864  case T_RawStmt:
2865  lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
2866  break;
2867 
2868  /* raw plannable queries */
2869  case T_InsertStmt:
2870  case T_DeleteStmt:
2871  case T_UpdateStmt:
2872  lev = LOGSTMT_MOD;
2873  break;
2874 
2875  case T_SelectStmt:
2876  if (((SelectStmt *) parsetree)->intoClause)
2877  lev = LOGSTMT_DDL; /* SELECT INTO */
2878  else
2879  lev = LOGSTMT_ALL;
2880  break;
2881 
2882  /* utility statements --- same whether raw or cooked */
2883  case T_TransactionStmt:
2884  lev = LOGSTMT_ALL;
2885  break;
2886 
2887  case T_DeclareCursorStmt:
2888  lev = LOGSTMT_ALL;
2889  break;
2890 
2891  case T_ClosePortalStmt:
2892  lev = LOGSTMT_ALL;
2893  break;
2894 
2895  case T_FetchStmt:
2896  lev = LOGSTMT_ALL;
2897  break;
2898 
2899  case T_CreateSchemaStmt:
2900  lev = LOGSTMT_DDL;
2901  break;
2902 
2903  case T_CreateStmt:
2905  lev = LOGSTMT_DDL;
2906  break;
2907 
2909  case T_DropTableSpaceStmt:
2911  lev = LOGSTMT_DDL;
2912  break;
2913 
2914  case T_CreateExtensionStmt:
2915  case T_AlterExtensionStmt:
2917  lev = LOGSTMT_DDL;
2918  break;
2919 
2920  case T_CreateFdwStmt:
2921  case T_AlterFdwStmt:
2926  case T_DropUserMappingStmt:
2928  lev = LOGSTMT_DDL;
2929  break;
2930 
2931  case T_DropStmt:
2932  lev = LOGSTMT_DDL;
2933  break;
2934 
2935  case T_TruncateStmt:
2936  lev = LOGSTMT_MOD;
2937  break;
2938 
2939  case T_CommentStmt:
2940  lev = LOGSTMT_DDL;
2941  break;
2942 
2943  case T_SecLabelStmt:
2944  lev = LOGSTMT_DDL;
2945  break;
2946 
2947  case T_CopyStmt:
2948  if (((CopyStmt *) parsetree)->is_from)
2949  lev = LOGSTMT_MOD;
2950  else
2951  lev = LOGSTMT_ALL;
2952  break;
2953 
2954  case T_PrepareStmt:
2955  {
2956  PrepareStmt *stmt = (PrepareStmt *) parsetree;
2957 
2958  /* Look through a PREPARE to the contained stmt */
2959  lev = GetCommandLogLevel(stmt->query);
2960  }
2961  break;
2962 
2963  case T_ExecuteStmt:
2964  {
2965  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2966  PreparedStatement *ps;
2967 
2968  /* Look through an EXECUTE to the referenced stmt */
2969  ps = FetchPreparedStatement(stmt->name, false);
2970  if (ps && ps->plansource->raw_parse_tree)
2972  else
2973  lev = LOGSTMT_ALL;
2974  }
2975  break;
2976 
2977  case T_DeallocateStmt:
2978  lev = LOGSTMT_ALL;
2979  break;
2980 
2981  case T_RenameStmt:
2982  lev = LOGSTMT_DDL;
2983  break;
2984 
2986  lev = LOGSTMT_DDL;
2987  break;
2988 
2990  lev = LOGSTMT_DDL;
2991  break;
2992 
2993  case T_AlterOwnerStmt:
2994  lev = LOGSTMT_DDL;
2995  break;
2996 
2998  case T_AlterTableStmt:
2999  lev = LOGSTMT_DDL;
3000  break;
3001 
3002  case T_AlterDomainStmt:
3003  lev = LOGSTMT_DDL;
3004  break;
3005 
3006  case T_GrantStmt:
3007  lev = LOGSTMT_DDL;
3008  break;
3009 
3010  case T_GrantRoleStmt:
3011  lev = LOGSTMT_DDL;
3012  break;
3013 
3015  lev = LOGSTMT_DDL;
3016  break;
3017 
3018  case T_DefineStmt:
3019  lev = LOGSTMT_DDL;
3020  break;
3021 
3022  case T_CompositeTypeStmt:
3023  lev = LOGSTMT_DDL;
3024  break;
3025 
3026  case T_CreateEnumStmt:
3027  lev = LOGSTMT_DDL;
3028  break;
3029 
3030  case T_CreateRangeStmt:
3031  lev = LOGSTMT_DDL;
3032  break;
3033 
3034  case T_AlterEnumStmt:
3035  lev = LOGSTMT_DDL;
3036  break;
3037 
3038  case T_ViewStmt:
3039  lev = LOGSTMT_DDL;
3040  break;
3041 
3042  case T_CreateFunctionStmt:
3043  lev = LOGSTMT_DDL;
3044  break;
3045 
3046  case T_AlterFunctionStmt:
3047  lev = LOGSTMT_DDL;
3048  break;
3049 
3050  case T_IndexStmt:
3051  lev = LOGSTMT_DDL;
3052  break;
3053 
3054  case T_RuleStmt:
3055  lev = LOGSTMT_DDL;
3056  break;
3057 
3058  case T_CreateSeqStmt:
3059  lev = LOGSTMT_DDL;
3060  break;
3061 
3062  case T_AlterSeqStmt:
3063  lev = LOGSTMT_DDL;
3064  break;
3065 
3066  case T_DoStmt:
3067  lev = LOGSTMT_ALL;
3068  break;
3069 
3070  case T_CreatedbStmt:
3071  lev = LOGSTMT_DDL;
3072  break;
3073 
3074  case T_AlterDatabaseStmt:
3075  lev = LOGSTMT_DDL;
3076  break;
3077 
3079  lev = LOGSTMT_DDL;
3080  break;
3081 
3082  case T_DropdbStmt:
3083  lev = LOGSTMT_DDL;
3084  break;
3085 
3086  case T_NotifyStmt:
3087  lev = LOGSTMT_ALL;
3088  break;
3089 
3090  case T_ListenStmt:
3091  lev = LOGSTMT_ALL;
3092  break;
3093 
3094  case T_UnlistenStmt:
3095  lev = LOGSTMT_ALL;
3096  break;
3097 
3098  case T_LoadStmt:
3099  lev = LOGSTMT_ALL;
3100  break;
3101 
3102  case T_ClusterStmt:
3103  lev = LOGSTMT_DDL;
3104  break;
3105 
3106  case T_VacuumStmt:
3107  lev = LOGSTMT_ALL;
3108  break;
3109 
3110  case T_ExplainStmt:
3111  {
3112  ExplainStmt *stmt = (ExplainStmt *) parsetree;
3113  bool analyze = false;
3114  ListCell *lc;
3115 
3116  /* Look through an EXPLAIN ANALYZE to the contained stmt */
3117  foreach(lc, stmt->options)
3118  {
3119  DefElem *opt = (DefElem *) lfirst(lc);
3120 
3121  if (strcmp(opt->defname, "analyze") == 0)
3122  analyze = defGetBoolean(opt);
3123  /* don't "break", as explain.c will use the last value */
3124  }
3125  if (analyze)
3126  return GetCommandLogLevel(stmt->query);
3127 
3128  /* Plain EXPLAIN isn't so interesting */
3129  lev = LOGSTMT_ALL;
3130  }
3131  break;
3132 
3133  case T_CreateTableAsStmt:
3134  lev = LOGSTMT_DDL;
3135  break;
3136 
3137  case T_RefreshMatViewStmt:
3138  lev = LOGSTMT_DDL;
3139  break;
3140 
3141  case T_AlterSystemStmt:
3142  lev = LOGSTMT_DDL;
3143  break;
3144 
3145  case T_VariableSetStmt:
3146  lev = LOGSTMT_ALL;
3147  break;
3148 
3149  case T_VariableShowStmt:
3150  lev = LOGSTMT_ALL;
3151  break;
3152 
3153  case T_DiscardStmt:
3154  lev = LOGSTMT_ALL;
3155  break;
3156 
3157  case T_CreateTrigStmt:
3158  lev = LOGSTMT_DDL;
3159  break;
3160 
3161  case T_CreateEventTrigStmt:
3162  lev = LOGSTMT_DDL;
3163  break;
3164 
3165  case T_AlterEventTrigStmt:
3166  lev = LOGSTMT_DDL;
3167  break;
3168 
3169  case T_CreatePLangStmt:
3170  lev = LOGSTMT_DDL;
3171  break;
3172 
3173  case T_CreateDomainStmt:
3174  lev = LOGSTMT_DDL;
3175  break;
3176 
3177  case T_CreateRoleStmt:
3178  lev = LOGSTMT_DDL;
3179  break;
3180 
3181  case T_AlterRoleStmt:
3182  lev = LOGSTMT_DDL;
3183  break;
3184 
3185  case T_AlterRoleSetStmt:
3186  lev = LOGSTMT_DDL;
3187  break;
3188 
3189  case T_DropRoleStmt:
3190  lev = LOGSTMT_DDL;
3191  break;
3192 
3193  case T_DropOwnedStmt:
3194  lev = LOGSTMT_DDL;
3195  break;
3196 
3197  case T_ReassignOwnedStmt:
3198  lev = LOGSTMT_DDL;
3199  break;
3200 
3201  case T_LockStmt:
3202  lev = LOGSTMT_ALL;
3203  break;
3204 
3205  case T_ConstraintsSetStmt:
3206  lev = LOGSTMT_ALL;
3207  break;
3208 
3209  case T_CheckPointStmt:
3210  lev = LOGSTMT_ALL;
3211  break;
3212 
3213  case T_ReindexStmt:
3214  lev = LOGSTMT_ALL; /* should this be DDL? */
3215  break;
3216 
3218  lev = LOGSTMT_DDL;
3219  break;
3220 
3221  case T_CreateCastStmt:
3222  lev = LOGSTMT_DDL;
3223  break;
3224 
3225  case T_CreateOpClassStmt:
3226  lev = LOGSTMT_DDL;
3227  break;
3228 
3229  case T_CreateOpFamilyStmt:
3230  lev = LOGSTMT_DDL;
3231  break;
3232 
3233  case T_CreateTransformStmt:
3234  lev = LOGSTMT_DDL;
3235  break;
3236 
3237  case T_AlterOpFamilyStmt:
3238  lev = LOGSTMT_DDL;
3239  break;
3240 
3241  case T_CreatePolicyStmt:
3242  lev = LOGSTMT_DDL;
3243  break;
3244 
3245  case T_AlterPolicyStmt:
3246  lev = LOGSTMT_DDL;
3247  break;
3248 
3250  lev = LOGSTMT_DDL;
3251  break;
3252 
3254  lev = LOGSTMT_DDL;
3255  break;
3256 
3257  case T_CreateAmStmt:
3258  lev = LOGSTMT_DDL;
3259  break;
3260 
3262  lev = LOGSTMT_DDL;
3263  break;
3264 
3266  lev = LOGSTMT_DDL;
3267  break;
3268 
3270  lev = LOGSTMT_DDL;
3271  break;
3272 
3274  lev = LOGSTMT_DDL;
3275  break;
3276 
3278  lev = LOGSTMT_DDL;
3279  break;
3280 
3281  /* already-planned queries */
3282  case T_PlannedStmt:
3283  {
3284  PlannedStmt *stmt = (PlannedStmt *) parsetree;
3285 
3286  switch (stmt->commandType)
3287  {
3288  case CMD_SELECT:
3289  lev = LOGSTMT_ALL;
3290  break;
3291 
3292  case CMD_UPDATE:
3293  case CMD_INSERT:
3294  case CMD_DELETE:
3295  lev = LOGSTMT_MOD;
3296  break;
3297 
3298  case CMD_UTILITY:
3299  lev = GetCommandLogLevel(stmt->utilityStmt);
3300  break;
3301 
3302  default:
3303  elog(WARNING, "unrecognized commandType: %d",
3304  (int) stmt->commandType);
3305  lev = LOGSTMT_ALL;
3306  break;
3307  }
3308  }
3309  break;
3310 
3311  /* parsed-and-rewritten-but-not-planned queries */
3312  case T_Query:
3313  {
3314  Query *stmt = (Query *) parsetree;
3315 
3316  switch (stmt->commandType)
3317  {
3318  case CMD_SELECT:
3319  lev = LOGSTMT_ALL;
3320  break;
3321 
3322  case CMD_UPDATE:
3323  case CMD_INSERT:
3324  case CMD_DELETE:
3325  lev = LOGSTMT_MOD;
3326  break;
3327 
3328  case CMD_UTILITY:
3329  lev = GetCommandLogLevel(stmt->utilityStmt);
3330  break;
3331 
3332  default:
3333  elog(WARNING, "unrecognized commandType: %d",
3334  (int) stmt->commandType);
3335  lev = LOGSTMT_ALL;
3336  break;
3337  }
3338 
3339  }
3340  break;
3341 
3342  default:
3343  elog(WARNING, "unrecognized node type: %d",
3344  (int) nodeTag(parsetree));
3345  lev = LOGSTMT_ALL;
3346  break;
3347  }
3348 
3349  return lev;
3350 }
CachedPlanSource * plansource
Definition: prepare.h:31
LogStmtLevel
Definition: tcopprot.h:39
List * options
Definition: parsenodes.h:3061
Node * utilityStmt
Definition: parsenodes.h:111
Node * query
Definition: parsenodes.h:3060
bool defGetBoolean(DefElem *def)
Definition: define.c:111
Node * stmt
Definition: parsenodes.h:1376
Node * utilityStmt
Definition: plannodes.h:83
#define WARNING
Definition: elog.h:40
Definition: nodes.h:299
CmdType commandType
Definition: plannodes.h:45
CmdType commandType
Definition: parsenodes.h:103
#define lfirst(lc)
Definition: pg_list.h:106
Node * query
Definition: parsenodes.h:3228
struct RawStmt * raw_parse_tree
Definition: plancache.h:82
#define nodeTag(nodeptr)
Definition: nodes.h:509
char * name
Definition: parsenodes.h:3240
char * defname
Definition: parsenodes.h:708
#define elog
Definition: elog.h:219
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:494
static long analyze(struct nfa *nfa)
Definition: regc_nfa.c:2816
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:2857
void PreventCommandDuringRecovery ( const char *  cmdname)

Definition at line 272 of file utility.c.

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

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

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

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

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

Definition at line 235 of file utility.c.

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

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

236 {
237  if (XactReadOnly)
238  ereport(ERROR,
239  (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
240  /* translator: %s is name of a SQL command, eg CREATE */
241  errmsg("cannot execute %s in a read-only transaction",
242  cmdname)));
243 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool XactReadOnly
Definition: xact.c:77
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ProcessUtility ( PlannedStmt pstmt,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
DestReceiver dest,
char *  completionTag 
)

Definition at line 332 of file utility.c.

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

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

338 {
339  Assert(IsA(pstmt, PlannedStmt));
340  Assert(pstmt->commandType == CMD_UTILITY);
341  Assert(queryString != NULL); /* required as of 8.4 */
342 
343  /*
344  * We provide a function hook variable that lets loadable plugins get
345  * control when ProcessUtility is called. Such a plugin would normally
346  * call standard_ProcessUtility().
347  */
349  (*ProcessUtility_hook) (pstmt, queryString,
350  context, params,
351  dest, completionTag);
352  else
353  standard_ProcessUtility(pstmt, queryString,
354  context, params,
355  dest, completionTag);
356 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:555
ProcessUtility_hook_type ProcessUtility_hook
Definition: utility.c:73
void standard_ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, DestReceiver *dest, char *completionTag)
Definition: utility.c:370
CmdType commandType
Definition: plannodes.h:45
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
static void ProcessUtilitySlow ( ParseState pstate,
PlannedStmt pstmt,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
DestReceiver dest,
char *  completionTag 
)
static

Definition at line 937 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(), HEAP_RELOPT_NAMESPACES, heap_reloptions(), DefineStmt::if_not_exists, ImportForeignSchema(), InvalidObjectAddress, InvalidOid, IsA, DefineStmt::kind, lfirst, lnext, makeNode, AlterDomainStmt::missing_ok, AlterDomainStmt::name, NewRelationCreateToastTable(), NIL, nodeTag, None_Receiver, NOTICE, NULL, OBJECT_AGGREGATE, OBJECT_COLLATION, OBJECT_OPERATOR, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, ObjectAddress::objectId, OidIsValid, DefineStmt::oldstyle, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PreventTransactionChain(), PROCESS_UTILITY_QUERY, PROCESS_UTILITY_SUBCOMMAND, PROCESS_UTILITY_TOPLEVEL, ProcessUtility(), RangeVarCallbackOwnsRelation(), RangeVarGetRelidExtended(), AlterTableStmt::relation, IndexStmt::relation, RELKIND_FOREIGN_TABLE, RELKIND_RELATION, RELKIND_TOASTVALUE, RangeVar::relname, RemoveUserMapping(), ShareLock, ShareUpdateExclusiveLock, PlannedStmt::stmt_len, PlannedStmt::stmt_location, AlterDomainStmt::subtype, T_AlterCollationStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterSeqStmt, T_AlterSubscriptionStmt, T_AlterTableMoveAllStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterUserMappingStmt, T_CommentStmt, T_CompositeTypeStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DefineStmt, T_DropOwnedStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropUserMappingStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_RefreshMatViewStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_ViewStmt, transformAlterTableStmt(), transformCreateStmt(), transformIndexStmt(), transformRelOptions(), AlterDomainStmt::typeName, CompositeTypeStmt::typevar, and PlannedStmt::utilityStmt.

Referenced by standard_ProcessUtility().

944 {
945  Node *parsetree = pstmt->utilityStmt;
946  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
947  bool isCompleteQuery = (context <= PROCESS_UTILITY_QUERY);
948  bool needCleanup;
949  bool commandCollected = false;
950  ObjectAddress address;
951  ObjectAddress secondaryObject = InvalidObjectAddress;
952 
953  /* All event trigger calls are done only when isCompleteQuery is true */
954  needCleanup = isCompleteQuery && EventTriggerBeginCompleteQuery();
955 
956  /* PG_TRY block is to ensure we call EventTriggerEndCompleteQuery */
957  PG_TRY();
958  {
959  if (isCompleteQuery)
960  EventTriggerDDLCommandStart(parsetree);
961 
962  switch (nodeTag(parsetree))
963  {
964  /*
965  * relation and attribute manipulation
966  */
967  case T_CreateSchemaStmt:
969  queryString,
970  pstmt->stmt_location,
971  pstmt->stmt_len);
972 
973  /*
974  * EventTriggerCollectSimpleCommand called by
975  * CreateSchemaCommand
976  */
977  commandCollected = true;
978  break;
979 
980  case T_CreateStmt:
982  {
983  List *stmts;
984  ListCell *l;
985 
986  /* Run parse analysis ... */
987  stmts = transformCreateStmt((CreateStmt *) parsetree,
988  queryString);
989 
990  /* ... and do it */
991  foreach(l, stmts)
992  {
993  Node *stmt = (Node *) lfirst(l);
994 
995  if (IsA(stmt, CreateStmt))
996  {
997  Datum toast_options;
998  static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
999 
1000  /* Create the table itself */
1001  address = DefineRelation((CreateStmt *) stmt,
1003  InvalidOid, NULL,
1004  queryString);
1006  secondaryObject,
1007  stmt);
1008 
1009  /*
1010  * Let NewRelationCreateToastTable decide if this
1011  * one needs a secondary relation too.
1012  */
1014 
1015  /*
1016  * parse and validate reloptions for the toast
1017  * table
1018  */
1019  toast_options = transformRelOptions((Datum) 0,
1020  ((CreateStmt *) stmt)->options,
1021  "toast",
1022  validnsps,
1023  true,
1024  false);
1026  toast_options,
1027  true);
1028 
1030  toast_options);
1031  }
1032  else if (IsA(stmt, CreateForeignTableStmt))
1033  {
1034  /* Create the table itself */
1035  address = DefineRelation((CreateStmt *) stmt,
1037  InvalidOid, NULL,
1038  queryString);
1040  address.objectId);
1042  secondaryObject,
1043  stmt);
1044  }
1045  else
1046  {
1047  /*
1048  * Recurse for anything else. Note the recursive
1049  * call will stash the objects so created into our
1050  * event trigger context.
1051  */
1052  PlannedStmt *wrapper;
1053 
1054  wrapper = makeNode(PlannedStmt);
1055  wrapper->commandType = CMD_UTILITY;
1056  wrapper->canSetTag = false;
1057  wrapper->utilityStmt = stmt;
1058  wrapper->stmt_location = pstmt->stmt_location;
1059  wrapper->stmt_len = pstmt->stmt_len;
1060 
1061  ProcessUtility(wrapper,
1062  queryString,
1064  params,
1065  None_Receiver,
1066  NULL);
1067  }
1068 
1069  /* Need CCI between commands */
1070  if (lnext(l) != NULL)
1072  }
1073 
1074  /*
1075  * The multiple commands generated here are stashed
1076  * individually, so disable collection below.
1077  */
1078  commandCollected = true;
1079  }
1080  break;
1081 
1082  case T_AlterTableStmt:
1083  {
1084  AlterTableStmt *atstmt = (AlterTableStmt *) parsetree;
1085  Oid relid;
1086  List *stmts;
1087  ListCell *l;
1088  LOCKMODE lockmode;
1089 
1090  /*
1091  * Figure out lock mode, and acquire lock. This also does
1092  * basic permissions checks, so that we won't wait for a
1093  * lock on (for example) a relation on which we have no
1094  * permissions.
1095  */
1096  lockmode = AlterTableGetLockLevel(atstmt->cmds);
1097  relid = AlterTableLookupRelation(atstmt, lockmode);
1098 
1099  if (OidIsValid(relid))
1100  {
1101  /* Run parse analysis ... */
1102  stmts = transformAlterTableStmt(relid, atstmt,
1103  queryString);
1104 
1105  /* ... ensure we have an event trigger context ... */
1106  EventTriggerAlterTableStart(parsetree);
1108 
1109  /* ... and do it */
1110  foreach(l, stmts)
1111  {
1112  Node *stmt = (Node *) lfirst(l);
1113 
1114  if (IsA(stmt, AlterTableStmt))
1115  {
1116  /* Do the table alteration proper */
1117  AlterTable(relid, lockmode,
1118  (AlterTableStmt *) stmt);
1119  }
1120  else
1121  {
1122  /*
1123  * Recurse for anything else. If we need to
1124  * do so, "close" the current complex-command
1125  * set, and start a new one at the bottom;
1126  * this is needed to ensure the ordering of
1127  * queued commands is consistent with the way
1128  * they are executed here.
1129  */
1130  PlannedStmt *wrapper;
1131 
1133  wrapper = makeNode(PlannedStmt);
1134  wrapper->commandType = CMD_UTILITY;
1135  wrapper->canSetTag = false;
1136  wrapper->utilityStmt = stmt;
1137  wrapper->stmt_location = pstmt->stmt_location;
1138  wrapper->stmt_len = pstmt->stmt_len;
1139  ProcessUtility(wrapper,
1140  queryString,
1142  params,
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 
1291  if (stmt->concurrent)
1292  PreventTransactionChain(isTopLevel,
1293  "CREATE INDEX CONCURRENTLY");
1294 
1295  /*
1296  * Look up the relation OID just once, right here at the
1297  * beginning, so that we don't end up repeating the name
1298  * lookup later and latching onto a different relation
1299  * partway through. To avoid lock upgrade hazards, it's
1300  * important that we take the strongest lock that will
1301  * eventually be needed here, so the lockmode calculation
1302  * needs to match what DefineIndex() does.
1303  */
1304  lockmode = stmt->concurrent ? ShareUpdateExclusiveLock
1305  : ShareLock;
1306  relid =
1307  RangeVarGetRelidExtended(stmt->relation, lockmode,
1308  false, false,
1310  NULL);
1311 
1312  /* Run parse analysis ... */
1313  stmt = transformIndexStmt(relid, stmt, queryString);
1314 
1315  /* ... and do it */
1316  EventTriggerAlterTableStart(parsetree);
1317  address =
1318  DefineIndex(relid, /* OID of heap relation */
1319  stmt,
1320  InvalidOid, /* no predefined OID */
1321  false, /* is_alter_table */
1322  true, /* check_rights */
1323  false, /* skip_build */
1324  false); /* quiet */
1325 
1326  /*
1327  * Add the CREATE INDEX node itself to stash right away;
1328  * if there were any commands stashed in the ALTER TABLE
1329  * code, we need them to appear after this one.
1330  */
1331  EventTriggerCollectSimpleCommand(address, secondaryObject,
1332  parsetree);
1333  commandCollected = true;
1335  }
1336  break;
1337 
1338  case T_CreateExtensionStmt:
1339  address = CreateExtension(pstate, (CreateExtensionStmt *) parsetree);
1340  break;
1341 
1342  case T_AlterExtensionStmt:
1343  address = ExecAlterExtensionStmt(pstate, (AlterExtensionStmt *) parsetree);
1344  break;
1345 
1348  &secondaryObject);
1349  break;
1350 
1351  case T_CreateFdwStmt:
1352  address = CreateForeignDataWrapper((CreateFdwStmt *) parsetree);
1353  break;
1354 
1355  case T_AlterFdwStmt:
1356  address = AlterForeignDataWrapper((AlterFdwStmt *) parsetree);
1357  break;
1358 
1360  address = CreateForeignServer((CreateForeignServerStmt *) parsetree);
1361  break;
1362 
1364  address = AlterForeignServer((AlterForeignServerStmt *) parsetree);
1365  break;
1366 
1368  address = CreateUserMapping((CreateUserMappingStmt *) parsetree);
1369  break;
1370 
1372  address = AlterUserMapping((AlterUserMappingStmt *) parsetree);
1373  break;
1374 
1375  case T_DropUserMappingStmt:
1376  RemoveUserMapping((DropUserMappingStmt *) parsetree);
1377  /* no commands stashed for DROP */
1378  commandCollected = true;
1379  break;
1380 
1383  /* commands are stashed inside ImportForeignSchema */
1384  commandCollected = true;
1385  break;
1386 
1387  case T_CompositeTypeStmt: /* CREATE TYPE (composite) */
1388  {
1389  CompositeTypeStmt *stmt = (CompositeTypeStmt *) parsetree;
1390 
1391  address = DefineCompositeType(stmt->typevar,
1392  stmt->coldeflist);
1393  }
1394  break;
1395 
1396  case T_CreateEnumStmt: /* CREATE TYPE AS ENUM */
1397  address = DefineEnum((CreateEnumStmt *) parsetree);
1398  break;
1399 
1400  case T_CreateRangeStmt: /* CREATE TYPE AS RANGE */
1401  address = DefineRange((CreateRangeStmt *) parsetree);
1402  break;
1403 
1404  case T_AlterEnumStmt: /* ALTER TYPE (enum) */
1405  address = AlterEnum((AlterEnumStmt *) parsetree);
1406  break;
1407 
1408  case T_ViewStmt: /* CREATE VIEW */
1409  EventTriggerAlterTableStart(parsetree);
1410  address = DefineView((ViewStmt *) parsetree, queryString,
1411  pstmt->stmt_location, pstmt->stmt_len);
1412  EventTriggerCollectSimpleCommand(address, secondaryObject,
1413  parsetree);
1414  /* stashed internally */
1415  commandCollected = true;
1417  break;
1418 
1419  case T_CreateFunctionStmt: /* CREATE FUNCTION */
1420  address = CreateFunction(pstate, (CreateFunctionStmt *) parsetree);
1421  break;
1422 
1423  case T_AlterFunctionStmt: /* ALTER FUNCTION */
1424  address = AlterFunction(pstate, (AlterFunctionStmt *) parsetree);
1425  break;
1426 
1427  case T_RuleStmt: /* CREATE RULE */
1428  address = DefineRule((RuleStmt *) parsetree, queryString);
1429  break;
1430 
1431  case T_CreateSeqStmt:
1432  address = DefineSequence(pstate, (CreateSeqStmt *) parsetree);
1433  break;
1434 
1435  case T_AlterSeqStmt:
1436  address = AlterSequence(pstate, (AlterSeqStmt *) parsetree);
1437  break;
1438 
1439  case T_CreateTableAsStmt:
1440  address = ExecCreateTableAs((CreateTableAsStmt *) parsetree,
1441  queryString, params, completionTag);
1442  break;
1443 
1444  case T_RefreshMatViewStmt:
1445 
1446  /*
1447  * REFRSH CONCURRENTLY executes some DDL commands internally.
1448  * Inhibit DDL command collection here to avoid those commands
1449  * from showing up in the deparsed command queue. The refresh
1450  * command itself is queued, which is enough.
1451  */
1453  PG_TRY();
1454  {
1455  address = ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
1456  queryString, params, completionTag);
1457  }
1458  PG_CATCH();
1459  {
1461  PG_RE_THROW();
1462  }
1463  PG_END_TRY();
1465  break;
1466 
1467  case T_CreateTrigStmt:
1468  address = CreateTrigger((CreateTrigStmt *) parsetree,
1469  queryString, InvalidOid, InvalidOid,
1470  InvalidOid, InvalidOid, false);
1471  break;
1472 
1473  case T_CreatePLangStmt:
1474  address = CreateProceduralLanguage((CreatePLangStmt *) parsetree);
1475  break;
1476 
1477  case T_CreateDomainStmt:
1478  address = DefineDomain((CreateDomainStmt *) parsetree);
1479  break;
1480 
1482  address = CreateConversionCommand((CreateConversionStmt *) parsetree);
1483  break;
1484 
1485  case T_CreateCastStmt:
1486  address = CreateCast((CreateCastStmt *) parsetree);
1487  break;
1488 
1489  case T_CreateOpClassStmt:
1490  DefineOpClass((CreateOpClassStmt *) parsetree);
1491  /* command is stashed in DefineOpClass */
1492  commandCollected = true;
1493  break;
1494 
1495  case T_CreateOpFamilyStmt:
1496  address = DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1497  break;
1498 
1499  case T_CreateTransformStmt:
1500  address = CreateTransform((CreateTransformStmt *) parsetree);
1501  break;
1502 
1503  case T_AlterOpFamilyStmt:
1504  AlterOpFamily((AlterOpFamilyStmt *) parsetree);
1505  /* commands are stashed in AlterOpFamily */
1506  commandCollected = true;
1507  break;
1508 
1510  address = AlterTSDictionary((AlterTSDictionaryStmt *) parsetree);
1511  break;
1512 
1515 
1516  /*
1517  * Commands are stashed in MakeConfigurationMapping and
1518  * DropConfigurationMapping, which are called from
1519  * AlterTSConfiguration
1520  */
1521  commandCollected = true;
1522  break;
1523 
1526  /* commands are stashed in AlterTableMoveAll */
1527  commandCollected = true;
1528  break;
1529 
1530  case T_DropStmt:
1531  ExecDropStmt((DropStmt *) parsetree, isTopLevel);
1532  /* no commands stashed for DROP */
1533  commandCollected = true;
1534  break;
1535 
1536  case T_RenameStmt:
1537  address = ExecRenameStmt((RenameStmt *) parsetree);
1538  break;
1539 
1541  address =
1543  &secondaryObject);
1544  break;
1545 
1547  address =
1549  &secondaryObject);
1550  break;
1551 
1552  case T_AlterOwnerStmt:
1553  address = ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
1554  break;
1555 
1556  case T_AlterOperatorStmt:
1557  address = AlterOperator((AlterOperatorStmt *) parsetree);
1558  break;
1559 
1560  case T_CommentStmt:
1561  address = CommentObject((CommentStmt *) parsetree);
1562  break;
1563 
1564  case T_GrantStmt:
1565  ExecuteGrantStmt((GrantStmt *) parsetree);
1566  /* commands are stashed in ExecGrantStmt_oids */
1567  commandCollected = true;
1568  break;
1569 
1570  case T_DropOwnedStmt:
1571  DropOwnedObjects((DropOwnedStmt *) parsetree);
1572  /* no commands stashed for DROP */
1573  commandCollected = true;
1574  break;
1575 
1579  commandCollected = true;
1580  break;
1581 
1582  case T_CreatePolicyStmt: /* CREATE POLICY */
1583  address = CreatePolicy((CreatePolicyStmt *) parsetree);
1584  break;
1585 
1586  case T_AlterPolicyStmt: /* ALTER POLICY */
1587  address = AlterPolicy((AlterPolicyStmt *) parsetree);
1588  break;
1589 
1590  case T_SecLabelStmt:
1591  address = ExecSecLabelStmt((SecLabelStmt *) parsetree);
1592  break;
1593 
1594  case T_CreateAmStmt:
1595  address = CreateAccessMethod((CreateAmStmt *) parsetree);
1596  break;
1597 
1599  address = CreatePublication((CreatePublicationStmt *) parsetree);
1600  break;
1601 
1603  AlterPublication((AlterPublicationStmt *) parsetree);
1604  /*
1605  * AlterPublication calls EventTriggerCollectSimpleCommand
1606  * directly
1607  */
1608  commandCollected = true;
1609  break;
1610 
1612  address = CreateSubscription((CreateSubscriptionStmt *) parsetree,
1613  isTopLevel);
1614  break;
1615 
1617  address = AlterSubscription((AlterSubscriptionStmt *) parsetree);
1618  break;
1619 
1621  DropSubscription((DropSubscriptionStmt *) parsetree, isTopLevel);
1622  /* no commands stashed for DROP */
1623  commandCollected = true;
1624  break;
1625 
1626  case T_CreateStatsStmt:
1627  address = CreateStatistics((CreateStatsStmt *) parsetree);
1628  break;
1629 
1630  case T_AlterCollationStmt:
1631  address = AlterCollation((AlterCollationStmt *) parsetree);
1632  break;
1633 
1634  default:
1635  elog(ERROR, "unrecognized node type: %d",
1636  (int) nodeTag(parsetree));
1637  break;
1638  }
1639 
1640  /*
1641  * Remember the object so that ddl_command_end event triggers have
1642  * access to it.
1643  */
1644  if (!commandCollected)
1645  EventTriggerCollectSimpleCommand(address, secondaryObject,
1646  parsetree);
1647 
1648  if (isCompleteQuery)
1649  {
1650  EventTriggerSQLDrop(parsetree);
1651  EventTriggerDDLCommandEnd(parsetree);
1652  }
1653  }
1654  PG_CATCH();
1655  {
1656  if (needCleanup)
1658  PG_RE_THROW();
1659  }
1660  PG_END_TRY();
1661 
1662  if (needCleanup)
1664 }
ObjectAddress AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
Definition: sequence.c:410
ObjectAddress DefineTSParser(List *names, List *parameters)
Definition: tsearchcmds.c:176
bytea * heap_reloptions(char relkind, Datum reloptions, bool validate)
Definition: reloptions.c:1402
#define NIL
Definition: pg_list.h:69
ObjectAddress AlterForeignServer(AlterForeignServerStmt *stmt)
Definition: foreigncmds.c:985
void CreateForeignTable(CreateForeignTableStmt *stmt, Oid relid)
Definition: foreigncmds.c:1446
void DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
ObjectAddress DefineOperator(List *names, List *parameters)
Definition: operatorcmds.c:68
ObjectAddress AlterSubscription(AlterSubscriptionStmt *stmt)
#define IsA(nodeptr, _type_)
Definition: nodes.h:555
ObjectAddress DefineTSConfiguration(List *names, List *parameters, ObjectAddress *copied)
Definition: tsearchcmds.c:960
ObjectAddress CreateTransform(CreateTransformStmt *stmt)
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1670
ObjectAddress AlterDomainAddConstraint(List *names, Node *newConstraint, ObjectAddress *constrAddr)
Definition: typecmds.c:2470
ObjectAddress CreateForeignDataWrapper(CreateFdwStmt *stmt)
Definition: foreigncmds.c:560
DropBehavior behavior
Definition: parsenodes.h:1768
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
Definition: functioncmds.c:861
int LOCKMODE
Definition: lockdefs.h:26
ObjectAddress CreatePublication(CreatePublicationStmt *stmt)
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:44
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok, bool nowait, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:217
Oid AlterTableLookupRelation(AlterTableStmt *stmt, LOCKMODE lockmode)
Definition: tablecmds.c:2999
ObjectAddress AlterEnum(AlterEnumStmt *stmt)
Definition: typecmds.c:1228
ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, bool isInternal)
Definition: trigger.c:138
void DropOwnedObjects(DropOwnedStmt *stmt)
Definition: user.c:1321
RangeVar * typevar
Definition: parsenodes.h:2886
void EventTriggerDDLCommandEnd(Node *parsetree)
Definition: nodes.h:504
ObjectAddress ExecAlterExtensionContentsStmt(AlterExtensionContentsStmt *stmt, ObjectAddress *objAddr)
Definition: extension.c:3164
ObjectAddress CreateProceduralLanguage(CreatePLangStmt *stmt)
Definition: proclang.c:64
void EventTriggerInhibitCommandCollection(void)
ObjectAddress DefineDomain(CreateDomainStmt *stmt)
Definition: typecmds.c:729
ObjectAddress DefineCompositeType(RangeVar *typevar, List *coldeflist)
Definition: typecmds.c:2068
void AlterTable(Oid relid, LOCKMODE lockmode, AlterTableStmt *stmt)
Definition: tablecmds.c:3049
ObjectAddress AlterDomainValidateConstraint(List *names, char *constrName)
Definition: typecmds.c:2579
unsigned int Oid
Definition: postgres_ext.h:31
ObjectAddress DefineOpClass(CreateOpClassStmt *stmt)
Definition: opclasscmds.c:323
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:538
int stmt_len
Definition: plannodes.h:87
void EventTriggerAlterTableStart(Node *parsetree)
char * relname
Definition: primnodes.h:68
ObjectAddress DefineAggregate(ParseState *pstate, List *name, List *args, bool oldstyle, List *parameters)
Definition: aggregatecmds.c:54
RangeVar * relation
Definition: parsenodes.h:2640
ObjectAddress AlterPolicy(AlterPolicyStmt *stmt)
Definition: policy.c:877
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
Definition: tablecmds.c:12634
List * args
Definition: parsenodes.h:2436
#define ERROR
Definition: elog.h:43
ObjectAddress AlterDomainDefault(List *names, Node *defaultRaw)
Definition: typecmds.c:2126
ObjectAddress AlterOperator(AlterOperatorStmt *stmt)
Definition: operatorcmds.c:385
void EventTriggerDDLCommandStart(Node *parsetree)
ObjectAddress CreatePolicy(CreatePolicyStmt *stmt)
Definition: policy.c:682
void EventTriggerSQLDrop(Node *parsetree)
ObjectAddress AlterTSConfiguration(AlterTSConfigurationStmt *stmt)
Definition: tsearchcmds.c:1173
ObjectAddress AlterDomainNotNull(List *names, bool notNull)
Definition: typecmds.c:2265
Oid RemoveUserMapping(DropUserMappingStmt *stmt)
Definition: foreigncmds.c:1345
ObjectAddress CreateUserMapping(CreateUserMappingStmt *stmt)
Definition: foreigncmds.c:1135
int stmt_location
Definition: plannodes.h:86
List * transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, const char *queryString)
ObjectAddress AlterTSDictionary(AlterTSDictionaryStmt *stmt)
Definition: tsearchcmds.c:525
Node * utilityStmt
Definition: plannodes.h:83
ObjectAddress DefineRange(CreateRangeStmt *stmt)
Definition: typecmds.c:1298
ObjectAddress DefineEnum(CreateEnumStmt *stmt)
Definition: typecmds.c:1107
ObjectAddress DefineView(ViewStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: view.c:417
Oid CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: schemacmds.c:51
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
#define HEAP_RELOPT_NAMESPACES
Definition: reloptions.h:58
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:114
#define lnext(lc)
Definition: pg_list.h:105
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
Definition: tablecmds.c:483
#define ereport(elevel, rest)
Definition: elog.h:122
void ExecAlterDefaultPrivilegesStmt(ParseState *pstate, AlterDefaultPrivilegesStmt *stmt)
Definition: aclchk.c:863
ObjectAddress DefineType(ParseState *pstate, List *names, List *parameters)
Definition: typecmds.c:116
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, DestReceiver *dest, char *completionTag)
Definition: utility.c:332
ObjectAddress CreateExtension(ParseState *pstate, CreateExtensionStmt *stmt)
Definition: extension.c:1615
void EventTriggerEndCompleteQuery(void)
LOCKMODE AlterTableGetLockLevel(List *cmds)
Definition: tablecmds.c:3118
ObjectAddress CreateForeignServer(CreateForeignServerStmt *stmt)
Definition: foreigncmds.c:861
bool canSetTag
Definition: plannodes.h:53
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
void EventTriggerUndoInhibitCommandCollection(void)
uintptr_t Datum
Definition: postgres.h:372
CmdType commandType
Definition: plannodes.h:45
void CommandCounterIncrement(void)
Definition: xact.c:922
ObjectType kind
Definition: parsenodes.h:2433
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:423
void EventTriggerCollectAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt)
Datum transformRelOptions(Datum oldOptions, List *defList, char *namspace, char *validnsps[], bool ignoreOids, bool isReset)
Definition: reloptions.c:736
#define InvalidOid
Definition: postgres_ext.h:36
ObjectAddress DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_exists)
Definition: collationcmds.c:44
List * defnames
Definition: parsenodes.h:2435
#define NOTICE
Definition: elog.h:37
ObjectAddress CreateCast(CreateCastStmt *stmt)
ObjectAddress ExecAlterExtensionStmt(ParseState *pstate, AlterExtensionStmt *stmt)
Definition: extension.c:2856
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:461
#define PG_CATCH()
Definition: elog.h:293
#define makeNode(_type_)
Definition: nodes.h:552
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
#define NULL
Definition: c.h:229
ObjectAddress DefineTSDictionary(List *names, List *parameters)
Definition: tsearchcmds.c:409
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
ObjectAddress DefineIndex(Oid relationId, IndexStmt *stmt, Oid indexRelationId, bool is_alter_table, bool check_rights, bool skip_build, bool quiet)
Definition: indexcmds.c:305
ObjectAddress CreateConversionCommand(CreateConversionStmt *stmt)
Oid AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
Definition: tablecmds.c:10289
ObjectAddress AlterForeignDataWrapper(AlterFdwStmt *stmt)
Definition: foreigncmds.c:673
List * transformCreateStmt(CreateStmt *stmt, const char *queryString)
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition: alter.c:766
#define PG_RE_THROW()
Definition: elog.h:314
ObjectAddress ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, ParamListInfo params, char *completionTag)
Definition: createas.c:224
#define nodeTag(nodeptr)
Definition: nodes.h:509
void EventTriggerAlterTableRelid(Oid objectId)
Oid AlterOpFamily(AlterOpFamilyStmt *stmt)
Definition: opclasscmds.c:763
ObjectAddress DefineOpFamily(CreateOpFamilyStmt *stmt)
Definition: opclasscmds.c:718
ObjectAddress AlterDomainDropConstraint(List *names, const char *constrName, DropBehavior behavior, bool missing_ok)
Definition: typecmds.c:2380
bool concurrent
Definition: parsenodes.h:2656
ObjectAddress DefineRule(RuleStmt *stmt, const char *queryString)
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:1641
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:2438
ObjectAddress ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, ParamListInfo params, char *completionTag)
Definition: matview.c:137
ObjectAddress CreateAccessMethod(CreateAmStmt *stmt)
Definition: amcmds.c:41
List * definition
Definition: parsenodes.h:2437
#define elog
Definition: elog.h:219
void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
#define PG_TRY()
Definition: elog.h:284
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
#define RELKIND_RELATION
Definition: pg_class.h:160
Definition: pg_list.h:45
ObjectAddress AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt)
bool oldstyle
Definition: parsenodes.h:2434
#define PG_END_TRY()
Definition: elog.h:300
void AlterPublication(AlterPublicationStmt *stmt)
bool EventTriggerBeginCompleteQuery(void)
void PreventTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3154
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:385
void EventTriggerAlterTableEnd(void)
ObjectAddress CreateStatistics(CreateStatsStmt *stmt)
Definition: statscmds.c:45
void standard_ProcessUtility ( PlannedStmt pstmt,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
DestReceiver dest,
char *  completionTag 
)

Definition at line 370 of file utility.c.

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterSystemSetConfigFile(), AlterTableSpaceOptions(), DefElem::arg, Assert, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), BeginTransactionBlock(), 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, EventTriggerSupportsGrantObjectType(), EventTriggerSupportsObjectType(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteDoStmt(), ExecuteGrantStmt(), ExecuteQuery(), ExecuteTruncate(), ExecVacuum(), ExplainQuery(), LoadStmt::filename, FinishPreparedTransaction(), free_parsestate(), GetPGVariable(), TransactionStmt::gid, GrantRole(), TransactionStmt::kind, ReindexStmt::kind, lfirst, list_make1, load_file(), LockTableCommand(), make_parsestate(), DropdbStmt::missing_ok, name, VariableShowStmt::name, ReindexStmt::name, nodeTag, NULL, AlterObjectDependsStmt::objectType, AlterObjectSchemaStmt::objectType, AlterOwnerStmt::objectType, GrantStmt::objtype, CommentStmt::objtype, SecLabelStmt::objtype, TransactionStmt::options, VacuumStmt::options, ReindexStmt::options, ParseState::p_sourcetext, NotifyStmt::payload, PerformCursorOpen(), PerformPortalClose(), PerformPortalFetch(), PointerIsValid, ClosePortalStmt::portalname, PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventTransactionChain(), PROCESS_UTILITY_TOPLEVEL, ProcessUtilitySlow(), ReassignOwnedObjects(), RecoveryInProgress(), REINDEX_OBJECT_DATABASE, REINDEX_OBJECT_INDEX, REINDEX_OBJECT_SCHEMA, REINDEX_OBJECT_SYSTEM, REINDEX_OBJECT_TABLE, ReindexIndex(), ReindexMultipleTables(), ReindexTable(), ReindexStmt::relation, ReleaseSavepoint(), DropStmt::removeType, RenameStmt::renameType, RequestCheckpoint(), RequireTransactionChain(), RollbackToSavepoint(), SetPGVariable(), snprintf(), PlannedStmt::stmt_len, PlannedStmt::stmt_location, strVal, superuser(), T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterEventTrigStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOwnerStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSystemStmt, T_AlterTableSpaceOptionsStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreatedbStmt, T_CreateEventTrigStmt, T_CreateRoleStmt, T_CreateTableSpaceStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropRoleStmt, T_DropStmt, T_DropTableSpaceStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PrepareStmt, T_ReassignOwnedStmt, T_ReindexStmt, T_RenameStmt, T_SecLabelStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, UINT64_FORMAT, UserAbortTransactionBlock(), PlannedStmt::utilityStmt, VACOPT_VACUUM, and WarnNoTransactionChain().

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

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

Definition at line 1844 of file utility.c.

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

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

1845 {
1846  Query *qry;
1847 
1848  switch (nodeTag(parsetree))
1849  {
1850  case T_DeclareCursorStmt:
1851  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
1852  if (qry->commandType == CMD_UTILITY)
1853  return UtilityContainsQuery(qry->utilityStmt);
1854  return qry;
1855 
1856  case T_ExplainStmt:
1857  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
1858  if (qry->commandType == CMD_UTILITY)
1859  return UtilityContainsQuery(qry->utilityStmt);
1860  return qry;
1861 
1862  case T_CreateTableAsStmt:
1863  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
1864  if (qry->commandType == CMD_UTILITY)
1865  return UtilityContainsQuery(qry->utilityStmt);
1866  return qry;
1867 
1868  default:
1869  return NULL;
1870  }
1871 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:573
Node * utilityStmt
Definition: parsenodes.h:111
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:1844
CmdType commandType
Definition: parsenodes.h:103
#define NULL
Definition: c.h:229
#define nodeTag(nodeptr)
Definition: nodes.h:509
bool UtilityReturnsTuples ( Node parsetree)

Definition at line 1703 of file utility.c.

References FetchPreparedStatement(), GetPortalByName(), FetchStmt::ismove, ExecuteStmt::name, nodeTag, PreparedStatement::plansource, PortalIsValid, FetchStmt::portalname, CachedPlanSource::resultDesc, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_VariableShowStmt, and PortalData::tupDesc.

Referenced by ChoosePortalStrategy().

1704 {
1705  switch (nodeTag(parsetree))
1706  {
1707  case T_FetchStmt:
1708  {
1709  FetchStmt *stmt = (FetchStmt *) parsetree;
1710  Portal portal;
1711 
1712  if (stmt->ismove)
1713  return false;
1714  portal = GetPortalByName(stmt->portalname);
1715  if (!PortalIsValid(portal))
1716  return false; /* not our business to raise error */
1717  return portal->tupDesc ? true : false;
1718  }
1719 
1720  case T_ExecuteStmt:
1721  {
1722  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1723  PreparedStatement *entry;
1724 
1725  entry = FetchPreparedStatement(stmt->name, false);
1726  if (!entry)
1727  return false; /* not our business to raise error */
1728  if (entry->plansource->resultDesc)
1729  return true;
1730  return false;
1731  }
1732 
1733  case T_ExplainStmt:
1734  return true;
1735 
1736  case T_VariableShowStmt:
1737  return true;
1738 
1739  default:
1740  return false;
1741  }
1742 }
CachedPlanSource * plansource
Definition: prepare.h:31
Portal GetPortalByName(const char *name)
Definition: portalmem.c:129
TupleDesc resultDesc
Definition: plancache.h:91
char * portalname
Definition: parsenodes.h:2621
#define PortalIsValid(p)
Definition: portal.h:198
bool ismove
Definition: parsenodes.h:2622
TupleDesc tupDesc
Definition: portal.h:154
#define nodeTag(nodeptr)
Definition: nodes.h:509
char * name
Definition: parsenodes.h:3240