PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
utility.h File Reference
#include "tcop/tcopprot.h"
Include dependency graph for utility.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

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

Enumerations

enum  ProcessUtilityContext { PROCESS_UTILITY_TOPLEVEL, PROCESS_UTILITY_QUERY, PROCESS_UTILITY_SUBCOMMAND }
 

Functions

void ProcessUtility (PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
 
void standard_ProcessUtility (PlannedStmt *pstmt, const char *queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, char *completionTag)
 
bool UtilityReturnsTuples (Node *parsetree)
 
TupleDesc UtilityTupleDescriptor (Node *parsetree)
 
QueryUtilityContainsQuery (Node *parsetree)
 
const char * CreateCommandTag (Node *parsetree)
 
LogStmtLevel GetCommandLogLevel (Node *parsetree)
 
bool CommandIsReadOnly (PlannedStmt *pstmt)
 

Variables

PGDLLIMPORT
ProcessUtility_hook_type 
ProcessUtility_hook
 

Typedef Documentation

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

Definition at line 27 of file utility.h.

Enumeration Type Documentation

Enumerator
PROCESS_UTILITY_TOPLEVEL 
PROCESS_UTILITY_QUERY 
PROCESS_UTILITY_SUBCOMMAND 

Definition at line 19 of file utility.h.

20 {
21  PROCESS_UTILITY_TOPLEVEL, /* toplevel interactive command */
22  PROCESS_UTILITY_QUERY, /* a complete query, but not toplevel */
23  PROCESS_UTILITY_SUBCOMMAND /* a portion of a query */
ProcessUtilityContext
Definition: utility.h:19

Function Documentation

bool CommandIsReadOnly ( PlannedStmt pstmt)

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

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

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

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

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

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

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

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

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

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

1857 {
1858  Query *qry;
1859 
1860  switch (nodeTag(parsetree))
1861  {
1862  case T_DeclareCursorStmt:
1863  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
1864  if (qry->commandType == CMD_UTILITY)
1865  return UtilityContainsQuery(qry->utilityStmt);
1866  return qry;
1867 
1868  case T_ExplainStmt:
1869  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
1870  if (qry->commandType == CMD_UTILITY)
1871  return UtilityContainsQuery(qry->utilityStmt);
1872  return qry;
1873 
1874  case T_CreateTableAsStmt:
1875  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
1876  if (qry->commandType == CMD_UTILITY)
1877  return UtilityContainsQuery(qry->utilityStmt);
1878  return qry;
1879 
1880  default:
1881  return NULL;
1882  }
1883 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
Node * utilityStmt
Definition: parsenodes.h:118
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:1856
CmdType commandType
Definition: parsenodes.h:110
#define NULL
Definition: c.h:229
#define nodeTag(nodeptr)
Definition: nodes.h:514
bool UtilityReturnsTuples ( Node parsetree)

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

1716 {
1717  switch (nodeTag(parsetree))
1718  {
1719  case T_FetchStmt:
1720  {
1721  FetchStmt *stmt = (FetchStmt *) parsetree;
1722  Portal portal;
1723 
1724  if (stmt->ismove)
1725  return false;
1726  portal = GetPortalByName(stmt->portalname);
1727  if (!PortalIsValid(portal))
1728  return false; /* not our business to raise error */
1729  return portal->tupDesc ? true : false;
1730  }
1731 
1732  case T_ExecuteStmt:
1733  {
1734  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1735  PreparedStatement *entry;
1736 
1737  entry = FetchPreparedStatement(stmt->name, false);
1738  if (!entry)
1739  return false; /* not our business to raise error */
1740  if (entry->plansource->resultDesc)
1741  return true;
1742  return false;
1743  }
1744 
1745  case T_ExplainStmt:
1746  return true;
1747 
1748  case T_VariableShowStmt:
1749  return true;
1750 
1751  default:
1752  return false;
1753  }
1754 }
CachedPlanSource * plansource
Definition: prepare.h:31
Portal GetPortalByName(const char *name)
Definition: portalmem.c:129
TupleDesc resultDesc
Definition: plancache.h:92
char * portalname
Definition: parsenodes.h:2665
#define PortalIsValid(p)
Definition: portal.h:199
bool ismove
Definition: parsenodes.h:2666
TupleDesc tupDesc
Definition: portal.h:155
#define nodeTag(nodeptr)
Definition: nodes.h:514
char * name
Definition: parsenodes.h:3284
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:494
TupleDesc UtilityTupleDescriptor ( Node parsetree)

Definition at line 1765 of file utility.c.

References CreateTupleDescCopy(), ExplainResultDesc(), FetchPreparedStatement(), FetchPreparedStatementResultDesc(), GetPGVariableResultDesc(), GetPortalByName(), FetchStmt::ismove, VariableShowStmt::name, ExecuteStmt::name, nodeTag, NULL, PortalIsValid, FetchStmt::portalname, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_VariableShowStmt, and PortalData::tupDesc.

Referenced by PlanCacheComputeResultDesc(), and PortalStart().

1766 {
1767  switch (nodeTag(parsetree))
1768  {
1769  case T_FetchStmt:
1770  {
1771  FetchStmt *stmt = (FetchStmt *) parsetree;
1772  Portal portal;
1773 
1774  if (stmt->ismove)
1775  return NULL;
1776  portal = GetPortalByName(stmt->portalname);
1777  if (!PortalIsValid(portal))
1778  return NULL; /* not our business to raise error */
1779  return CreateTupleDescCopy(portal->tupDesc);
1780  }
1781 
1782  case T_ExecuteStmt:
1783  {
1784  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1785  PreparedStatement *entry;
1786 
1787  entry = FetchPreparedStatement(stmt->name, false);
1788  if (!entry)
1789  return NULL; /* not our business to raise error */
1790  return FetchPreparedStatementResultDesc(entry);
1791  }
1792 
1793  case T_ExplainStmt:
1794  return ExplainResultDesc((ExplainStmt *) parsetree);
1795 
1796  case T_VariableShowStmt:
1797  {
1798  VariableShowStmt *n = (VariableShowStmt *) parsetree;
1799 
1800  return GetPGVariableResultDesc(n->name);
1801  }
1802 
1803  default:
1804  return NULL;
1805  }
1806 }
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:7903
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:141
Portal GetPortalByName(const char *name)
Definition: portalmem.c:129
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:302
char * portalname
Definition: parsenodes.h:2665
#define PortalIsValid(p)
Definition: portal.h:199
bool ismove
Definition: parsenodes.h:2666
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:526
TupleDesc tupDesc
Definition: portal.h:155
#define NULL
Definition: c.h:229
#define nodeTag(nodeptr)
Definition: nodes.h:514
char * name
Definition: parsenodes.h:3284
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:494

Variable Documentation

Definition at line 73 of file utility.c.

Referenced by _PG_fini(), _PG_init(), and ProcessUtility().