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:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:568
#define WARNING
Definition: elog.h:40
CmdType commandType
Definition: plannodes.h:45
List * rowMarks
Definition: plannodes.h:88
#define Assert(condition)
Definition: c.h:699
bool hasModifyingCTE
Definition: plannodes.h:51
#define elog
Definition: elog.h:219

◆ CreateCommandTag()

const char* CreateCommandTag ( Node parsetree)

Definition at line 2070 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_AlterSubscriptionStmt, T_AlterSystemStmt, T_AlterTableMoveAllStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterUserMappingStmt, T_CallStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreateAmStmt, T_CreateCastStmt, T_CreateConversionStmt, T_CreatedbStmt, T_CreateDomainStmt, T_CreateEnumStmt, T_CreateEventTrigStmt, T_CreateExtensionStmt, T_CreateFdwStmt, T_CreateForeignServerStmt, T_CreateForeignTableStmt, T_CreateFunctionStmt, T_CreateOpClassStmt, T_CreateOpFamilyStmt, T_CreatePLangStmt, T_CreatePolicyStmt, T_CreatePublicationStmt, T_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStatsStmt, T_CreateStmt, T_CreateSubscriptionStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, T_CreateTransformStmt, T_CreateTrigStmt, T_CreateUserMappingStmt, T_DeallocateStmt, T_DeclareCursorStmt, T_DefineStmt, T_DeleteStmt, T_DiscardStmt, T_DoStmt, T_DropdbStmt, T_DropOwnedStmt, T_DropRoleStmt, T_DropStmt, T_DropSubscriptionStmt, T_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_ImportForeignSchemaStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PrepareStmt, T_Query, T_RawStmt, T_ReassignOwnedStmt, T_RefreshMatViewStmt, T_ReindexStmt, T_RenameStmt, T_RuleStmt, T_SecLabelStmt, T_SelectStmt, T_TransactionStmt, T_TruncateStmt, T_UnlistenStmt, T_UpdateStmt, T_VacuumStmt, T_VariableSetStmt, T_VariableShowStmt, T_ViewStmt, TRANS_STMT_BEGIN, TRANS_STMT_COMMIT, TRANS_STMT_COMMIT_PREPARED, TRANS_STMT_PREPARE, TRANS_STMT_RELEASE, TRANS_STMT_ROLLBACK, TRANS_STMT_ROLLBACK_PREPARED, TRANS_STMT_ROLLBACK_TO, TRANS_STMT_SAVEPOINT, TRANS_STMT_START, PlannedStmt::utilityStmt, Query::utilityStmt, VACOPT_VACUUM, VAR_RESET, VAR_RESET_ALL, VAR_SET_CURRENT, VAR_SET_DEFAULT, VAR_SET_MULTI, VAR_SET_VALUE, and WARNING.

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

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

◆ GetCommandLogLevel()

LogStmtLevel GetCommandLogLevel ( Node parsetree)

Definition at line 2930 of file utility.c.

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

Referenced by check_log_statement(), and GetCommandLogLevel().

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

◆ 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:568
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:45
#define Assert(condition)
Definition: c.h:699

