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 99 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().

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

◆ CreateCommandTag()

const char* CreateCommandTag ( Node parsetree)

Definition at line 2093 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_COLUMN, 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().

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

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

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

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

◆ ProcessUtility()

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

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

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

◆ standard_ProcessUtility()

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

Definition at line 376 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(), DeallocateQuery(), DefineSavepoint(), DefElem::defname, DiscardCommand(), DoCopy(), DropDatabase(), 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(), 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().

383 {
384  Node *parsetree = pstmt->utilityStmt;
385  bool isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);
386  bool isAtomicContext = (!(context == PROCESS_UTILITY_TOPLEVEL || context == PROCESS_UTILITY_QUERY_NONATOMIC) || IsTransactionBlock());
387  ParseState *pstate;
388 
389  /* This can recurse, so check for excessive recursion */
391 
392  check_xact_readonly(parsetree);
393 
394  if (completionTag)
395  completionTag[0] = '\0';
396 
397  pstate = make_parsestate(NULL);
398  pstate->p_sourcetext = queryString;
399 
400  switch (nodeTag(parsetree))
401  {
402  /*
403  * ******************** transactions ********************
404  */
405  case T_TransactionStmt:
406  {
407  TransactionStmt *stmt = (TransactionStmt *) parsetree;
408 
409  switch (stmt->kind)
410  {
411  /*
412  * START TRANSACTION, as defined by SQL99: Identical
413  * to BEGIN. Same code for both.
414  */
415  case TRANS_STMT_BEGIN:
416  case TRANS_STMT_START:
417  {
418  ListCell *lc;
419 
421  foreach(lc, stmt->options)
422  {
423  DefElem *item = (DefElem *) lfirst(lc);
424 
425  if (strcmp(item->defname, "transaction_isolation") == 0)
426  SetPGVariable("transaction_isolation",
427  list_make1(item->arg),
428  true);
429  else if (strcmp(item->defname, "transaction_read_only") == 0)
430  SetPGVariable("transaction_read_only",
431  list_make1(item->arg),
432  true);
433  else if (strcmp(item->defname, "transaction_deferrable") == 0)
434  SetPGVariable("transaction_deferrable",
435  list_make1(item->arg),
436  true);
437  }
438  }
439  break;
440 
441  case TRANS_STMT_COMMIT:
442  if (!EndTransactionBlock(stmt->chain))
443  {
444  /* report unsuccessful commit in completionTag */
445  if (completionTag)
446  strcpy(completionTag, "ROLLBACK");
447  }
448  break;
449 
450  case TRANS_STMT_PREPARE:
451  PreventCommandDuringRecovery("PREPARE TRANSACTION");
452  if (!PrepareTransactionBlock(stmt->gid))
453  {
454  /* report unsuccessful commit in completionTag */
455  if (completionTag)
456  strcpy(completionTag, "ROLLBACK");
457  }
458  break;
459 
461  PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
462  PreventCommandDuringRecovery("COMMIT PREPARED");
463  FinishPreparedTransaction(stmt->gid, true);
464  break;
465 
467  PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
468  PreventCommandDuringRecovery("ROLLBACK PREPARED");
469  FinishPreparedTransaction(stmt->gid, false);
470  break;
471 
472  case TRANS_STMT_ROLLBACK:
474  break;
475 
477  RequireTransactionBlock(isTopLevel, "SAVEPOINT");
479  break;
480 
481  case TRANS_STMT_RELEASE:
482  RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
484  break;
485 
487  RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
489 
490  /*
491  * CommitTransactionCommand is in charge of
492  * re-defining the savepoint again
493  */
494  break;
495  }
496  }
497  break;
498 
499  /*
500  * Portal (cursor) manipulation
501  */
502  case T_DeclareCursorStmt:
503  PerformCursorOpen((DeclareCursorStmt *) parsetree, params,
504  queryString, isTopLevel);
505  break;
506 
507  case T_ClosePortalStmt:
508  {
509  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
510 
511  CheckRestrictedOperation("CLOSE");
513  }
514  break;
515 
516  case T_FetchStmt:
517  PerformPortalFetch((FetchStmt *) parsetree, dest,
518  completionTag);
519  break;
520 
521  case T_DoStmt:
522  ExecuteDoStmt((DoStmt *) parsetree, isAtomicContext);
523  break;
524 
526  /* no event triggers for global objects */
527  PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
528  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
529  break;
530 
532  /* no event triggers for global objects */
533  PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
534  DropTableSpace((DropTableSpaceStmt *) parsetree);
535  break;
536 
538  /* no event triggers for global objects */
540  break;
541 
542  case T_TruncateStmt:
543  ExecuteTruncate((TruncateStmt *) parsetree);
544  break;
545 
546  case T_CopyStmt:
547  {
548  uint64 processed;
549 
550  DoCopy(pstate, (CopyStmt *) parsetree,
551  pstmt->stmt_location, pstmt->stmt_len,
552  &processed);
553  if (completionTag)
554  snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
555  "COPY " UINT64_FORMAT, processed);
556  }
557  break;
558 
559  case T_PrepareStmt:
560  CheckRestrictedOperation("PREPARE");
561  PrepareQuery((PrepareStmt *) parsetree, queryString,
562  pstmt->stmt_location, pstmt->stmt_len);
563  break;
564 
565  case T_ExecuteStmt:
566  ExecuteQuery((ExecuteStmt *) parsetree, NULL,
567  queryString, params,
568  dest, completionTag);
569  break;
570 
571  case T_DeallocateStmt:
572  CheckRestrictedOperation("DEALLOCATE");
573  DeallocateQuery((DeallocateStmt *) parsetree);
574  break;
575 
576  case T_GrantRoleStmt:
577  /* no event triggers for global objects */
578  GrantRole((GrantRoleStmt *) parsetree);
579  break;
580 
581  case T_CreatedbStmt:
582  /* no event triggers for global objects */
583  PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
584  createdb(pstate, (CreatedbStmt *) parsetree);
585  break;
586 
587  case T_AlterDatabaseStmt:
588  /* no event triggers for global objects */
589  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
590  break;
591 
593  /* no event triggers for global objects */
594  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
595  break;
596 
597  case T_DropdbStmt:
598  /* no event triggers for global objects */
599  PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
600  DropDatabase(pstate, (DropdbStmt *) parsetree);
601  break;
602 
603  /* Query-level asynchronous notification */
604  case T_NotifyStmt:
605  {
606  NotifyStmt *stmt = (NotifyStmt *) parsetree;
607 
609  Async_Notify(stmt->conditionname, stmt->payload);
610  }
611  break;
612 
613  case T_ListenStmt:
614  {
615  ListenStmt *stmt = (ListenStmt *) parsetree;
616 
618  CheckRestrictedOperation("LISTEN");
620  }
621  break;
622 
623  case T_UnlistenStmt:
624  {
625  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
626 
627  /* we allow UNLISTEN during recovery, as it's a noop */
628  CheckRestrictedOperation("UNLISTEN");
629  if (stmt->conditionname)
631  else
633  }
634  break;
635 
636  case T_LoadStmt:
637  {
638  LoadStmt *stmt = (LoadStmt *) parsetree;
639 
640  closeAllVfds(); /* probably not necessary... */
641  /* Allowed names are restricted if you're not superuser */
642  load_file(stmt->filename, !superuser());
643  }
644  break;
645 
646  case T_CallStmt:
647  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
648  break;
649 
650  case T_ClusterStmt:
651  /* we choose to allow this during "read only" transactions */
652  PreventCommandDuringRecovery("CLUSTER");
653  /* forbidden in parallel mode due to CommandIsReadOnly */
654  cluster((ClusterStmt *) parsetree, isTopLevel);
655  break;
656 
657  case T_VacuumStmt:
658  {
659  VacuumStmt *stmt = (VacuumStmt *) parsetree;
660 
661  /* we choose to allow this during "read only" transactions */
663  "VACUUM" : "ANALYZE");
664  /* forbidden in parallel mode due to CommandIsReadOnly */
665  ExecVacuum(pstate, stmt, isTopLevel);
666  }
667  break;
668 
669  case T_ExplainStmt:
670  ExplainQuery(pstate, (ExplainStmt *) parsetree, queryString, params,
671  queryEnv, dest);
672  break;
673 
674  case T_AlterSystemStmt:
675  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
677  break;
678 
679  case T_VariableSetStmt:
680  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
681  break;
682 
683  case T_VariableShowStmt:
684  {
685  VariableShowStmt *n = (VariableShowStmt *) parsetree;
686 
687  GetPGVariable(n->name, dest);
688  }
689  break;
690 
691  case T_DiscardStmt:
692  /* should we allow DISCARD PLANS? */
693  CheckRestrictedOperation("DISCARD");
694  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
695  break;
696 
698  /* no event triggers on event triggers */
700  break;
701 
703  /* no event triggers on event triggers */
704  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
705  break;
706 
707  /*
708  * ******************************** ROLE statements ****
709  */
710  case T_CreateRoleStmt:
711  /* no event triggers for global objects */
712  CreateRole(pstate, (CreateRoleStmt *) parsetree);
713  break;
714 
715  case T_AlterRoleStmt:
716  /* no event triggers for global objects */
717  AlterRole((AlterRoleStmt *) parsetree);
718  break;
719 
720  case T_AlterRoleSetStmt:
721  /* no event triggers for global objects */
722  AlterRoleSet((AlterRoleSetStmt *) parsetree);
723  break;
724 
725  case T_DropRoleStmt:
726  /* no event triggers for global objects */
727  DropRole((DropRoleStmt *) parsetree);
728  break;
729 
730  case T_ReassignOwnedStmt:
731  /* no event triggers for global objects */
733  break;
734 
735  case T_LockStmt:
736 
737  /*
738  * Since the lock would just get dropped immediately, LOCK TABLE
739  * outside a transaction block is presumed to be user error.
740  */
741  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
742  /* forbidden in parallel mode due to CommandIsReadOnly */
743  LockTableCommand((LockStmt *) parsetree);
744  break;
745 
747  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
749  break;
750 
751  case T_CheckPointStmt:
752  if (!superuser())
753  ereport(ERROR,
754  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
755  errmsg("must be superuser to do CHECKPOINT")));
756 
757  /*
758  * You might think we should have a PreventCommandDuringRecovery()
759  * here, but we interpret a CHECKPOINT command during recovery as
760  * a request for a restartpoint instead. We allow this since it
761  * can be a useful way of reducing switchover time when using
762  * various forms of replication.
763  */
766  break;
767 
768  case T_ReindexStmt:
769  {
770  ReindexStmt *stmt = (ReindexStmt *) parsetree;
771 
772  if (stmt->concurrent)
773  PreventInTransactionBlock(isTopLevel,
774  "REINDEX CONCURRENTLY");
775 
776  /* we choose to allow this during "read only" transactions */
777  PreventCommandDuringRecovery("REINDEX");
778  /* forbidden in parallel mode due to CommandIsReadOnly */
779  switch (stmt->kind)
780  {
782  ReindexIndex(stmt->relation, stmt->options, stmt->concurrent);
783  break;
785  ReindexTable(stmt->relation, stmt->options, stmt->concurrent);
786  break;
790 
791  /*
792  * This cannot run inside a user transaction block; if
793  * we were inside a transaction, then its commit- and
794  * start-transaction-command calls would not have the
795  * intended effect!
796  */
797  PreventInTransactionBlock(isTopLevel,
798  (stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
799  (stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
800  "REINDEX DATABASE");
801  ReindexMultipleTables(stmt->name, stmt->kind, stmt->options, stmt->concurrent);
802  break;
803  default:
804  elog(ERROR, "unrecognized object type: %d",
805  (int) stmt->kind);
806  break;
807  }
808  }
809  break;
810 
811  /*
812  * The following statements are supported by Event Triggers only
813  * in some cases, so we "fast path" them in the other cases.
814  */
815 
816  case T_GrantStmt:
817  {
818  GrantStmt *stmt = (GrantStmt *) parsetree;
819 
821  ProcessUtilitySlow(pstate, pstmt, queryString,
822  context, params, queryEnv,
823  dest, completionTag);
824  else
825  ExecuteGrantStmt(stmt);
826  }
827  break;
828 
829  case T_DropStmt:
830  {
831  DropStmt *stmt = (DropStmt *) parsetree;
832 
834  ProcessUtilitySlow(pstate, pstmt, queryString,
835  context, params, queryEnv,
836  dest, completionTag);
837  else
838  ExecDropStmt(stmt, isTopLevel);
839  }
840  break;
841 
842  case T_RenameStmt:
843  {
844  RenameStmt *stmt = (RenameStmt *) parsetree;
845 
847  ProcessUtilitySlow(pstate, pstmt, queryString,
848  context, params, queryEnv,
849  dest, completionTag);
850  else
851  ExecRenameStmt(stmt);
852  }
853  break;
854 
856  {
857  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
858 
860  ProcessUtilitySlow(pstate, pstmt, queryString,
861  context, params, queryEnv,
862  dest, completionTag);
863  else
864  ExecAlterObjectDependsStmt(stmt, NULL);
865  }
866  break;
867 
869  {
870  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
871 
873  ProcessUtilitySlow(pstate, pstmt, queryString,
874  context, params, queryEnv,
875  dest, completionTag);
876  else
877  ExecAlterObjectSchemaStmt(stmt, NULL);
878  }
879  break;
880 
881  case T_AlterOwnerStmt:
882  {
883  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
884 
886  ProcessUtilitySlow(pstate, pstmt, queryString,
887  context, params, queryEnv,
888  dest, completionTag);
889  else
890  ExecAlterOwnerStmt(stmt);
891  }
892  break;
893 
894  case T_CommentStmt:
895  {
896  CommentStmt *stmt = (CommentStmt *) parsetree;
897 
899  ProcessUtilitySlow(pstate, pstmt, queryString,
900  context, params, queryEnv,
901  dest, completionTag);
902  else
903  CommentObject(stmt);
904  break;
905  }
906 
907  case T_SecLabelStmt:
908  {
909  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
910 
912  ProcessUtilitySlow(pstate, pstmt, queryString,
913  context, params, queryEnv,
914  dest, completionTag);
915  else
916  ExecSecLabelStmt(stmt);
917  break;
918  }
919 
920  default:
921  /* All other statement types have event trigger support */
922  ProcessUtilitySlow(pstate, pstmt, queryString,
923  context, params, queryEnv,
924  dest, completionTag);
925  break;
926  }
927 
928  free_parsestate(pstate);
929 
930  /*
931  * Make effects of commands visible, for instance so that
932  * PreCommit_on_commit_actions() can see them (see for example bug
933  * #15631).
934  */
936 }
ObjectType objtype
Definition: parsenodes.h:2657
void closeAllVfds(void)
Definition: fd.c:2680
ObjectType objtype
Definition: parsenodes.h:2669
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1724
void PerformPortalClose(const char *name)
Definition: portalcmds.c:216
bool EndTransactionBlock(bool chain)
Definition: xact.c:3709
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:3391
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:1650
ObjectType objectType
Definition: parsenodes.h:2936
void DefineSavepoint(const char *name)
Definition: xact.c:4038
bool is_vacuumcmd
Definition: parsenodes.h:3191
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:5332
void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest)
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:293
Definition: nodes.h:525
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3657
int errcode(int sqlerrcode)
Definition: elog.c:608
void PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params, const char *queryString, bool isTopLevel)
Definition: portalcmds.c:42
bool superuser(void)
Definition: superuser.c:46
char * filename
Definition: parsenodes.h:3107
void Async_Listen(const char *channel)
Definition: async.c:762
Oid CreateTableSpace(CreateTableSpaceStmt *stmt)
Definition: tablespace.c:233
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:7935
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1501
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:4232
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc.c:8791
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:43
#define list_make1(x1)
Definition: pg_list.h:227
bool IsTransactionBlock(void)
Definition: xact.c:4635
void DeallocateQuery(DeallocateStmt *stmt)
Definition: prepare.c:557
#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:944
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:275
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:3333
void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
Definition: guc.c:8173
int stmt_location
Definition: plannodes.h:93
void check_stack_depth(void)
Definition: postgres.c:3277
Node * utilityStmt
Definition: plannodes.h:90
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3331
void cluster(ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:102
void ExecuteDoStmt(DoStmt *stmt, bool atomic)
const char * p_sourcetext
Definition: parse_node.h:176
void DropTableSpace(DropTableSpaceStmt *stmt)
Definition: tablespace.c:413
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:331
#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
void BeginTransactionBlock(void)
Definition: xact.c:3589
Oid AlterRole(AlterRoleStmt *stmt)
Definition: user.c:520
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:7959
void CommandCounterIncrement(void)
Definition: xact.c:1005
void ReleaseSavepoint(const char *name)
Definition: xact.c:4123
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:902
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
char * conditionname
Definition: parsenodes.h:2978
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:431
bool EventTriggerSupportsObjectType(ObjectType obtype)
Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
Definition: dbcommands.c:1471
void FinishPreparedTransaction(const char *gid, bool isCommit)
Definition: twophase.c:1399
#define CHECKPOINT_WAIT
Definition: xlog.h:219
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:469
#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:837
#define lfirst(lc)
Definition: pg_list.h:190
ReindexObjectType kind
Definition: parsenodes.h:3331
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:807
#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:100
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
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:133
void DropRole(DropRoleStmt *stmt)
Definition: user.c:983
bool concurrent
Definition: parsenodes.h:3336
const char * name
Definition: parsenodes.h:3334
char * defname
Definition: parsenodes.h:730
void UserAbortTransactionBlock(bool chain)
Definition: xact.c:3869
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:76
#define snprintf
Definition: port.h:192
void DropDatabase(ParseState *pstate, DropdbStmt *stmt)
Definition: dbcommands.c:1446
#define UINT64_FORMAT
Definition: c.h:402
void DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
Definition: discard.c:31
void RequireTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3397
void Async_Unlisten(const char *channel)
Definition: async.c:776
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:8317
void RequestCheckpoint(int flags)
Definition: checkpointer.c:941
char * payload
Definition: parsenodes.h:2979
TransactionStmtKind kind
Definition: parsenodes.h:3023
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:384
char * conditionname
Definition: parsenodes.h:2999
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:1010

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

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

1908 {
1909  Query *qry;
1910 
1911  switch (nodeTag(parsetree))
1912  {
1913  case T_DeclareCursorStmt:
1914  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
1915  if (qry->commandType == CMD_UTILITY)
1916  return UtilityContainsQuery(qry->utilityStmt);
1917  return qry;
1918 
1919  case T_ExplainStmt:
1920  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
1921  if (qry->commandType == CMD_UTILITY)
1922  return UtilityContainsQuery(qry->utilityStmt);
1923  return qry;
1924 
1925  case T_CreateTableAsStmt:
1926  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
1927  if (qry->commandType == CMD_UTILITY)
1928  return UtilityContainsQuery(qry->utilityStmt);
1929  return qry;
1930 
1931  default:
1932  return NULL;
1933  }
1934 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
Node * utilityStmt
Definition: parsenodes.h:120
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:1907
CmdType commandType
Definition: parsenodes.h:112
#define nodeTag(nodeptr)
Definition: nodes.h:530

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

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

1758 {
1759  switch (nodeTag(parsetree))
1760  {
1761  case T_CallStmt:
1762  {
1763  CallStmt *stmt = (CallStmt *) parsetree;
1764 
1765  return (stmt->funcexpr->funcresulttype == RECORDOID);
1766  }
1767  case T_FetchStmt:
1768  {
1769  FetchStmt *stmt = (FetchStmt *) parsetree;
1770  Portal portal;
1771 
1772  if (stmt->ismove)
1773  return false;
1774  portal = GetPortalByName(stmt->portalname);
1775  if (!PortalIsValid(portal))
1776  return false; /* not our business to raise error */
1777  return portal->tupDesc ? true : false;
1778  }
1779 
1780  case T_ExecuteStmt:
1781  {
1782  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1783  PreparedStatement *entry;
1784 
1785  entry = FetchPreparedStatement(stmt->name, false);
1786  if (!entry)
1787  return false; /* not our business to raise error */
1788  if (entry->plansource->resultDesc)
1789  return true;
1790  return false;
1791  }
1792 
1793  case T_ExplainStmt:
1794  return true;
1795 
1796  case T_VariableShowStmt:
1797  return true;
1798 
1799  default:
1800  return false;
1801  }
1802 }
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:313
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:3402
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:486

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

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

1814 {
1815  switch (nodeTag(parsetree))
1816  {
1817  case T_CallStmt:
1818  return CallStmtResultDesc((CallStmt *) parsetree);
1819 
1820  case T_FetchStmt:
1821  {
1822  FetchStmt *stmt = (FetchStmt *) parsetree;
1823  Portal portal;
1824 
1825  if (stmt->ismove)
1826  return NULL;
1827  portal = GetPortalByName(stmt->portalname);
1828  if (!PortalIsValid(portal))
1829  return NULL; /* not our business to raise error */
1830  return CreateTupleDescCopy(portal->tupDesc);
1831  }
1832 
1833  case T_ExecuteStmt:
1834  {
1835  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1836  PreparedStatement *entry;
1837 
1838  entry = FetchPreparedStatement(stmt->name, false);
1839  if (!entry)
1840  return NULL; /* not our business to raise error */
1841  return FetchPreparedStatementResultDesc(entry);
1842  }
1843 
1844  case T_ExplainStmt:
1845  return ExplainResultDesc((ExplainStmt *) parsetree);
1846 
1847  case T_VariableShowStmt:
1848  {
1849  VariableShowStmt *n = (VariableShowStmt *) parsetree;
1850 
1851  return GetPGVariableResultDesc(n->name);
1852  }
1853 
1854  default:
1855  return NULL;
1856  }
1857 }
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:8800
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:518
TupleDesc tupDesc
Definition: portal.h:157
#define nodeTag(nodeptr)
Definition: nodes.h:530
char * name
Definition: parsenodes.h:3402
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:486

Variable Documentation

◆ ProcessUtility_hook

Definition at line 75 of file utility.c.

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