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, 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, 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)
 
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, 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 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:559
#define WARNING
Definition: elog.h:40
CmdType commandType
Definition: plannodes.h:45
List * rowMarks
Definition: plannodes.h:72
#define Assert(condition)
Definition: c.h:670
bool hasModifyingCTE
Definition: plannodes.h:51
#define elog
Definition: elog.h:219
const char* CreateCommandTag ( Node parsetree)

Definition at line 2012 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_TABLE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ClosePortalStmt::portalname, PlannedStmt::rowMarks, Query::rowMarks, 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_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().

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

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

2836 {
2837  LogStmtLevel lev;
2838 
2839  switch (nodeTag(parsetree))
2840  {
2841  /* recurse if we're given a RawStmt */
2842  case T_RawStmt:
2843  lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
2844  break;
2845 
2846  /* raw plannable queries */
2847  case T_InsertStmt:
2848  case T_DeleteStmt:
2849  case T_UpdateStmt:
2850  lev = LOGSTMT_MOD;
2851  break;
2852 
2853  case T_SelectStmt:
2854  if (((SelectStmt *) parsetree)->intoClause)
2855  lev = LOGSTMT_DDL; /* SELECT INTO */
2856  else
2857  lev = LOGSTMT_ALL;
2858  break;
2859 
2860  /* utility statements --- same whether raw or cooked */
2861  case T_TransactionStmt:
2862  lev = LOGSTMT_ALL;
2863  break;
2864 
2865  case T_DeclareCursorStmt:
2866  lev = LOGSTMT_ALL;
2867  break;
2868 
2869  case T_ClosePortalStmt:
2870  lev = LOGSTMT_ALL;
2871  break;
2872 
2873  case T_FetchStmt:
2874  lev = LOGSTMT_ALL;
2875  break;
2876 
2877  case T_CreateSchemaStmt:
2878  lev = LOGSTMT_DDL;
2879  break;
2880 
2881  case T_CreateStmt:
2883  lev = LOGSTMT_DDL;
2884  break;
2885 
2887  case T_DropTableSpaceStmt:
2889  lev = LOGSTMT_DDL;
2890  break;
2891 
2892  case T_CreateExtensionStmt:
2893  case T_AlterExtensionStmt:
2895  lev = LOGSTMT_DDL;
2896  break;
2897 
2898  case T_CreateFdwStmt:
2899  case T_AlterFdwStmt:
2904  case T_DropUserMappingStmt:
2906  lev = LOGSTMT_DDL;
2907  break;
2908 
2909  case T_DropStmt:
2910  lev = LOGSTMT_DDL;
2911  break;
2912 
2913  case T_TruncateStmt:
2914  lev = LOGSTMT_MOD;
2915  break;
2916 
2917  case T_CommentStmt:
2918  lev = LOGSTMT_DDL;
2919  break;
2920 
2921  case T_SecLabelStmt:
2922  lev = LOGSTMT_DDL;
2923  break;
2924 
2925  case T_CopyStmt:
2926  if (((CopyStmt *) parsetree)->is_from)
2927  lev = LOGSTMT_MOD;
2928  else
2929  lev = LOGSTMT_ALL;
2930  break;
2931 
2932  case T_PrepareStmt:
2933  {
2934  PrepareStmt *stmt = (PrepareStmt *) parsetree;
2935 
2936  /* Look through a PREPARE to the contained stmt */
2937  lev = GetCommandLogLevel(stmt->query);
2938  }
2939  break;
2940 
2941  case T_ExecuteStmt:
2942  {
2943  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2944  PreparedStatement *ps;
2945 
2946  /* Look through an EXECUTE to the referenced stmt */
2947  ps = FetchPreparedStatement(stmt->name, false);
2948  if (ps && ps->plansource->raw_parse_tree)
2950  else
2951  lev = LOGSTMT_ALL;
2952  }
2953  break;
2954 
2955  case T_DeallocateStmt:
2956  lev = LOGSTMT_ALL;
2957  break;
2958 
2959  case T_RenameStmt:
2960  lev = LOGSTMT_DDL;
2961  break;
2962 
2964  lev = LOGSTMT_DDL;
2965  break;
2966 
2968  lev = LOGSTMT_DDL;
2969  break;
2970 
2971  case T_AlterOwnerStmt:
2972  lev = LOGSTMT_DDL;
2973  break;
2974 
2976  case T_AlterTableStmt:
2977  lev = LOGSTMT_DDL;
2978  break;
2979 
2980  case T_AlterDomainStmt:
2981  lev = LOGSTMT_DDL;
2982  break;
2983 
2984  case T_GrantStmt:
2985  lev = LOGSTMT_DDL;
2986  break;
2987 
2988  case T_GrantRoleStmt:
2989  lev = LOGSTMT_DDL;
2990  break;
2991 
2993  lev = LOGSTMT_DDL;
2994  break;
2995 
2996  case T_DefineStmt:
2997  lev = LOGSTMT_DDL;
2998  break;
2999 
3000  case T_CompositeTypeStmt:
3001  lev = LOGSTMT_DDL;
3002  break;
3003 
3004  case T_CreateEnumStmt:
3005  lev = LOGSTMT_DDL;
3006  break;
3007 
3008  case T_CreateRangeStmt:
3009  lev = LOGSTMT_DDL;
3010  break;
3011 
3012  case T_AlterEnumStmt:
3013  lev = LOGSTMT_DDL;
3014  break;
3015 
3016  case T_ViewStmt:
3017  lev = LOGSTMT_DDL;
3018  break;
3019 
3020  case T_CreateFunctionStmt:
3021  lev = LOGSTMT_DDL;
3022  break;
3023 
3024  case T_AlterFunctionStmt:
3025  lev = LOGSTMT_DDL;
3026  break;
3027 
3028  case T_IndexStmt:
3029  lev = LOGSTMT_DDL;
3030  break;
3031 
3032  case T_RuleStmt:
3033  lev = LOGSTMT_DDL;
3034  break;
3035 
3036  case T_CreateSeqStmt:
3037  lev = LOGSTMT_DDL;
3038  break;
3039 
3040  case T_AlterSeqStmt:
3041  lev = LOGSTMT_DDL;
3042  break;
3043 
3044  case T_DoStmt:
3045  lev = LOGSTMT_ALL;
3046  break;
3047 
3048  case T_CreatedbStmt:
3049  lev = LOGSTMT_DDL;
3050  break;
3051 
3052  case T_AlterDatabaseStmt:
3053  lev = LOGSTMT_DDL;
3054  break;
3055 
3057  lev = LOGSTMT_DDL;
3058  break;
3059 
3060  case T_DropdbStmt:
3061  lev = LOGSTMT_DDL;
3062  break;
3063 
3064  case T_NotifyStmt:
3065  lev = LOGSTMT_ALL;
3066  break;
3067 
3068  case T_ListenStmt:
3069  lev = LOGSTMT_ALL;
3070  break;
3071 
3072  case T_UnlistenStmt:
3073  lev = LOGSTMT_ALL;
3074  break;
3075 
3076  case T_LoadStmt:
3077  lev = LOGSTMT_ALL;
3078  break;
3079 
3080  case T_ClusterStmt:
3081  lev = LOGSTMT_DDL;
3082  break;
3083 
3084  case T_VacuumStmt:
3085  lev = LOGSTMT_ALL;
3086  break;
3087 
3088  case T_ExplainStmt:
3089  {
3090  ExplainStmt *stmt = (ExplainStmt *) parsetree;
3091  bool analyze = false;
3092  ListCell *lc;
3093 
3094  /* Look through an EXPLAIN ANALYZE to the contained stmt */
3095  foreach(lc, stmt->options)
3096  {
3097  DefElem *opt = (DefElem *) lfirst(lc);
3098 
3099  if (strcmp(opt->defname, "analyze") == 0)
3100  analyze = defGetBoolean(opt);
3101  /* don't "break", as explain.c will use the last value */
3102  }
3103  if (analyze)
3104  return GetCommandLogLevel(stmt->query);
3105 
3106  /* Plain EXPLAIN isn't so interesting */
3107  lev = LOGSTMT_ALL;
3108  }
3109  break;
3110 
3111  case T_CreateTableAsStmt:
3112  lev = LOGSTMT_DDL;
3113  break;
3114 
3115  case T_RefreshMatViewStmt:
3116  lev = LOGSTMT_DDL;
3117  break;
3118 
3119  case T_AlterSystemStmt:
3120  lev = LOGSTMT_DDL;
3121  break;
3122 
3123  case T_VariableSetStmt:
3124  lev = LOGSTMT_ALL;
3125  break;
3126 
3127  case T_VariableShowStmt:
3128  lev = LOGSTMT_ALL;
3129  break;
3130 
3131  case T_DiscardStmt:
3132  lev = LOGSTMT_ALL;
3133  break;
3134 
3135  case T_CreateTrigStmt:
3136  lev = LOGSTMT_DDL;
3137  break;
3138 
3139  case T_CreateEventTrigStmt:
3140  lev = LOGSTMT_DDL;
3141  break;
3142 
3143  case T_AlterEventTrigStmt:
3144  lev = LOGSTMT_DDL;
3145  break;
3146 
3147  case T_CreatePLangStmt:
3148  lev = LOGSTMT_DDL;
3149  break;
3150 
3151  case T_CreateDomainStmt:
3152  lev = LOGSTMT_DDL;
3153  break;
3154 
3155  case T_CreateRoleStmt:
3156  lev = LOGSTMT_DDL;
3157  break;
3158 
3159  case T_AlterRoleStmt:
3160  lev = LOGSTMT_DDL;
3161  break;
3162 
3163  case T_AlterRoleSetStmt:
3164  lev = LOGSTMT_DDL;
3165  break;
3166 
3167  case T_DropRoleStmt:
3168  lev = LOGSTMT_DDL;
3169  break;
3170 
3171  case T_DropOwnedStmt:
3172  lev = LOGSTMT_DDL;
3173  break;
3174 
3175  case T_ReassignOwnedStmt:
3176  lev = LOGSTMT_DDL;
3177  break;
3178 
3179  case T_LockStmt:
3180  lev = LOGSTMT_ALL;
3181  break;
3182 
3183  case T_ConstraintsSetStmt:
3184  lev = LOGSTMT_ALL;
3185  break;
3186 
3187  case T_CheckPointStmt:
3188  lev = LOGSTMT_ALL;
3189  break;
3190 
3191  case T_ReindexStmt:
3192  lev = LOGSTMT_ALL; /* should this be DDL? */
3193  break;
3194 
3196  lev = LOGSTMT_DDL;
3197  break;
3198 
3199  case T_CreateCastStmt:
3200  lev = LOGSTMT_DDL;
3201  break;
3202 
3203  case T_CreateOpClassStmt:
3204  lev = LOGSTMT_DDL;
3205  break;
3206 
3207  case T_CreateOpFamilyStmt:
3208  lev = LOGSTMT_DDL;
3209  break;
3210 
3211  case T_CreateTransformStmt:
3212  lev = LOGSTMT_DDL;
3213  break;
3214 
3215  case T_AlterOpFamilyStmt:
3216  lev = LOGSTMT_DDL;
3217  break;
3218 
3219  case T_CreatePolicyStmt:
3220  lev = LOGSTMT_DDL;
3221  break;
3222 
3223  case T_AlterPolicyStmt:
3224  lev = LOGSTMT_DDL;
3225  break;
3226 
3228  lev = LOGSTMT_DDL;
3229  break;
3230 
3232  lev = LOGSTMT_DDL;
3233  break;
3234 
3235  case T_CreateAmStmt:
3236  lev = LOGSTMT_DDL;
3237  break;
3238 
3240  lev = LOGSTMT_DDL;
3241  break;
3242 
3244  lev = LOGSTMT_DDL;
3245  break;
3246 
3248  lev = LOGSTMT_DDL;
3249  break;
3250 
3252  lev = LOGSTMT_DDL;
3253  break;
3254 
3256  lev = LOGSTMT_DDL;
3257  break;
3258 
3259  /* already-planned queries */
3260  case T_PlannedStmt:
3261  {
3262  PlannedStmt *stmt = (PlannedStmt *) parsetree;
3263 
3264  switch (stmt->commandType)
3265  {
3266  case CMD_SELECT:
3267  lev = LOGSTMT_ALL;
3268  break;
3269 
3270  case CMD_UPDATE:
3271  case CMD_INSERT:
3272  case CMD_DELETE:
3273  lev = LOGSTMT_MOD;
3274  break;
3275 
3276  case CMD_UTILITY:
3277  lev = GetCommandLogLevel(stmt->utilityStmt);
3278  break;
3279 
3280  default:
3281  elog(WARNING, "unrecognized commandType: %d",
3282  (int) stmt->commandType);
3283  lev = LOGSTMT_ALL;
3284  break;
3285  }
3286  }
3287  break;
3288 
3289  /* parsed-and-rewritten-but-not-planned queries */
3290  case T_Query:
3291  {
3292  Query *stmt = (Query *) parsetree;
3293 
3294  switch (stmt->commandType)
3295  {
3296  case CMD_SELECT:
3297  lev = LOGSTMT_ALL;
3298  break;
3299 
3300  case CMD_UPDATE:
3301  case CMD_INSERT:
3302  case CMD_DELETE:
3303  lev = LOGSTMT_MOD;
3304  break;
3305 
3306  case CMD_UTILITY:
3307  lev = GetCommandLogLevel(stmt->utilityStmt);
3308  break;
3309 
3310  default:
3311  elog(WARNING, "unrecognized commandType: %d",
3312  (int) stmt->commandType);
3313  lev = LOGSTMT_ALL;
3314  break;
3315  }
3316 
3317  }
3318  break;
3319 
3320  default:
3321  elog(WARNING, "unrecognized node type: %d",
3322  (int) nodeTag(parsetree));
3323  lev = LOGSTMT_ALL;
3324  break;
3325  }
3326 
3327  return lev;
3328 }
CachedPlanSource * plansource
Definition: prepare.h:31
LogStmtLevel
Definition: tcopprot.h:39
List * options
Definition: parsenodes.h:3001
Node * utilityStmt
Definition: parsenodes.h:111
Node * query
Definition: parsenodes.h:3000
bool defGetBoolean(DefElem *def)
Definition: define.c:111
Node * stmt
Definition: parsenodes.h:1337
Node * utilityStmt
Definition: plannodes.h:80
#define WARNING
Definition: elog.h:40
Definition: nodes.h:308
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:3168
struct RawStmt * raw_parse_tree
Definition: plancache.h:82
#define nodeTag(nodeptr)
Definition: nodes.h:513
char * name
Definition: parsenodes.h:3180
char * defname
Definition: parsenodes.h:675
#define elog
Definition: elog.h:219
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:492
static long analyze(struct nfa *nfa)
Definition: regc_nfa.c:2816
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:2835
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:559
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:226
#define Assert(condition)
Definition: c.h:670
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:2491
void closeAllVfds(void)
Definition: fd.c:2371
ObjectType objtype
Definition: parsenodes.h:2504
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1661
void PerformPortalClose(const char *name)
Definition: portalcmds.c:216
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectType renameType
Definition: parsenodes.h:2677
Oid ReindexTable(RangeVar *relation, int options)
Definition: indexcmds.c:1836
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:44
void ExecuteDoStmt(DoStmt *stmt)
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:1568
ObjectType objectType
Definition: parsenodes.h:2725
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:4714
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:290
Definition: nodes.h:508
#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:2896
Oid ReindexIndex(RangeVar *indexRelation, int options)
Definition: indexcmds.c:1742
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:234
bool RecoveryInProgress(void)
Definition: xlog.c:7825
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1165
bool EndTransactionBlock(void)
Definition: xact.c:3523
void ExecuteQuery(ExecuteStmt *stmt, IntoClause *intoClause, const char *queryString, ParamListInfo params, DestReceiver *dest, char *completionTag)
Definition: prepare.c:198
int stmt_len
Definition: plannodes.h:84
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Definition: user.c:72
ObjectType removeType
Definition: parsenodes.h:2466
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc.c:7853
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:563
#define ERROR
Definition: elog.h:43
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:272
void GrantRole(GrantRoleStmt *stmt)
Definition: user.c:1252
void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest, char *completionTag)
Definition: portalcmds.c:168
RangeVar * relation
Definition: parsenodes.h:3112
void UserAbortTransactionBlock(void)
Definition: xact.c:3647
void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
Definition: guc.c:7243
int stmt_location
Definition: plannodes.h:83
void ExecVacuum(VacuumStmt *vacstmt, bool isTopLevel)
Definition: vacuum.c:84
Node * utilityStmt
Definition: plannodes.h:80
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:401
void PrepareQuery(PrepareStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: prepare.c:55
char * conditionname
Definition: parsenodes.h:2780
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition: alter.c:307
#define CHECKPOINT_FORCE
Definition: xlog.h:180
#define ereport(elevel, rest)
Definition: elog.h:122
Oid AlterEventTrigger(AlterEventTrigStmt *stmt)
Node * arg
Definition: parsenodes.h:676
void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind, int options)
Definition: indexcmds.c:1864
bool missing_ok
Definition: parsenodes.h:2936
void BeginTransactionBlock(void)
Definition: xact.c:3413
Oid AlterRole(AlterRoleStmt *stmt)
Definition: user.c:488
bool PrepareTransactionBlock(char *gid)
Definition: xact.c:3472
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:3200
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:7028
void DefineSavepoint(char *name)
Definition: xact.c:3746
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:864
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
char * conditionname
Definition: parsenodes.h:2769
void dropdb(const char *dbname, bool missing_ok)
Definition: dbcommands.c:781
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:402
bool EventTriggerSupportsObjectType(ObjectType obtype)
Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
Definition: dbcommands.c:1390
void FinishPreparedTransaction(const char *gid, bool isCommit)
Definition: twophase.c:1323
void RequireTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3206
#define CHECKPOINT_WAIT
Definition: xlog.h:184
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:440
#define COMPLETION_TAG_BUFSIZE
Definition: dest.h:74
#define NULL
Definition: c.h:226
void DoCopy(ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
Definition: copy.c:773
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
ReindexObjectType kind
Definition: parsenodes.h:3110
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:745
void ReleaseSavepoint(List *options)
Definition: xact.c:3809
const char * name
Definition: encode.c:521
void RollbackToSavepoint(List *options)
Definition: xact.c:3922
#define nodeTag(nodeptr)
Definition: nodes.h:513
void Async_Notify(const char *channel, const char *payload)
Definition: async.c:540
bool EventTriggerSupportsGrantObjectType(GrantObjectType objtype)
GrantObjectType objtype
Definition: parsenodes.h:1755
void LockTableCommand(LockStmt *lockstmt)
Definition: lockcmds.c:36
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
Definition: dbcommands.c:100
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ReassignOwnedObjects(ReassignOwnedStmt *stmt)
Definition: user.c:1337
#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:944
const char * name
Definition: parsenodes.h:3113
char * defname
Definition: parsenodes.h:675
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:521
#define UINT64_FORMAT
Definition: c.h:313
char * dbname
Definition: parsenodes.h:2935
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:7388
void RequestCheckpoint(int flags)
Definition: checkpointer.c:967
void PreventTransactionChain(bool isTopLevel, const char *stmtType)
Definition: xact.c:3152
char * payload
Definition: parsenodes.h:2770
TransactionStmtKind kind
Definition: parsenodes.h:2814
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:384
char * conditionname
Definition: parsenodes.h:2790
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:987
Query* UtilityContainsQuery ( Node parsetree)

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

1836 {
1837  Query *qry;
1838 
1839  switch (nodeTag(parsetree))
1840  {
1841  case T_DeclareCursorStmt:
1842  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
1843  if (qry->commandType == CMD_UTILITY)
1844  return UtilityContainsQuery(qry->utilityStmt);
1845  return qry;
1846 
1847  case T_ExplainStmt:
1848  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
1849  if (qry->commandType == CMD_UTILITY)
1850  return UtilityContainsQuery(qry->utilityStmt);
1851  return qry;
1852 
1853  case T_CreateTableAsStmt:
1854  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
1855  if (qry->commandType == CMD_UTILITY)
1856  return UtilityContainsQuery(qry->utilityStmt);
1857  return qry;
1858 
1859  default:
1860  return NULL;
1861  }
1862 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:577
Node * utilityStmt
Definition: parsenodes.h:111
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:1835
CmdType commandType
Definition: parsenodes.h:103
#define NULL
Definition: c.h:226
#define nodeTag(nodeptr)
Definition: nodes.h:513
bool UtilityReturnsTuples ( Node parsetree)

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

1695 {
1696  switch (nodeTag(parsetree))
1697  {
1698  case T_FetchStmt:
1699  {
1700  FetchStmt *stmt = (FetchStmt *) parsetree;
1701  Portal portal;
1702 
1703  if (stmt->ismove)
1704  return false;
1705  portal = GetPortalByName(stmt->portalname);
1706  if (!PortalIsValid(portal))
1707  return false; /* not our business to raise error */
1708  return portal->tupDesc ? true : false;
1709  }
1710 
1711  case T_ExecuteStmt:
1712  {
1713  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1714  PreparedStatement *entry;
1715 
1716  entry = FetchPreparedStatement(stmt->name, false);
1717  if (!entry)
1718  return false; /* not our business to raise error */
1719  if (entry->plansource->resultDesc)
1720  return true;
1721  return false;
1722  }
1723 
1724  case T_ExplainStmt:
1725  return true;
1726 
1727  case T_VariableShowStmt:
1728  return true;
1729 
1730  default:
1731  return false;
1732  }
1733 }
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:2570
#define PortalIsValid(p)
Definition: portal.h:197
bool ismove
Definition: parsenodes.h:2571
TupleDesc tupDesc
Definition: portal.h:153
#define nodeTag(nodeptr)
Definition: nodes.h:513
char * name
Definition: parsenodes.h:3180
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:492
TupleDesc UtilityTupleDescriptor ( Node parsetree)

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

1745 {
1746  switch (nodeTag(parsetree))
1747  {
1748  case T_FetchStmt:
1749  {
1750  FetchStmt *stmt = (FetchStmt *) parsetree;
1751  Portal portal;
1752 
1753  if (stmt->ismove)
1754  return NULL;
1755  portal = GetPortalByName(stmt->portalname);
1756  if (!PortalIsValid(portal))
1757  return NULL; /* not our business to raise error */
1758  return CreateTupleDescCopy(portal->tupDesc);
1759  }
1760 
1761  case T_ExecuteStmt:
1762  {
1763  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1764  PreparedStatement *entry;
1765 
1766  entry = FetchPreparedStatement(stmt->name, false);
1767  if (!entry)
1768  return NULL; /* not our business to raise error */
1769  return FetchPreparedStatementResultDesc(entry);
1770  }
1771 
1772  case T_ExplainStmt:
1773  return ExplainResultDesc((ExplainStmt *) parsetree);
1774 
1775  case T_VariableShowStmt:
1776  {
1777  VariableShowStmt *n = (VariableShowStmt *) parsetree;
1778 
1779  return GetPGVariableResultDesc(n->name);
1780  }
1781 
1782  default:
1783  return NULL;
1784  }
1785 }
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:7862
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:141
Portal GetPortalByName(const char *name)
Definition: portalmem.c:129
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:294
char * portalname
Definition: parsenodes.h:2570
#define PortalIsValid(p)
Definition: portal.h:197
bool ismove
Definition: parsenodes.h:2571
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:524
TupleDesc tupDesc
Definition: portal.h:153
#define NULL
Definition: c.h:226
#define nodeTag(nodeptr)
Definition: nodes.h:513
char * name
Definition: parsenodes.h:3180
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:492

Variable Documentation

Definition at line 73 of file utility.c.

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