◆ 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, check_xact_readonly(), CHECKPOINT_FORCE, CHECKPOINT_IMMEDIATE, CHECKPOINT_WAIT, CheckRestrictedOperation(), closeAllVfds(), cluster(), CommentObject(), COMPLETION_TAG_BUFSIZE, NotifyStmt::conditionname, ListenStmt::conditionname, UnlistenStmt::conditionname, createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DropdbStmt::dbname, DeallocateQuery(), DefineSavepoint(), DefElem::defname, DiscardCommand(), DoCopy(), dropdb(), DropRole(), DropTableSpace(), elog, EndTransactionBlock(), ereport, errcode(), errmsg(), ERROR, EventTriggerSupportsObjectType(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteCallStmt(), ExecuteDoStmt(), ExecuteGrantStmt(), ExecuteQuery(), ExecuteTruncate(), ExecVacuum(), ExplainQuery(), LoadStmt::filename, FinishPreparedTransaction(), free_parsestate(), GetPGVariable(), TransactionStmt::gid, GrantRole(), 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, VacuumStmt::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, VACOPT_VACUUM, 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  check_xact_readonly(parsetree);
391 
392  if (completionTag)
393  completionTag[0] = '\0';
394 
395  pstate = make_parsestate(NULL);
396  pstate->p_sourcetext = queryString;
397 
398  switch (nodeTag(parsetree))
399  {
400  /*
401  * ******************** transactions ********************
402  */
403  case T_TransactionStmt:
404  {
405  TransactionStmt *stmt = (TransactionStmt *) parsetree;
406 
407  switch (stmt->kind)
408  {
409  /*
410  * START TRANSACTION, as defined by SQL99: Identical
411  * to BEGIN. Same code for both.
412  */
413  case TRANS_STMT_BEGIN:
414  case TRANS_STMT_START:
415  {
416  ListCell *lc;
417 
419  foreach(lc, stmt->options)
420  {
421  DefElem *item = (DefElem *) lfirst(lc);
422 
423  if (strcmp(item->defname, "transaction_isolation") == 0)
424  SetPGVariable("transaction_isolation",
425  list_make1(item->arg),
426  true);
427  else if (strcmp(item->defname, "transaction_read_only") == 0)
428  SetPGVariable("transaction_read_only",
429  list_make1(item->arg),
430  true);
431  else if (strcmp(item->defname, "transaction_deferrable") == 0)
432  SetPGVariable("transaction_deferrable",
433  list_make1(item->arg),
434  true);
435  }
436  }
437  break;
438 
439  case TRANS_STMT_COMMIT:
440  if (!EndTransactionBlock())
441  {
442  /* report unsuccessful commit in completionTag */
443  if (completionTag)
444  strcpy(completionTag, "ROLLBACK");
445  }
446  break;
447 
448  case TRANS_STMT_PREPARE:
449  PreventCommandDuringRecovery("PREPARE TRANSACTION");
450  if (!PrepareTransactionBlock(stmt->gid))
451  {
452  /* report unsuccessful commit in completionTag */
453  if (completionTag)
454  strcpy(completionTag, "ROLLBACK");
455  }
456  break;
457 
459  PreventInTransactionBlock(isTopLevel, "COMMIT PREPARED");
460  PreventCommandDuringRecovery("COMMIT PREPARED");
461  FinishPreparedTransaction(stmt->gid, true);
462  break;
463 
465  PreventInTransactionBlock(isTopLevel, "ROLLBACK PREPARED");
466  PreventCommandDuringRecovery("ROLLBACK PREPARED");
467  FinishPreparedTransaction(stmt->gid, false);
468  break;
469 
470  case TRANS_STMT_ROLLBACK:
472  break;
473 
475  RequireTransactionBlock(isTopLevel, "SAVEPOINT");
477  break;
478 
479  case TRANS_STMT_RELEASE:
480  RequireTransactionBlock(isTopLevel, "RELEASE SAVEPOINT");
482  break;
483 
485  RequireTransactionBlock(isTopLevel, "ROLLBACK TO SAVEPOINT");
487 
488  /*
489  * CommitTransactionCommand is in charge of
490  * re-defining the savepoint again
491  */
492  break;
493  }
494  }
495  break;
496 
497  /*
498  * Portal (cursor) manipulation
499  */
500  case T_DeclareCursorStmt:
501  PerformCursorOpen((DeclareCursorStmt *) parsetree, params,
502  queryString, isTopLevel);
503  break;
504 
505  case T_ClosePortalStmt:
506  {
507  ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
508 
509  CheckRestrictedOperation("CLOSE");
511  }
512  break;
513 
514  case T_FetchStmt:
515  PerformPortalFetch((FetchStmt *) parsetree, dest,
516  completionTag);
517  break;
518 
519  case T_DoStmt:
520  ExecuteDoStmt((DoStmt *) parsetree, isAtomicContext);
521  break;
522 
524  /* no event triggers for global objects */
525  PreventInTransactionBlock(isTopLevel, "CREATE TABLESPACE");
526  CreateTableSpace((CreateTableSpaceStmt *) parsetree);
527  break;
528 
530  /* no event triggers for global objects */
531  PreventInTransactionBlock(isTopLevel, "DROP TABLESPACE");
532  DropTableSpace((DropTableSpaceStmt *) parsetree);
533  break;
534 
536  /* no event triggers for global objects */
538  break;
539 
540  case T_TruncateStmt:
541  ExecuteTruncate((TruncateStmt *) parsetree);
542  break;
543 
544  case T_CopyStmt:
545  {
546  uint64 processed;
547 
548  DoCopy(pstate, (CopyStmt *) parsetree,
549  pstmt->stmt_location, pstmt->stmt_len,
550  &processed);
551  if (completionTag)
552  snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
553  "COPY " UINT64_FORMAT, processed);
554  }
555  break;
556 
557  case T_PrepareStmt:
558  CheckRestrictedOperation("PREPARE");
559  PrepareQuery((PrepareStmt *) parsetree, queryString,
560  pstmt->stmt_location, pstmt->stmt_len);
561  break;
562 
563  case T_ExecuteStmt:
564  ExecuteQuery((ExecuteStmt *) parsetree, NULL,
565  queryString, params,
566  dest, completionTag);
567  break;
568 
569  case T_DeallocateStmt:
570  CheckRestrictedOperation("DEALLOCATE");
571  DeallocateQuery((DeallocateStmt *) parsetree);
572  break;
573 
574  case T_GrantRoleStmt:
575  /* no event triggers for global objects */
576  GrantRole((GrantRoleStmt *) parsetree);
577  break;
578 
579  case T_CreatedbStmt:
580  /* no event triggers for global objects */
581  PreventInTransactionBlock(isTopLevel, "CREATE DATABASE");
582  createdb(pstate, (CreatedbStmt *) parsetree);
583  break;
584 
585  case T_AlterDatabaseStmt:
586  /* no event triggers for global objects */
587  AlterDatabase(pstate, (AlterDatabaseStmt *) parsetree, isTopLevel);
588  break;
589 
591  /* no event triggers for global objects */
592  AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
593  break;
594 
595  case T_DropdbStmt:
596  {
597  DropdbStmt *stmt = (DropdbStmt *) parsetree;
598 
599  /* no event triggers for global objects */
600  PreventInTransactionBlock(isTopLevel, "DROP DATABASE");
601  dropdb(stmt->dbname, stmt->missing_ok);
602  }
603  break;
604 
605  /* Query-level asynchronous notification */
606  case T_NotifyStmt:
607  {
608  NotifyStmt *stmt = (NotifyStmt *) parsetree;
609 
611  Async_Notify(stmt->conditionname, stmt->payload);
612  }
613  break;
614 
615  case T_ListenStmt:
616  {
617  ListenStmt *stmt = (ListenStmt *) parsetree;
618 
620  CheckRestrictedOperation("LISTEN");
622  }
623  break;
624 
625  case T_UnlistenStmt:
626  {
627  UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
628 
629  PreventCommandDuringRecovery("UNLISTEN");
630  CheckRestrictedOperation("UNLISTEN");
631  if (stmt->conditionname)
633  else
635  }
636  break;
637 
638  case T_LoadStmt:
639  {
640  LoadStmt *stmt = (LoadStmt *) parsetree;
641 
642  closeAllVfds(); /* probably not necessary... */
643  /* Allowed names are restricted if you're not superuser */
644  load_file(stmt->filename, !superuser());
645  }
646  break;
647 
648  case T_CallStmt:
649  ExecuteCallStmt(castNode(CallStmt, parsetree), params, isAtomicContext, dest);
650  break;
651 
652  case T_ClusterStmt:
653  /* we choose to allow this during "read only" transactions */
654  PreventCommandDuringRecovery("CLUSTER");
655  /* forbidden in parallel mode due to CommandIsReadOnly */
656  cluster((ClusterStmt *) parsetree, isTopLevel);
657  break;
658 
659  case T_VacuumStmt:
660  {
661  VacuumStmt *stmt = (VacuumStmt *) parsetree;
662 
663  /* we choose to allow this during "read only" transactions */
665  "VACUUM" : "ANALYZE");
666  /* forbidden in parallel mode due to CommandIsReadOnly */
667  ExecVacuum(stmt, isTopLevel);
668  }
669  break;
670 
671  case T_ExplainStmt:
672  ExplainQuery(pstate, (ExplainStmt *) parsetree, queryString, params,
673  queryEnv, dest);
674  break;
675 
676  case T_AlterSystemStmt:
677  PreventInTransactionBlock(isTopLevel, "ALTER SYSTEM");
679  break;
680 
681  case T_VariableSetStmt:
682  ExecSetVariableStmt((VariableSetStmt *) parsetree, isTopLevel);
683  break;
684 
685  case T_VariableShowStmt:
686  {
687  VariableShowStmt *n = (VariableShowStmt *) parsetree;
688 
689  GetPGVariable(n->name, dest);
690  }
691  break;
692 
693  case T_DiscardStmt:
694  /* should we allow DISCARD PLANS? */
695  CheckRestrictedOperation("DISCARD");
696  DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
697  break;
698 
700  /* no event triggers on event triggers */
702  break;
703 
705  /* no event triggers on event triggers */
706  AlterEventTrigger((AlterEventTrigStmt *) parsetree);
707  break;
708 
709  /*
710  * ******************************** ROLE statements ****
711  */
712  case T_CreateRoleStmt:
713  /* no event triggers for global objects */
714  CreateRole(pstate, (CreateRoleStmt *) parsetree);
715  break;
716 
717  case T_AlterRoleStmt:
718  /* no event triggers for global objects */
719  AlterRole((AlterRoleStmt *) parsetree);
720  break;
721 
722  case T_AlterRoleSetStmt:
723  /* no event triggers for global objects */
724  AlterRoleSet((AlterRoleSetStmt *) parsetree);
725  break;
726 
727  case T_DropRoleStmt:
728  /* no event triggers for global objects */
729  DropRole((DropRoleStmt *) parsetree);
730  break;
731 
732  case T_ReassignOwnedStmt:
733  /* no event triggers for global objects */
735  break;
736 
737  case T_LockStmt:
738 
739  /*
740  * Since the lock would just get dropped immediately, LOCK TABLE
741  * outside a transaction block is presumed to be user error.
742  */
743  RequireTransactionBlock(isTopLevel, "LOCK TABLE");
744  /* forbidden in parallel mode due to CommandIsReadOnly */
745  LockTableCommand((LockStmt *) parsetree);
746  break;
747 
749  WarnNoTransactionBlock(isTopLevel, "SET CONSTRAINTS");
751  break;
752 
753  case T_CheckPointStmt:
754  if (!superuser())
755  ereport(ERROR,
756  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
757  errmsg("must be superuser to do CHECKPOINT")));
758 
759  /*
760  * You might think we should have a PreventCommandDuringRecovery()
761  * here, but we interpret a CHECKPOINT command during recovery as
762  * a request for a restartpoint instead. We allow this since it
763  * can be a useful way of reducing switchover time when using
764  * various forms of replication.
765  */
768  break;
769 
770  case T_ReindexStmt:
771  {
772  ReindexStmt *stmt = (ReindexStmt *) parsetree;
773 
774  /* we choose to allow this during "read only" transactions */
775  PreventCommandDuringRecovery("REINDEX");
776  /* forbidden in parallel mode due to CommandIsReadOnly */
777  switch (stmt->kind)
778  {
780  ReindexIndex(stmt->relation, stmt->options);
781  break;
783  ReindexTable(stmt->relation, stmt->options);
784  break;
788 
789  /*
790  * This cannot run inside a user transaction block; if
791  * we were inside a transaction, then its commit- and
792  * start-transaction-command calls would not have the
793  * intended effect!
794  */
795  PreventInTransactionBlock(isTopLevel,
796  (stmt->kind == REINDEX_OBJECT_SCHEMA) ? "REINDEX SCHEMA" :
797  (stmt->kind == REINDEX_OBJECT_SYSTEM) ? "REINDEX SYSTEM" :
798  "REINDEX DATABASE");
799  ReindexMultipleTables(stmt->name, stmt->kind, stmt->options);
800  break;
801  default:
802  elog(ERROR, "unrecognized object type: %d",
803  (int) stmt->kind);
804  break;
805  }
806  }
807  break;
808 
809  /*
810  * The following statements are supported by Event Triggers only
811  * in some cases, so we "fast path" them in the other cases.
812  */
813 
814  case T_GrantStmt:
815  {
816  GrantStmt *stmt = (GrantStmt *) parsetree;
817 
819  ProcessUtilitySlow(pstate, pstmt, queryString,
820  context, params, queryEnv,
821  dest, completionTag);
822  else
823  ExecuteGrantStmt(stmt);
824  }
825  break;
826 
827  case T_DropStmt:
828  {
829  DropStmt *stmt = (DropStmt *) parsetree;
830 
832  ProcessUtilitySlow(pstate, pstmt, queryString,
833  context, params, queryEnv,
834  dest, completionTag);
835  else
836  ExecDropStmt(stmt, isTopLevel);
837  }
838  break;
839 
840  case T_RenameStmt:
841  {
842  RenameStmt *stmt = (RenameStmt *) parsetree;
843 
845  ProcessUtilitySlow(pstate, pstmt, queryString,
846  context, params, queryEnv,
847  dest, completionTag);
848  else
849  ExecRenameStmt(stmt);
850  }
851  break;
852 
854  {
855  AlterObjectDependsStmt *stmt = (AlterObjectDependsStmt *) parsetree;
856 
858  ProcessUtilitySlow(pstate, pstmt, queryString,
859  context, params, queryEnv,
860  dest, completionTag);
861  else
862  ExecAlterObjectDependsStmt(stmt, NULL);
863  }
864  break;
865 
867  {
868  AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;
869 
871  ProcessUtilitySlow(pstate, pstmt, queryString,
872  context, params, queryEnv,
873  dest, completionTag);
874  else
875  ExecAlterObjectSchemaStmt(stmt, NULL);
876  }
877  break;
878 
879  case T_AlterOwnerStmt:
880  {
881  AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;
882 
884  ProcessUtilitySlow(pstate, pstmt, queryString,
885  context, params, queryEnv,
886  dest, completionTag);
887  else
888  ExecAlterOwnerStmt(stmt);
889  }
890  break;
891 
892  case T_CommentStmt:
893  {
894  CommentStmt *stmt = (CommentStmt *) parsetree;
895 
897  ProcessUtilitySlow(pstate, pstmt, queryString,
898  context, params, queryEnv,
899  dest, completionTag);
900  else
901  CommentObject(stmt);
902  break;
903  }
904 
905  case T_SecLabelStmt:
906  {
907  SecLabelStmt *stmt = (SecLabelStmt *) parsetree;
908 
910  ProcessUtilitySlow(pstate, pstmt, queryString,
911  context, params, queryEnv,
912  dest, completionTag);
913  else
914  ExecSecLabelStmt(stmt);
915  break;
916  }
917 
918  default:
919  /* All other statement types have event trigger support */
920  ProcessUtilitySlow(pstate, pstmt, queryString,
921  context, params, queryEnv,
922  dest, completionTag);
923  break;
924  }
925 
926  free_parsestate(pstate);
927 }
ObjectType objtype
Definition: parsenodes.h:2618
void closeAllVfds(void)
Definition: fd.c:2767
ObjectType objtype
Definition: parsenodes.h:2630
static void ExecDropStmt(DropStmt *stmt, bool isTopLevel)
Definition: utility.c:1710
void PerformPortalClose(const char *name)
Definition: portalcmds.c:216
ObjectAddress CommentObject(CommentStmt *stmt)
Definition: comment.c:40
ObjectType renameType
Definition: parsenodes.h:2843
Oid ReindexTable(RangeVar *relation, int options)
Definition: indexcmds.c:2261
ObjectAddress ExecSecLabelStmt(SecLabelStmt *stmt)
Definition: seclabel.c:44
void WarnNoTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3213
#define castNode(_type_, nodeptr)
Definition: nodes.h:586
Oid AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
Definition: dbcommands.c:1575
ObjectType objectType
Definition: parsenodes.h:2888
void DefineSavepoint(const char *name)
Definition: xact.c:3825
void AfterTriggerSetState(ConstraintsSetStmt *stmt)
Definition: trigger.c:5306
void ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest)
static void CheckRestrictedOperation(const char *cmdname)
Definition: utility.c:294
Definition: nodes.h:517
bool PrepareTransactionBlock(const char *gid)
Definition: xact.c:3480
int errcode(int sqlerrcode)
Definition: elog.c:575
void PerformCursorOpen(DeclareCursorStmt *cstmt, ParamListInfo params, const char *queryString, bool isTopLevel)
Definition: portalcmds.c:42
bool superuser(void)
Definition: superuser.c:47
char * filename
Definition: parsenodes.h:3058
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
void Async_Listen(const char *channel)
Definition: async.c:638
Oid CreateTableSpace(CreateTableSpaceStmt *stmt)
Definition: tablespace.c:234
bool RecoveryInProgress(void)
Definition: xlog.c:7949
void ExecuteTruncate(TruncateStmt *stmt)
Definition: tablecmds.c:1322
bool EndTransactionBlock(void)
Definition: xact.c:3532
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:100
Oid CreateRole(ParseState *pstate, CreateRoleStmt *stmt)
Definition: user.c:72
ObjectType removeType
Definition: parsenodes.h:2593
void RollbackToSavepoint(const char *name)
Definition: xact.c:4019
void GetPGVariable(const char *name, DestReceiver *dest)
Definition: guc.c:8171
ParseState * make_parsestate(ParseState *parentParseState)
Definition: parse_node.c:44
void ReindexIndex(RangeVar *indexRelation, int options)
Definition: indexcmds.c:2161
#define list_make1(x1)
Definition: pg_list.h:139
bool IsTransactionBlock(void)
Definition: xact.c:4422
void DeallocateQuery(DeallocateStmt *stmt)
Definition: prepare.c:566
#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:935
void PreventCommandDuringRecovery(const char *cmdname)
Definition: utility.c:276
char * savepoint_name
Definition: parsenodes.h:2977
void GrantRole(GrantRoleStmt *stmt)
Definition: user.c:1274
void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest, char *completionTag)
Definition: portalcmds.c:168
RangeVar * relation
Definition: parsenodes.h:3288
void UserAbortTransactionBlock(void)
Definition: xact.c:3668
void ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
Definition: guc.c:7553
int stmt_location
Definition: plannodes.h:99
void ExecVacuum(VacuumStmt *vacstmt, bool isTopLevel)
Definition: vacuum.c:87
Node * utilityStmt
Definition: plannodes.h:96
void PreventInTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3153
void cluster(ClusterStmt *stmt, bool isTopLevel)
Definition: cluster.c:106
void ExecuteDoStmt(DoStmt *stmt, bool atomic)
const char * p_sourcetext
Definition: parse_node.h:173
void DropTableSpace(DropTableSpaceStmt *stmt)
Definition: tablespace.c:402
void PrepareQuery(PrepareStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
Definition: prepare.c:57
char * conditionname
Definition: parsenodes.h:2941
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition: alter.c:325
#define CHECKPOINT_FORCE
Definition: xlog.h:180
#define ereport(elevel, rest)
Definition: elog.h:122
Oid AlterEventTrigger(AlterEventTrigStmt *stmt)
Node * arg
Definition: parsenodes.h:731
void ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind, int options)
Definition: indexcmds.c:2289
bool missing_ok
Definition: parsenodes.h:3098
void BeginTransactionBlock(void)
Definition: xact.c:3412
Oid AlterRole(AlterRoleStmt *stmt)
Definition: user.c:504
void AlterSystemSetConfigFile(AlterSystemStmt *altersysstmt)
Definition: guc.c:7339
void ReleaseSavepoint(const char *name)
Definition: xact.c:3910
Oid AlterRoleSet(AlterRoleSetStmt *stmt)
Definition: user.c:886
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
char * conditionname
Definition: parsenodes.h:2930
void dropdb(const char *dbname, bool missing_ok)
Definition: dbcommands.c:780
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition: alter.c:425
bool EventTriggerSupportsObjectType(ObjectType obtype)
Oid AlterDatabase(ParseState *pstate, AlterDatabaseStmt *stmt, bool isTopLevel)
Definition: dbcommands.c:1397
void FinishPreparedTransaction(const char *gid, bool isCommit)
Definition: twophase.c:1433
#define CHECKPOINT_WAIT
Definition: xlog.h:184
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition: alter.c:463
#define COMPLETION_TAG_BUFSIZE
Definition: dest.h:74
void DoCopy(ParseState *pstate, const CopyStmt *stmt, int stmt_location, int stmt_len, uint64 *processed)
Definition: copy.c:782
#define lfirst(lc)
Definition: pg_list.h:106
ReindexObjectType kind
Definition: parsenodes.h:3286
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:137
void Async_UnlistenAll(void)
Definition: async.c:670
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition: alter.c:802
#define nodeTag(nodeptr)
Definition: nodes.h:522
void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest)
Definition: explain.c:143
void Async_Notify(const char *channel, const char *payload)
Definition: async.c:543
void LockTableCommand(LockStmt *lockstmt)
Definition: lockcmds.c:40
Oid createdb(ParseState *pstate, const CreatedbStmt *stmt)
Definition: dbcommands.c:99
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ReassignOwnedObjects(ReassignOwnedStmt *stmt)
Definition: user.c:1359
ObjectType objtype
Definition: parsenodes.h:1872
#define CHECKPOINT_IMMEDIATE
Definition: xlog.h:179
static void check_xact_readonly(Node *parsetree)
Definition: utility.c:134
void DropRole(DropRoleStmt *stmt)
Definition: user.c:966
const char * name
Definition: parsenodes.h:3289
char * defname
Definition: parsenodes.h:730
#define elog
Definition: elog.h:219
void free_parsestate(ParseState *pstate)
Definition: parse_node.c:77
#define UINT64_FORMAT
Definition: c.h:368
char * dbname
Definition: parsenodes.h:3097
void DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
Definition: discard.c:31
void RequireTransactionBlock(bool isTopLevel, const char *stmtType)
Definition: xact.c:3219
void Async_Unlisten(const char *channel)
Definition: async.c:652
void SetPGVariable(const char *name, List *args, bool is_local)
Definition: guc.c:7697
void RequestCheckpoint(int flags)
Definition: checkpointer.c:967
char * payload
Definition: parsenodes.h:2931
TransactionStmtKind kind
Definition: parsenodes.h:2975
void ExecuteGrantStmt(GrantStmt *stmt)
Definition: aclchk.c:385
char * conditionname
Definition: parsenodes.h:2951
Oid AlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt)
Definition: tablespace.c:988

