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

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

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

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

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

Definition at line 332 of file utility.c.

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

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

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

Definition at line 370 of file utility.c.

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

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

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

Definition at line 1844 of file utility.c.

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

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

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

Definition at line 1703 of file utility.c.

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

Referenced by ChoosePortalStrategy().

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

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

1754 {
1755  switch (nodeTag(parsetree))
1756  {
1757  case T_FetchStmt:
1758  {
1759  FetchStmt *stmt = (FetchStmt *) parsetree;
1760  Portal portal;
1761 
1762  if (stmt->ismove)
1763  return NULL;
1764  portal = GetPortalByName(stmt->portalname);
1765  if (!PortalIsValid(portal))
1766  return NULL; /* not our business to raise error */
1767  return CreateTupleDescCopy(portal->tupDesc);
1768  }
1769 
1770  case T_ExecuteStmt:
1771  {
1772  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1773  PreparedStatement *entry;
1774 
1775  entry = FetchPreparedStatement(stmt->name, false);
1776  if (!entry)
1777  return NULL; /* not our business to raise error */
1778  return FetchPreparedStatementResultDesc(entry);
1779  }
1780 
1781  case T_ExplainStmt:
1782  return ExplainResultDesc((ExplainStmt *) parsetree);
1783 
1784  case T_VariableShowStmt:
1785  {
1786  VariableShowStmt *n = (VariableShowStmt *) parsetree;
1787 
1788  return GetPGVariableResultDesc(n->name);
1789  }
1790 
1791  default:
1792  return NULL;
1793  }
1794 }
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:7879
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:141
Portal GetPortalByName(const char *name)
Definition: portalmem.c:129
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:300
char * portalname
Definition: parsenodes.h:2621
#define PortalIsValid(p)
Definition: portal.h:198
bool ismove
Definition: parsenodes.h:2622
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:526
TupleDesc tupDesc
Definition: portal.h:154
#define NULL
Definition: c.h:229
#define nodeTag(nodeptr)
Definition: nodes.h:509
char * name
Definition: parsenodes.h:3240
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().