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_QUERY_NONATOMIC, 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 29 of file utility.h.

Enumeration Type Documentation

◆ ProcessUtilityContext

Enumerator
PROCESS_UTILITY_TOPLEVEL 
PROCESS_UTILITY_QUERY 
PROCESS_UTILITY_QUERY_NONATOMIC 
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_QUERY_NONATOMIC, /* a complete query, nonatomic
24  * execution context */
25  PROCESS_UTILITY_SUBCOMMAND /* a portion of a query */
ProcessUtilityContext
Definition: utility.h:19

Function Documentation

◆ CommandIsReadOnly()

bool CommandIsReadOnly ( PlannedStmt pstmt)

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

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

◆ CreateCommandTag()

const char* CreateCommandTag ( Node parsetree)

Definition at line 2104 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, relkind, 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_AlterStatsStmt, 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, 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().

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

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 2968 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_AlterStatsStmt, 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().

2969 {
2970  LogStmtLevel lev;
2971 
2972  switch (nodeTag(parsetree))
2973  {
2974  /* recurse if we're given a RawStmt */
2975  case T_RawStmt:
2976  lev = GetCommandLogLevel(((RawStmt *) parsetree)->stmt);
2977  break;
2978 
2979  /* raw plannable queries */
2980  case T_InsertStmt:
2981  case T_DeleteStmt:
2982  case T_UpdateStmt:
2983  lev = LOGSTMT_MOD;
2984  break;
2985 
2986  case T_SelectStmt:
2987  if (((SelectStmt *) parsetree)->intoClause)
2988  lev = LOGSTMT_DDL; /* SELECT INTO */
2989  else
2990  lev = LOGSTMT_ALL;
2991  break;
2992 
2993  /* utility statements --- same whether raw or cooked */
2994  case T_TransactionStmt:
2995  lev = LOGSTMT_ALL;
2996  break;
2997 
2998  case T_DeclareCursorStmt:
2999  lev = LOGSTMT_ALL;
3000  break;
3001 
3002  case T_ClosePortalStmt:
3003  lev = LOGSTMT_ALL;
3004  break;
3005 
3006  case T_FetchStmt:
3007  lev = LOGSTMT_ALL;
3008  break;
3009 
3010  case T_CreateSchemaStmt:
3011  lev = LOGSTMT_DDL;
3012  break;
3013 
3014  case T_CreateStmt:
3016  lev = LOGSTMT_DDL;
3017  break;
3018 
3020  case T_DropTableSpaceStmt:
3022  lev = LOGSTMT_DDL;
3023  break;
3024 
3025  case T_CreateExtensionStmt:
3026  case T_AlterExtensionStmt:
3028  lev = LOGSTMT_DDL;
3029  break;
3030 
3031  case T_CreateFdwStmt:
3032  case T_AlterFdwStmt:
3037  case T_DropUserMappingStmt:
3039  lev = LOGSTMT_DDL;
3040  break;
3041 
3042  case T_DropStmt:
3043  lev = LOGSTMT_DDL;
3044  break;
3045 
3046  case T_TruncateStmt:
3047  lev = LOGSTMT_MOD;
3048  break;
3049 
3050  case T_CommentStmt:
3051  lev = LOGSTMT_DDL;
3052  break;
3053 
3054  case T_SecLabelStmt:
3055  lev = LOGSTMT_DDL;
3056  break;
3057 
3058  case T_CopyStmt:
3059  if (((CopyStmt *) parsetree)->is_from)
3060  lev = LOGSTMT_MOD;
3061  else
3062  lev = LOGSTMT_ALL;
3063  break;
3064 
3065  case T_PrepareStmt:
3066  {
3067  PrepareStmt *stmt = (PrepareStmt *) parsetree;
3068 
3069  /* Look through a PREPARE to the contained stmt */
3070  lev = GetCommandLogLevel(stmt->query);
3071  }
3072  break;
3073 
3074  case T_ExecuteStmt:
3075  {
3076  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
3077  PreparedStatement *ps;
3078 
3079  /* Look through an EXECUTE to the referenced stmt */
3080  ps = FetchPreparedStatement(stmt->name, false);
3081  if (ps && ps->plansource->raw_parse_tree)
3083  else
3084  lev = LOGSTMT_ALL;
3085  }
3086  break;
3087 
3088  case T_DeallocateStmt:
3089  lev = LOGSTMT_ALL;
3090  break;
3091 
3092  case T_RenameStmt:
3093  lev = LOGSTMT_DDL;
3094  break;
3095 
3097  lev = LOGSTMT_DDL;
3098  break;
3099 
3101  lev = LOGSTMT_DDL;
3102  break;
3103 
3104  case T_AlterOwnerStmt:
3105  lev = LOGSTMT_DDL;
3106  break;
3107 
3108  case T_AlterOperatorStmt:
3109  lev = LOGSTMT_DDL;
3110  break;
3111 
3113  case T_AlterTableStmt:
3114  lev = LOGSTMT_DDL;
3115  break;
3116 
3117  case T_AlterDomainStmt:
3118  lev = LOGSTMT_DDL;
3119  break;
3120 
3121  case T_GrantStmt:
3122  lev = LOGSTMT_DDL;
3123  break;
3124 
3125  case T_GrantRoleStmt:
3126  lev = LOGSTMT_DDL;
3127  break;
3128 
3130  lev = LOGSTMT_DDL;
3131  break;
3132 
3133  case T_DefineStmt:
3134  lev = LOGSTMT_DDL;
3135  break;
3136 
3137  case T_CompositeTypeStmt:
3138  lev = LOGSTMT_DDL;
3139  break;
3140 
3141  case T_CreateEnumStmt:
3142  lev = LOGSTMT_DDL;
3143  break;
3144 
3145  case T_CreateRangeStmt:
3146  lev = LOGSTMT_DDL;
3147  break;
3148 
3149  case T_AlterEnumStmt:
3150  lev = LOGSTMT_DDL;
3151  break;
3152 
3153  case T_ViewStmt:
3154  lev = LOGSTMT_DDL;
3155  break;
3156 
3157  case T_CreateFunctionStmt:
3158  lev = LOGSTMT_DDL;
3159  break;
3160 
3161  case T_AlterFunctionStmt:
3162  lev = LOGSTMT_DDL;
3163  break;
3164 
3165  case T_IndexStmt:
3166  lev = LOGSTMT_DDL;
3167  break;
3168 
3169  case T_RuleStmt:
3170  lev = LOGSTMT_DDL;
3171  break;
3172 
3173  case T_CreateSeqStmt:
3174  lev = LOGSTMT_DDL;
3175  break;
3176 
3177  case T_AlterSeqStmt:
3178  lev = LOGSTMT_DDL;
3179  break;
3180 
3181  case T_DoStmt:
3182  lev = LOGSTMT_ALL;
3183  break;
3184 
3185  case T_CreatedbStmt:
3186  lev = LOGSTMT_DDL;
3187  break;
3188 
3189  case T_AlterDatabaseStmt:
3190  lev = LOGSTMT_DDL;
3191  break;
3192 
3194  lev = LOGSTMT_DDL;
3195  break;
3196 
3197  case T_DropdbStmt:
3198  lev = LOGSTMT_DDL;
3199  break;
3200 
3201  case T_NotifyStmt:
3202  lev = LOGSTMT_ALL;
3203  break;
3204 
3205  case T_ListenStmt:
3206  lev = LOGSTMT_ALL;
3207  break;
3208 
3209  case T_UnlistenStmt:
3210  lev = LOGSTMT_ALL;
3211  break;
3212 
3213  case T_LoadStmt:
3214  lev = LOGSTMT_ALL;
3215  break;
3216 
3217  case T_CallStmt:
3218  lev = LOGSTMT_ALL;
3219  break;
3220 
3221  case T_ClusterStmt:
3222  lev = LOGSTMT_DDL;
3223  break;
3224 
3225  case T_VacuumStmt:
3226  lev = LOGSTMT_ALL;
3227  break;
3228 
3229  case T_ExplainStmt:
3230  {
3231  ExplainStmt *stmt = (ExplainStmt *) parsetree;
3232  bool analyze = false;
3233  ListCell *lc;
3234 
3235  /* Look through an EXPLAIN ANALYZE to the contained stmt */
3236  foreach(lc, stmt->options)
3237  {
3238  DefElem *opt = (DefElem *) lfirst(lc);
3239 
3240  if (strcmp(opt->defname, "analyze") == 0)
3241  analyze = defGetBoolean(opt);
3242  /* don't "break", as explain.c will use the last value */
3243  }
3244  if (analyze)
3245  return GetCommandLogLevel(stmt->query);
3246 
3247  /* Plain EXPLAIN isn't so interesting */
3248  lev = LOGSTMT_ALL;
3249  }
3250  break;
3251 
3252  case T_CreateTableAsStmt:
3253  lev = LOGSTMT_DDL;
3254  break;
3255 
3256  case T_RefreshMatViewStmt:
3257  lev = LOGSTMT_DDL;
3258  break;
3259 
3260  case T_AlterSystemStmt:
3261  lev = LOGSTMT_DDL;
3262  break;
3263 
3264  case T_VariableSetStmt:
3265  lev = LOGSTMT_ALL;
3266  break;
3267 
3268  case T_VariableShowStmt:
3269  lev = LOGSTMT_ALL;
3270  break;
3271 
3272  case T_DiscardStmt:
3273  lev = LOGSTMT_ALL;
3274  break;
3275 
3276  case T_CreateTrigStmt:
3277  lev = LOGSTMT_DDL;
3278  break;
3279 
3280  case T_CreateEventTrigStmt:
3281  lev = LOGSTMT_DDL;
3282  break;
3283 
3284  case T_AlterEventTrigStmt:
3285  lev = LOGSTMT_DDL;
3286  break;
3287 
3288  case T_CreatePLangStmt:
3289  lev = LOGSTMT_DDL;
3290  break;
3291 
3292  case T_CreateDomainStmt:
3293  lev = LOGSTMT_DDL;
3294  break;
3295 
3296  case T_CreateRoleStmt:
3297  lev = LOGSTMT_DDL;
3298  break;
3299 
3300  case T_AlterRoleStmt:
3301  lev = LOGSTMT_DDL;
3302  break;
3303 
3304  case T_AlterRoleSetStmt:
3305  lev = LOGSTMT_DDL;
3306  break;
3307 
3308  case T_DropRoleStmt:
3309  lev = LOGSTMT_DDL;
3310  break;
3311 
3312  case T_DropOwnedStmt:
3313  lev = LOGSTMT_DDL;
3314  break;
3315 
3316  case T_ReassignOwnedStmt:
3317  lev = LOGSTMT_DDL;
3318  break;
3319 
3320  case T_LockStmt:
3321  lev = LOGSTMT_ALL;
3322  break;
3323 
3324  case T_ConstraintsSetStmt:
3325  lev = LOGSTMT_ALL;
3326  break;
3327 
3328  case T_CheckPointStmt:
3329  lev = LOGSTMT_ALL;
3330  break;
3331 
3332  case T_ReindexStmt:
3333  lev = LOGSTMT_ALL; /* should this be DDL? */
3334  break;
3335 
3337  lev = LOGSTMT_DDL;
3338  break;
3339 
3340  case T_CreateCastStmt:
3341  lev = LOGSTMT_DDL;
3342  break;
3343 
3344  case T_CreateOpClassStmt:
3345  lev = LOGSTMT_DDL;
3346  break;
3347 
3348  case T_CreateOpFamilyStmt:
3349  lev = LOGSTMT_DDL;
3350  break;
3351 
3352  case T_CreateTransformStmt:
3353  lev = LOGSTMT_DDL;
3354  break;
3355 
3356  case T_AlterOpFamilyStmt:
3357  lev = LOGSTMT_DDL;
3358  break;
3359 
3360  case T_CreatePolicyStmt:
3361  lev = LOGSTMT_DDL;
3362  break;
3363 
3364  case T_AlterPolicyStmt:
3365  lev = LOGSTMT_DDL;
3366  break;
3367 
3369  lev = LOGSTMT_DDL;
3370  break;
3371 
3373  lev = LOGSTMT_DDL;
3374  break;
3375 
3376  case T_CreateAmStmt:
3377  lev = LOGSTMT_DDL;
3378  break;
3379 
3381  lev = LOGSTMT_DDL;
3382  break;
3383 
3385  lev = LOGSTMT_DDL;
3386  break;
3387 
3389  lev = LOGSTMT_DDL;
3390  break;
3391 
3393  lev = LOGSTMT_DDL;
3394  break;
3395 
3397  lev = LOGSTMT_DDL;
3398  break;
3399 
3400  case T_CreateStatsStmt:
3401  lev = LOGSTMT_DDL;
3402  break;
3403 
3404  case T_AlterStatsStmt:
3405  lev = LOGSTMT_DDL;
3406  break;
3407 
3408  case T_AlterCollationStmt:
3409  lev = LOGSTMT_DDL;
3410  break;
3411 
3412  /* already-planned queries */
3413  case T_PlannedStmt:
3414  {
3415  PlannedStmt *stmt = (PlannedStmt *) parsetree;
3416 
3417  switch (stmt->commandType)
3418  {
3419  case CMD_SELECT:
3420  lev = LOGSTMT_ALL;
3421  break;
3422 
3423  case CMD_UPDATE:
3424  case CMD_INSERT:
3425  case CMD_DELETE:
3426  lev = LOGSTMT_MOD;
3427  break;
3428 
3429  case CMD_UTILITY:
3430  lev = GetCommandLogLevel(stmt->utilityStmt);
3431  break;
3432 
3433  default:
3434  elog(WARNING, "unrecognized commandType: %d",
3435  (int) stmt->commandType);
3436  lev = LOGSTMT_ALL;
3437  break;
3438  }
3439  }
3440  break;
3441 
3442  /* parsed-and-rewritten-but-not-planned queries */
3443  case T_Query:
3444  {
3445  Query *stmt = (Query *) parsetree;
3446 
3447  switch (stmt->commandType)
3448  {
3449  case CMD_SELECT:
3450  lev = LOGSTMT_ALL;
3451  break;
3452 
3453  case CMD_UPDATE:
3454  case CMD_INSERT:
3455  case CMD_DELETE:
3456  lev = LOGSTMT_MOD;
3457  break;
3458 
3459  case CMD_UTILITY:
3460  lev = GetCommandLogLevel(stmt->utilityStmt);
3461  break;
3462 
3463  default:
3464  elog(WARNING, "unrecognized commandType: %d",
3465  (int) stmt->commandType);
3466  lev = LOGSTMT_ALL;
3467  break;
3468  }
3469 
3470  }
3471  break;
3472 
3473  default:
3474  elog(WARNING, "unrecognized node type: %d",
3475  (int) nodeTag(parsetree));
3476  lev = LOGSTMT_ALL;
3477  break;
3478  }
3479 
3480  return lev;
3481 }
CachedPlanSource * plansource
Definition: prepare.h:31
LogStmtLevel
Definition: tcopprot.h:35
List * options
Definition: parsenodes.h:3220
Node * utilityStmt
Definition: parsenodes.h:120
Node * query
Definition: parsenodes.h:3219
bool defGetBoolean(DefElem *def)
Definition: define.c:111
Node * stmt
Definition: parsenodes.h:1485
Node * utilityStmt
Definition: plannodes.h:90
#define WARNING
Definition: elog.h:40
Definition: nodes.h:310
CmdType commandType
Definition: plannodes.h:46
CmdType commandType
Definition: parsenodes.h:112
#define lfirst(lc)
Definition: pg_list.h:190
Node * query
Definition: parsenodes.h:3389
struct RawStmt * raw_parse_tree
Definition: plancache.h:96
#define nodeTag(nodeptr)
Definition: nodes.h:530
#define elog(elevel,...)
Definition: elog.h:226
char * name
Definition: parsenodes.h:3401
char * defname
Definition: parsenodes.h:730
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:485
static long analyze(struct nfa *nfa)
Definition: regc_nfa.c:2816
LogStmtLevel GetCommandLogLevel(Node *parsetree)
Definition: utility.c:2968