◆ UtilityContainsQuery()

Query* UtilityContainsQuery ( Node parsetree)

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

1885 {
1886  Query *qry;
1887 
1888  switch (nodeTag(parsetree))
1889  {
1890  case T_DeclareCursorStmt:
1891  qry = castNode(Query, ((DeclareCursorStmt *) parsetree)->query);
1892  if (qry->commandType == CMD_UTILITY)
1893  return UtilityContainsQuery(qry->utilityStmt);
1894  return qry;
1895 
1896  case T_ExplainStmt:
1897  qry = castNode(Query, ((ExplainStmt *) parsetree)->query);
1898  if (qry->commandType == CMD_UTILITY)
1899  return UtilityContainsQuery(qry->utilityStmt);
1900  return qry;
1901 
1902  case T_CreateTableAsStmt:
1903  qry = castNode(Query, ((CreateTableAsStmt *) parsetree)->query);
1904  if (qry->commandType == CMD_UTILITY)
1905  return UtilityContainsQuery(qry->utilityStmt);
1906  return qry;
1907 
1908  default:
1909  return NULL;
1910  }
1911 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:586
Node * utilityStmt
Definition: parsenodes.h:120
Query * UtilityContainsQuery(Node *parsetree)
Definition: utility.c:1884
CmdType commandType
Definition: parsenodes.h:112
#define nodeTag(nodeptr)
Definition: nodes.h:522

◆ UtilityReturnsTuples()

bool UtilityReturnsTuples ( Node parsetree)

Definition at line 1743 of file utility.c.

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

Referenced by ChoosePortalStrategy(), and UtilityTupleDescriptor().

1744 {
1745  switch (nodeTag(parsetree))
1746  {
1747  case T_FetchStmt:
1748  {
1749  FetchStmt *stmt = (FetchStmt *) parsetree;
1750  Portal portal;
1751 
1752  if (stmt->ismove)
1753  return false;
1754  portal = GetPortalByName(stmt->portalname);
1755  if (!PortalIsValid(portal))
1756  return false; /* not our business to raise error */
1757  return portal->tupDesc ? true : false;
1758  }
1759 
1760  case T_ExecuteStmt:
1761  {
1762  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1763  PreparedStatement *entry;
1764 
1765  entry = FetchPreparedStatement(stmt->name, false);
1766  if (!entry)
1767  return false; /* not our business to raise error */
1768  if (entry->plansource->resultDesc)
1769  return true;
1770  return false;
1771  }
1772 
1773  case T_ExplainStmt:
1774  return true;
1775 
1776  case T_VariableShowStmt:
1777  return true;
1778 
1779  default:
1780  return false;
1781  }
1782 }
CachedPlanSource * plansource
Definition: prepare.h:31
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
TupleDesc resultDesc
Definition: plancache.h:92
#define true
Definition: c.h:279
char * portalname
Definition: parsenodes.h:2695
#define PortalIsValid(p)
Definition: portal.h:201
bool ismove
Definition: parsenodes.h:2696
TupleDesc tupDesc
Definition: portal.h:157
#define nodeTag(nodeptr)
Definition: nodes.h:522
char * name
Definition: parsenodes.h:3356
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:495

◆ UtilityTupleDescriptor()

TupleDesc UtilityTupleDescriptor ( Node parsetree)

Definition at line 1793 of file utility.c.

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

Referenced by PlanCacheComputeResultDesc(), and PortalStart().

1794 {
1795  switch (nodeTag(parsetree))
1796  {
1797  case T_FetchStmt:
1798  {
1799  FetchStmt *stmt = (FetchStmt *) parsetree;
1800  Portal portal;
1801 
1802  if (stmt->ismove)
1803  return NULL;
1804  portal = GetPortalByName(stmt->portalname);
1805  if (!PortalIsValid(portal))
1806  return NULL; /* not our business to raise error */
1807  return CreateTupleDescCopy(portal->tupDesc);
1808  }
1809 
1810  case T_ExecuteStmt:
1811  {
1812  ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1813  PreparedStatement *entry;
1814 
1815  entry = FetchPreparedStatement(stmt->name, false);
1816  if (!entry)
1817  return NULL; /* not our business to raise error */
1818  return FetchPreparedStatementResultDesc(entry);
1819  }
1820 
1821  case T_ExplainStmt:
1822  return ExplainResultDesc((ExplainStmt *) parsetree);
1823 
1824  case T_VariableShowStmt:
1825  {
1826  VariableShowStmt *n = (VariableShowStmt *) parsetree;
1827 
1828  return GetPGVariableResultDesc(n->name);
1829  }
1830 
1831  default:
1832  return NULL;
1833  }
1834 }
TupleDesc GetPGVariableResultDesc(const char *name)
Definition: guc.c:8180
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:112
Portal GetPortalByName(const char *name)
Definition: portalmem.c:130
TupleDesc ExplainResultDesc(ExplainStmt *stmt)
Definition: explain.c:300
char * portalname
Definition: parsenodes.h:2695
#define PortalIsValid(p)
Definition: portal.h:201
bool ismove
Definition: parsenodes.h:2696
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Definition: prepare.c:527
TupleDesc tupDesc
Definition: portal.h:157
#define nodeTag(nodeptr)
Definition: nodes.h:522
char * name
Definition: parsenodes.h:3356
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Definition: prepare.c:495

Variable Documentation

◆ ProcessUtility_hook

Definition at line 76 of file utility.c.

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