PostgreSQL Source Code  git master
utility.h File Reference
#include "tcop/tcopprot.h"
Include dependency graph for utility.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

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

Enumerations

enum  ProcessUtilityContext { PROCESS_UTILITY_TOPLEVEL, PROCESS_UTILITY_QUERY, PROCESS_UTILITY_SUBCOMMAND }
 

Functions

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

Variables

PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook
 

Typedef Documentation

◆ ProcessUtility_hook_type

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

Definition at line 27 of file utility.h.

Enumeration Type Documentation

◆ ProcessUtilityContext

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

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

Definition at line 97 of file utility.c.

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

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

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

◆ CreateCommandTag()

const char* CreateCommandTag ( Node parsetree)

Definition at line 2046 of file utility.c.

References AlterObjectTypeCommandTag(), CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, PlannedStmt::commandType, Query::commandType, CreateCommandTag(), DISCARD_ALL, DISCARD_PLANS, DISCARD_SEQUENCES, DISCARD_TEMP, elog, GrantStmt::is_grant, GrantRoleStmt::is_grant, FetchStmt::ismove, TransactionStmt::kind, LCS_FORKEYSHARE, LCS_FORNOKEYUPDATE, LCS_FORSHARE, LCS_FORUPDATE, linitial, DeallocateStmt::name, NIL, nodeTag, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_CONVERSION, OBJECT_DOMAIN, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_TABLE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ClosePortalStmt::portalname, PlannedStmt::rowMarks, Query::rowMarks, T_AlterCollationStmt, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterSubscriptionStmt, T_AlterSystemStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DeleteStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PrepareStmt, T_Query, T_RawStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_SelectStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_UpdateStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, PlannedStmt::utilityStmt, Query::utilityStmt, VACOPT_VACUUM, VAR_RESET, VAR_RESET_ALL, VAR_SET_CURRENT, VAR_SET_DEFAULT, VAR_SET_MULTI, VAR_SET_VALUE, and WARNING.

Referenced by _SPI_execute_plan(), _SPI_prepare_oneshot_plan(), _SPI_prepare_plan(), check_xact_readonly(), CreateCommandTag(), EventTriggerCommonSetup(), exec_parse_message(), exec_simple_query(), ExecCheckXactReadOnly(), get_command_tag(), init_execution_state(), pg_event_trigger_ddl_commands(), PrepareQuery(), and SPI_cursor_open_internal().

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

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 2906 of file utility.c.

References analyze(), CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, PlannedStmt::commandType, Query::commandType, defGetBoolean(), DefElem::defname, elog, FetchPreparedStatement(), GetCommandLogLevel(), lfirst, LOGSTMT_ALL, LOGSTMT_DDL, LOGSTMT_MOD, ExecuteStmt::name, nodeTag, ExplainStmt::options, PreparedStatement::plansource, ExplainStmt::query, PrepareStmt::query, CachedPlanSource::raw_parse_tree, RawStmt::stmt, T_AlterCollationStmt, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectDependsStmt, T_AlterObjectSchemaStmt, T_AlterOperatorStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterPolicyStmt, T_AlterPublicationStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterSubscriptionStmt, T_AlterSystemStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DeleteStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PrepareStmt, T_Query, T_RawStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_SelectStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_UpdateStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, PlannedStmt::utilityStmt, Query::utilityStmt, and WARNING.

Referenced by check_log_statement(), and GetCommandLogLevel().

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

◆ ProcessUtility()

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

Definition at line 335 of file utility.c.

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

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

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

◆ standard_ProcessUtility()

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

Definition at line 374 of file utility.c.

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterSystemSetConfigFile(), AlterTableSpaceOptions(), DefElem::arg, Assert, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), BeginTransactionBlock(), castNode, check_xact_readonly(), CHECKPOINT_FORCE, CHECKPOINT_IMMEDIATE, CHECKPOINT_WAIT, CheckRestrictedOperation(), closeAllVfds(), cluster(), CommentObject(), COMPLETION_TAG_BUFSIZE, NotifyStmt::conditionname, ListenStmt::conditionname, UnlistenStmt::conditionname, createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DropdbStmt::dbname, DeallocateQuery(), DefineSavepoint(), DefElem::defname, DiscardCommand(), DoCopy(), dropdb(), DropRole(), DropTableSpace(), elog, EndTransactionBlock(), ereport, errcode(), errmsg(), ERROR, EventTriggerSupportsGrantObjectType(), EventTriggerSupportsObjectType(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteCallStmt(), 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, 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_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreatedbStmt, T_CreateEventTrigStmt, T_CreateRoleStmt, T_CreateTableSpaceStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropRoleStmt, T_DropStmt, T_DropTableSpaceStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PrepareStmt, T_ReassignOwnedStmt, T_ReindexStmt, T_RenameStmt, T_SecLabelStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, UINT64_FORMAT, UserAbortTransactionBlock(), PlannedStmt::utilityStmt, VACOPT_VACUUM, and WarnNoTransactionChain().

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

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

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

Definition at line 1860 of file utility.c.

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

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

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

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

Definition at line 1719 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, true, and PortalData::tupDesc.

Referenced by ChoosePortalStrategy(), and UtilityTupleDescriptor().

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

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

Definition at line 1769 of file utility.c.

References CMD_DELETE, CMD_INSERT, CMD_NOTHING, CMD_SELECT, CMD_UNKNOWN, CMD_UPDATE, CMD_UTILITY, Query::commandType, CreateTupleDescCopy(), ExplainResultDesc(), FetchPreparedStatement(), FetchPreparedStatementResultDesc(), GetPGVariableResultDesc(), GetPortalByName(), FetchStmt::ismove, VariableShowStmt::name, ExecuteStmt::name, nodeTag, PortalIsValid, FetchStmt::portalname, Query::returningList, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_VariableShowStmt, PortalData::tupDesc, UtilityReturnsTuples(), and Query::utilityStmt.

Referenced by PlanCacheComputeResultDesc(), and PortalStart().

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

Variable Documentation

◆ ProcessUtility_hook

Definition at line 73 of file utility.c.

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