◆ ProcessUtility()

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

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

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

◆ standard_ProcessUtility()

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

Definition at line 377 of file utility.c.

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterSystemSetConfigFile(), AlterTableSpaceOptions(), DefElem::arg, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), BeginTransactionBlock(), castNode, TransactionStmt::chain, check_stack_depth(), check_xact_readonly(), CHECKPOINT_FORCE, CHECKPOINT_IMMEDIATE, CHECKPOINT_WAIT, CheckRestrictedOperation(), closeAllVfds(), cluster(), CommandCounterIncrement(), CommentObject(), COMPLETION_TAG_BUFSIZE, ReindexStmt::concurrent, 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, EventTriggerSupportsObjectType(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteCallStmt(), ExecuteDoStmt(), ExecuteGrantStmt(), ExecuteQuery(), ExecuteTruncate(), ExecVacuum(), ExplainQuery(), LoadStmt::filename, FinishPreparedTransaction(), free_parsestate(), GetPGVariable(), TransactionStmt::gid, GrantRole(), VacuumStmt::is_vacuumcmd, IsTransactionBlock(), TransactionStmt::kind, ReindexStmt::kind, lfirst, list_make1, load_file(), LockTableCommand(), make_parsestate(), DropdbStmt::missing_ok, VariableShowStmt::name, ReindexStmt::name, nodeTag, AlterObjectDependsStmt::objectType, AlterObjectSchemaStmt::objectType, AlterOwnerStmt::objectType, GrantStmt::objtype, CommentStmt::objtype, SecLabelStmt::objtype, TransactionStmt::options, ReindexStmt::options, ParseState::p_sourcetext, NotifyStmt::payload, PerformCursorOpen(), PerformPortalClose(), PerformPortalFetch(), ClosePortalStmt::portalname, PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventInTransactionBlock(), PROCESS_UTILITY_QUERY_NONATOMIC, 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(), RequireTransactionBlock(), RollbackToSavepoint(), TransactionStmt::savepoint_name, SetPGVariable(), snprintf, PlannedStmt::stmt_len, PlannedStmt::stmt_location, 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, and WarnNoTransactionBlock().

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

384 {
385  Node *parsetree = pstmt->utilityStmt;
386  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
387  bool isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
388  ParseState *pstate;
389 
390  /* This can recurse, so check for excessive recursion */
392 
393  check_xact_readonly(parsetree);
394 
395  if (completionTag)
396  completionTag[0] = '\0';
397 
398  pstate = make_parsestate(NULL);
399  pstate->p_sourcetext = queryString;
400 
401  switch (nodeTag(parsetree))
402  {
403  /*
404  * ******************** transactions ********************
405  */
406  case T_TransactionStmt:
407  {
408  TransactionStmt *stmt = (TransactionStmt *) parsetree;
409 
410  switch (stmt->kind)
411  {
412  /*
413  * START TRANSACTION, as defined by SQL99: Identical
414  * to BEGIN. Same code for both.
415  */
416  case TRANS_STMT_BEGIN:
417  case TRANS_STMT_START:
418  {
419  ListCell *lc;
420 
422  foreach(lc, stmt->options)
423  {
424  DefElem *item = (DefElem *) lfirst(lc);
425 
426  if (strcmp(item->defname, "transaction_isolation") == 0)
427  SetPGVariable("transaction_isolation",
428  list_make1(item->arg),
429  true);
430  else if (strcmp(item->defname, "transaction_read_only") == 0)
431  SetPGVariable("transaction_read_only",
432  list_make1(item->arg),
433  true);
434  else if (strcmp(item->defname, "transaction_deferrable") == 0)
435  SetPGVariable("transaction_deferrable",
436  list_make1(item->arg),
437  true);
438  }
439  }
440  break;
441 
442  case TRANS_STMT_COMMIT:
443  if (!EndTransactionBlock(stmt->chain))
444  {
445  /* report unsuccessful commit in completionTag */
446  if (completionTag)
447  strcpy(completionTag, "ROLLBACK");
448  }
449  break;
450 
451  case TRANS_STMT_PREPARE:
452  PreventCommandDuringRecovery("PREPARE TRANSACTION");
453  if (!PrepareTransactionBlock(stmt->gid))
454  {
455  /* report unsuccessful commit in completionTag */
456  if (completionTag)
457  strcpy(completionTag, "ROLLBACK");
458  }
459  break;
460 
462  PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
463  PreventCommandDuringRecovery("COMMIT PREPARED");
464  FinishPreparedTransaction(stmt->gid, true);
465  break;
466 
468  PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
469  PreventCommandDuringRecovery("ROLLBACK PREPARED");
470  FinishPreparedTransaction(stmt->gid, false);
471  break;
472 
473  case TRANS_STMT_ROLLBACK:
475  break;
476 
478  RequireTransactionBlock(isTopLevel, "SAVEPOINT");
480  break;
481 
482  case TRANS_STMT_RELEASE:
483  RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
485  break;
486 
488  RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
490 
491  /*
492  * CommitTransactionCommand is in charge of
493  * re-defining the savepoint again
494  */
495  break;
496  }
497  }
498  break;
499 
500  /*
501  * Portal (cursor) manipulation
502  */
503  case T_DeclareCursorStmt:
504  PerformCursorOpen((DeclareCursorStmt *) parsetree, params,
505  queryString, isTopLevel);
506  break;
507 
508  case T_ClosePortalStmt:
509  {
510  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
511 
512  CheckRestrictedOperation("CLOSE");
514  }
515  break;
516 
517  case T_FetchStmt:
518  PerformPortalFetch((FetchStmt *) parsetree, dest,
519  completionTag);
520  break;
521 
522  case T_DoStmt:
523  ExecuteDoStmt((DoStmt *) parsetree, isAtomicContext);
524  break;
525 
527  /* no event triggers for global objects */
528  PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
529  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
530  break;
531 
533  /* no event triggers for global objects */
534  PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
535  DropTableSpace((DropTableSpaceStmt *) parsetree);
536  break;
537 
539  /* no event triggers for global objects */
541  break;
542 
543  case T_TruncateStmt:
544  ExecuteTruncate((TruncateStmt *) parsetree);
545  break;
546 
547  case T_CopyStmt:
548  {
549  uint64 processed;
550 
551  DoCopy(pstate, (CopyStmt *) parsetree,
552  pstmt->stmt_location, pstmt->stmt_len,
553  &processed);
554  if (completionTag)
555  snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
556  "COPY " UINT64_FORMAT, processed);
557  }
558  break;
559 
560  case T_PrepareStmt:
561  CheckRestrictedOperation("PREPARE");
562  PrepareQuery((PrepareStmt *) parsetree, queryString,
563  pstmt->stmt_location, pstmt->stmt_len);
564  break;
565 
566  case T_ExecuteStmt:
567  ExecuteQuery((ExecuteStmt *) parsetree, NULL,
568  queryString, params,
569  dest, completionTag);
570  break;
571 
572  case T_DeallocateStmt:
573  CheckRestrictedOperation("DEALLOCATE");
574  DeallocateQuery((DeallocateStmt *) parsetree);
575  break;
576 
577  case T_GrantRoleStmt:
578  /* no event triggers for global objects */
579  GrantRole((GrantRoleStmt *) parsetree);
580  break;
581 
582  case T_CreatedbStmt:
583  /* no event triggers for global objects */
584  PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
585  createdb(pstate, (CreatedbStmt *) parsetree);
586  break;
587 
588  case T_AlterDatabaseStmt:
589  /* no event triggers for global objects */
590  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
591  break;
592 
594  /* no event triggers for global objects */
595  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
596  break;
597 
598  case T_DropdbStmt:
599  {
600  DropdbStmt *stmt = (DropdbStmt *) parsetree;
601 
602  /* no event triggers for global objects */
603  PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
604  dropdb(stmt->dbname, stmt->missing_ok);
605  }
606  break;
607 
608  /* Query-level asynchronous notification */
609  case T_NotifyStmt:
610  {
611  NotifyStmt *stmt = (NotifyStmt *) parsetree;
612 
614  Async_Notify(stmt->conditionname, stmt->payload);
615  }
616  break;
617 
618  case T_ListenStmt:
619  {
620  ListenStmt *stmt = (ListenStmt *) parsetree;
621 
623  CheckRestrictedOperation("LISTEN");
625  }
626  break;
627 
628  case T_UnlistenStmt:
629  {
630  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
631 
632  /* we allow UNLISTEN during recovery, as it's a noop */
633  CheckRestrictedOperation("UNLISTEN");
634  if (stmt->conditionname)
636  else
638  }
639  break;
640 
641  case T_LoadStmt:
642  {
643  LoadStmt *stmt = (LoadStmt *) parsetree;
644 
645  closeAllVfds(); /* probably not necessary... */
646  /* Allowed names are restricted if you're not superuser */
647  load_file(stmt->filename, !superuser());
648  }
649  break;
650 
651  case T_CallStmt:
652  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
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(pstate, stmt, isTopLevel);
671  }
672  break;
673 
674  case T_ExplainStmt:
675  ExplainQuery(pstate, (ExplainStmt *) parsetree, queryString, params,
676  queryEnv, dest);
677  break;
678 
679  case T_AlterSystemStmt:
680  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
682  break;
683 
684  case T_VariableSetStmt:
685  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
686  break;
687 
688  case T_VariableShowStmt:
689  {
690  VariableShowStmt *n = (VariableShowStmt *) parsetree;
691 
692  GetPGVariable(n->name, dest);
693  }
694  break;
695 
696  case T_DiscardStmt:
697  /* should we allow DISCARD PLANS? */
698  CheckRestrictedOperation("DISCARD");
699  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
700  break;
701 
703  /* no event triggers on event triggers */
705  break;
706 
708  /* no event triggers on event triggers */
709  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
710  break;
711 
712  /*
713  * ******************************** ROLE statements ****
714  */
715  case T_CreateRoleStmt:
716  /* no event triggers for global objects */
717  CreateRole(pstate, (CreateRoleStmt *) parsetree);
718  break;
719 
720  case T_AlterRoleStmt:
721  /* no event triggers for global objects */
722  AlterRole((AlterRoleStmt *) parsetree);
723  break;
724 
725  case T_AlterRoleSetStmt:
726  /* no event triggers for global objects */
727  AlterRoleSet((AlterRoleSetStmt *) parsetree);
728  break;
729 
730  case T_DropRoleStmt:
731  /* no event triggers for global objects */
732  DropRole((DropRoleStmt *) parsetree);
733  break;
734 
735  case T_ReassignOwnedStmt:
736  /* no event triggers for global objects */
738  break;
739 
740  case T_LockStmt:
741 
742  /*
743  * Since the lock would just get dropped immediately, LOCK TABLE
744  * outside a transaction block is presumed to be user error.
745  */
746  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
747  /* forbidden in parallel mode due to CommandIsReadOnly */
748  LockTableCommand((LockStmt *) parsetree);
749  break;
750 
752  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
754  break;
755 
756  case T_CheckPointStmt:
757  if (!superuser())
758  ereport(ERROR,
759  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
760  errmsg("must be superuser to do CHECKPOINT")));
761 
762  /*
763  * You might think we should have a PreventCommandDuringRecovery()
764  * here, but we interpret a CHECKPOINT command during recovery as
765  * a request for a restartpoint instead. We allow this since it
766  * can be a useful way of reducing switchover time when using
767  * various forms of replication.
768  */
771  break;
772 
773  case T_ReindexStmt:
774  {
775  ReindexStmt *stmt = (ReindexStmt *) parsetree;
776 
777  if (stmt->concurrent)
778  PreventInTransactionBlock(isTopLevel,
779  "REINDEX CONCURRENTLY");
780 
781  /* we choose to allow this during "read only" transactions */
782  PreventCommandDuringRecovery("REINDEX");
783  /* forbidden in parallel mode due to CommandIsReadOnly */
784  switch (stmt->kind)
785  {
787  ReindexIndex(stmt->relation, stmt->options, stmt->concurrent);
788  break;
790  ReindexTable(stmt->relation, stmt->options, stmt->concurrent);
791  break;
795 
796  /*
797  * This cannot run inside a user transaction block; if
798  * we were inside a transaction, then its commit- and
799  * start-transaction-command calls would not have the
800  * intended effect!
801  */
802  PreventInTransactionBlock(isTopLevel,
803  (stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
804  (stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
805  "REINDEX DATABASE");
806  ReindexMultipleTables(stmt->name, stmt->kind, stmt->options, stmt->concurrent);
807  break;
808  default:
809  elog(ERROR, "unrecognized object type: %d",
810  (int) stmt->kind);
811  break;
812  }
813  }
814  break;
815 
816  /*
817  * The following statements are supported by Event Triggers only
818  * in some cases, so we "fast path" them in the other cases.
819  */
820 
821  case T_GrantStmt:
822  {
823  GrantStmt *stmt = (GrantStmt *) parsetree;
824 
826  ProcessUtilitySlow(pstate, pstmt, queryString,
827  context, params, queryEnv,
828  dest, completionTag);
829  else
830  ExecuteGrantStmt(stmt);
831  }
832  break;
833 
834  case T_DropStmt:
835  {
836  DropStmt *stmt = (DropStmt *) parsetree;
837 
839  ProcessUtilitySlow(pstate, pstmt, queryString,
840  context, params, queryEnv,
841  dest, completionTag);
842  else
843  ExecDropStmt(stmt, isTopLevel);
844  }
845  break;
846 
847  case T_RenameStmt:
848  {
849  RenameStmt *stmt = (RenameStmt *) parsetree;
850 
852  ProcessUtilitySlow(pstate, pstmt, queryString,
853  context, params, queryEnv,
854  dest, completionTag);
855  else
856  ExecRenameStmt(stmt);
857  }
858  break;
859 
861  {
862  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
863 
865  ProcessUtilitySlow(pstate, pstmt, queryString,
866  context, params, queryEnv,
867  dest, completionTag);
868  else
869  ExecAlterObjectDependsStmt(stmt, NULL);
870  }
871  break;
872 
874  {
875  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
876 
878  ProcessUtilitySlow(pstate, pstmt, queryString,
879  context, params, queryEnv,
880  dest, completionTag);
881  else
882  ExecAlterObjectSchemaStmt(stmt, NULL);
883  }
884  break;
885 
886  case T_AlterOwnerStmt:
887  {
888  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
889 
891  ProcessUtilitySlow(pstate, pstmt, queryString,
892  context, params, queryEnv,
893  dest, completionTag);
894  else
895  ExecAlterOwnerStmt(stmt);
896  }
897  break;
898 
899  case T_CommentStmt:
900  {
901  CommentStmt *stmt = (CommentStmt *) parsetree;
902 
904  ProcessUtilitySlow(pstate, pstmt, queryString,
905  context, params, queryEnv,
906  dest, completionTag);
907  else
908  CommentObject(stmt);
909  break;
910  }
911 
912  case T_SecLabelStmt:
913  {
914  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
915 
917  ProcessUtilitySlow(pstate, pstmt, queryString,
918  context, params, queryEnv,
919  dest, completionTag);
920  else
921  ExecSecLabelStmt(stmt);
922  break;
923  }
924 
925  default:
926  /* All other statement types have event trigger support */
927  ProcessUtilitySlow(pstate, pstmt, queryString,
928  context, params, queryEnv,
929  dest, completionTag);
930  break;
931  }
932 
933  free_parsestate(pstate);
934 
935  /*
936  * Make effects of commands visible, for instance so that
937  * PreCommit_on_commit_actions() can see them (see for example bug
938  * #15631).
939  */
941 }
ObjectType objtype
Definition: parsenodes.h:2657
void closeAllVfds(void)
Definition: fd.c:2643
ObjectType objtype
Definition: parsenodes.h:2669
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1735
void PerformPortalClose(const char *name)
Definition: portalcmds.c:216
bool EndTransactionBlock(bool chain)
Definition: xact.c:3707
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
Oid ReindexTable(RangeVar *relation, int options, bool concurrent)
Definition: indexcmds.c:2434
ObjectType renameType
Definition: parsenodes.h:2891
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:44
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3388
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:1618
ObjectType objectType
Definition: parsenodes.h:2936
void DefineSavepoint(const char *name)
Definition: xact.c:4036
bool is_vacuumcmd
Definition: parsenodes.h:3190
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:5325
void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest)
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:294
Definition: nodes.h:525
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3655
int errcode(int sqlerrcode)
Definition: elog.c:570
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:3107
void Async_Listen(const char *channel)
Definition: async.c:762
Oid CreateTableSpace(CreateTableSpaceStmt *stmt)
Definition: tablespace.c:234
void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind, int options, bool concurrent)
Definition: indexcmds.c:2478
void ReindexIndex(RangeVar *indexRelation, int options, bool concurrent)
Definition: indexcmds.c:2317
bool RecoveryInProgress(void)
Definition: xlog.c:7913
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1498
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:94
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Definition: user.c:71
ObjectType removeType
Definition: parsenodes.h:2632
void RollbackToSavepoint(const char *name)
Definition: xact.c:4230
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc.c:8738
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:44
#define list_make1(x1)
Definition: pg_list.h:227
bool IsTransactionBlock(void)
Definition: xact.c:4633
void DeallocateQuery(DeallocateStmt *stmt)
Definition: prepare.c:556
#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:949
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:276
char * savepoint_name
Definition: parsenodes.h:3025
void GrantRole(GrantRoleStmt *stmt)
Definition: user.c:1301
void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest, char *completionTag)
Definition: portalcmds.c:168
RangeVar * relation
Definition: parsenodes.h:3332
void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
Definition: guc.c:8120
int stmt_location
Definition: plannodes.h:93
void check_stack_depth(void)
Definition: postgres.c:3262
Node * utilityStmt
Definition: plannodes.h:90
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3328
void cluster(ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:103
void ExecuteDoStmt(DoStmt *stmt, bool atomic)
const char * p_sourcetext
Definition: parse_node.h:176
void DropTableSpace(DropTableSpaceStmt *stmt)
Definition: tablespace.c:414
void PrepareQuery(PrepareStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: prepare.c:57
char * conditionname
Definition: parsenodes.h:2989
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition: alter.c:332
#define CHECKPOINT_FORCE
Definition: xlog.h:215
#define ereport(elevel, rest)
Definition: elog.h:141
Oid AlterEventTrigger(AlterEventTrigStmt *stmt)
Node * arg
Definition: parsenodes.h:731
bool missing_ok
Definition: parsenodes.h:3147
void BeginTransactionBlock(void)
Definition: xact.c:3587
Oid AlterRole(AlterRoleStmt *stmt)
Definition: user.c:520
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:7906
void CommandCounterIncrement(void)
Definition: xact.c:1003
void ReleaseSavepoint(const char *name)
Definition: xact.c:4121
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:902
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
char * conditionname
Definition: parsenodes.h:2978
void dropdb(const char *dbname, bool missing_ok)
Definition: dbcommands.c:814
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:432
bool EventTriggerSupportsObjectType(ObjectType obtype)
Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
Definition: dbcommands.c:1439
void FinishPreparedTransaction(const char *gid, bool isCommit)
Definition: twophase.c:1454
#define CHECKPOINT_WAIT
Definition: xlog.h:219
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:470
#define COMPLETION_TAG_BUFSIZE
Definition: dest.h:74
void ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
Definition: vacuum.c:88
void DoCopy(ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
Definition: copy.c:838
#define lfirst(lc)
Definition: pg_list.h:190
ReindexObjectType kind
Definition: parsenodes.h:3330
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:146
void Async_UnlistenAll(void)
Definition: async.c:794
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition: alter.c:809
#define nodeTag(nodeptr)
Definition: nodes.h:530
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:615
void LockTableCommand(LockStmt *lockstmt)
Definition: lockcmds.c:41
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
Definition: dbcommands.c:101
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
void ReassignOwnedObjects(ReassignOwnedStmt *stmt)
Definition: user.c:1386
ObjectType objtype
Definition: parsenodes.h:1906
#define CHECKPOINT_IMMEDIATE
Definition: xlog.h:214
static void check_xact_readonly(Node *parsetree)
Definition: utility.c:134
void DropRole(DropRoleStmt *stmt)
Definition: user.c:983
bool concurrent
Definition: parsenodes.h:3335
const char * name
Definition: parsenodes.h:3333
char * defname
Definition: parsenodes.h:730
void UserAbortTransactionBlock(bool chain)
Definition: xact.c:3867
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:77
#define snprintf
Definition: port.h:192
#define UINT64_FORMAT
Definition: c.h:401
char * dbname
Definition: parsenodes.h:3146
void DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
Definition: discard.c:31
void RequireTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3394
void Async_Unlisten(const char *channel)
Definition: async.c:776
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8264
void RequestCheckpoint(int flags)
Definition: checkpointer.c:952
char * payload
Definition: parsenodes.h:2979
TransactionStmtKind kind
Definition: parsenodes.h:3023
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:385
char * conditionname
Definition: parsenodes.h:2999
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:1011

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

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

1919 {
1920  Query *qry;
1921 
1922  switch (nodeTag(parsetree))
1923  {
1924  case T_DeclareCursorStmt:
1925  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
1926  if (qry->commandType == CMD_UTILITY)
1927  return UtilityContainsQuery(qry->utilityStmt);
1928  return qry;
1929 
1930  case T_ExplainStmt:
1931  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
1932  if (qry->commandType == CMD_UTILITY)
1933  return UtilityContainsQuery(qry->utilityStmt);
1934  return qry;
1935 
1936  case T_CreateTableAsStmt:
1937  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
1938  if (qry->commandType == CMD_UTILITY)
1939  return UtilityContainsQuery(qry->utilityStmt);
1940  return qry;
1941 
1942  default:
1943  return NULL;
1944  }
1945 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
Node * utilityStmt
Definition: parsenodes.h:120
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:1918
CmdType commandType
Definition: parsenodes.h:112
#define nodeTag(nodeptr)
Definition: nodes.h:530

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

Definition at line 1768 of file utility.c.

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

Referenced by ChoosePortalStrategy(), and UtilityTupleDescriptor().

1769 {
1770  switch (nodeTag(parsetree))
1771  {
1772  case T_CallStmt:
1773  {
1774  CallStmt *stmt = (CallStmt *) parsetree;
1775 
1776  return (stmt->funcexpr->funcresulttype == RECORDOID);
1777  }
1778  case T_FetchStmt:
1779  {
1780  FetchStmt *stmt = (FetchStmt *) parsetree;
1781  Portal portal;
1782 
1783  if (stmt->ismove)
1784  return false;
1785  portal = GetPortalByName(stmt->portalname);
1786  if (!PortalIsValid(portal))
1787  return false; /* not our business to raise error */
1788  return portal->tupDesc ? true : false;
1789  }
1790 
1791  case T_ExecuteStmt:
1792  {
1793  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1794  PreparedStatement *entry;
1795 
1796  entry = FetchPreparedStatement(stmt->name, false);
1797  if (!entry)
1798  return false; /* not our business to raise error */
1799  if (entry->plansource->resultDesc)
1800  return true;
1801  return false;
1802  }
1803 
1804  case T_ExplainStmt:
1805  return true;
1806 
1807  case T_VariableShowStmt:
1808  return true;
1809 
1810  default:
1811  return false;
1812  }
1813 }
Oid funcresulttype
Definition: primnodes.h:456
FuncExpr * funcexpr
Definition: parsenodes.h:2875
CachedPlanSource * plansource
Definition: prepare.h:31
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
TupleDesc resultDesc
Definition: plancache.h:105
#define true
Definition: c.h:312
char * portalname
Definition: parsenodes.h:2734
#define PortalIsValid(p)
Definition: portal.h:201
bool ismove
Definition: parsenodes.h:2735
TupleDesc tupDesc
Definition: portal.h:157
#define nodeTag(nodeptr)
Definition: nodes.h:530
char * name
Definition: parsenodes.h:3401
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:485

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

Definition at line 1824 of file utility.c.

References CallStmtResultDesc(), 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_CallStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_VariableShowStmt, PortalData::tupDesc, UtilityReturnsTuples(), and Query::utilityStmt.

Referenced by PlanCacheComputeResultDesc(), and PortalStart().

1825 {
1826  switch (nodeTag(parsetree))
1827  {
1828  case T_CallStmt:
1829  return CallStmtResultDesc((CallStmt *) parsetree);
1830 
1831  case T_FetchStmt:
1832  {
1833  FetchStmt *stmt = (FetchStmt *) parsetree;
1834  Portal portal;
1835 
1836  if (stmt->ismove)
1837  return NULL;
1838  portal = GetPortalByName(stmt->portalname);
1839  if (!PortalIsValid(portal))
1840  return NULL; /* not our business to raise error */
1841  return CreateTupleDescCopy(portal->tupDesc);
1842  }
1843 
1844  case T_ExecuteStmt:
1845  {
1846  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1847  PreparedStatement *entry;
1848 
1849  entry = FetchPreparedStatement(stmt->name, false);
1850  if (!entry)
1851  return NULL; /* not our business to raise error */
1852  return FetchPreparedStatementResultDesc(entry);
1853  }
1854 
1855  case T_ExplainStmt:
1856  return ExplainResultDesc((ExplainStmt *) parsetree);
1857 
1858  case T_VariableShowStmt:
1859  {
1860  VariableShowStmt *n = (VariableShowStmt *) parsetree;
1861 
1862  return GetPGVariableResultDesc(n->name);
1863  }
1864 
1865  default:
1866  return NULL;
1867  }
1868 }
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:8747
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:110
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
TupleDesc CallStmtResultDesc(CallStmt *stmt)
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:302
char * portalname
Definition: parsenodes.h:2734
#define PortalIsValid(p)
Definition: portal.h:201
bool ismove
Definition: parsenodes.h:2735
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:517
TupleDesc tupDesc
Definition: portal.h:157
#define nodeTag(nodeptr)
Definition: nodes.h:530
char * name
Definition: parsenodes.h:3401
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:485

Variable Documentation

◆ ProcessUtility_hook

Definition at line 76 of file utility.c.

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