1 /*-------------------------------------------------------------------------
4 * Contains functions which control the execution of the POSTGRES utility
5 * commands. At one time acted as an interface between the Lisp and C
8 * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
13 * src/backend/tcop/utility.c
15 *-------------------------------------------------------------------------
19 #include "access/reloptions.h"
20 #include "access/twophase.h"
21 #include "access/xact.h"
22 #include "catalog/catalog.h"
23 #include "catalog/namespace.h"
24 #include "catalog/toasting.h"
25 #include "commands/alter.h"
26 #include "commands/async.h"
27 #include "commands/cluster.h"
28 #include "commands/comment.h"
29 #include "commands/conversioncmds.h"
30 #include "commands/copy.h"
31 #include "commands/dbcommands.h"
32 #include "commands/defrem.h"
33 #include "commands/discard.h"
34 #include "commands/explain.h"
35 #include "commands/lockcmds.h"
36 #include "commands/portalcmds.h"
37 #include "commands/prepare.h"
38 #include "commands/proclang.h"
39 #include "commands/schemacmds.h"
40 #include "commands/seclabel.h"
41 #include "commands/sequence.h"
42 #include "commands/tablecmds.h"
43 #include "commands/tablespace.h"
44 #include "commands/trigger.h"
45 #include "commands/typecmds.h"
46 #include "commands/user.h"
47 #include "commands/vacuum.h"
48 #include "commands/view.h"
49 #include "miscadmin.h"
50 #include "parser/parse_utilcmd.h"
51 #include "postmaster/bgwriter.h"
52 #include "rewrite/rewriteDefine.h"
53 #include "rewrite/rewriteRemove.h"
54 #include "storage/fd.h"
55 #include "tcop/pquery.h"
56 #include "tcop/utility.h"
57 #include "utils/acl.h"
58 #include "utils/guc.h"
59 #include "utils/syscache.h"
62 /* Hook for plugins to get control in ProcessUtility() */
63 ProcessUtility_hook_type ProcessUtility_hook = NULL;
67 * Verify user has ownership of specified relation, else ereport.
69 * If noCatalogs is true then we also deny access to system catalogs,
70 * except when allowSystemTableMods is true.
73 CheckRelationOwnership(RangeVar *rel, bool noCatalogs)
78 relOid = RangeVarGetRelid(rel, false);
79 tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relOid));
80 if (!HeapTupleIsValid(tuple)) /* should not happen */
81 elog(ERROR, "cache lookup failed for relation %u", relOid);
83 if (!pg_class_ownercheck(relOid, GetUserId()))
84 aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
89 if (!allowSystemTableMods &&
90 IsSystemClass((Form_pg_class) GETSTRUCT(tuple)))
92 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
93 errmsg("permission denied: \"%s\" is a system catalog",
97 ReleaseSysCache(tuple);
102 * CommandIsReadOnly: is an executable query read-only?
104 * This is a much stricter test than we apply for XactReadOnly mode;
105 * the query must be *in truth* read-only, because the caller wishes
106 * not to do CommandCounterIncrement for it.
108 * Note: currently no need to support Query nodes here
111 CommandIsReadOnly(Node *parsetree)
113 if (IsA(parsetree, PlannedStmt))
115 PlannedStmt *stmt = (PlannedStmt *) parsetree;
117 switch (stmt->commandType)
120 if (stmt->intoClause != NULL)
121 return false; /* SELECT INTO */
122 else if (stmt->rowMarks != NIL)
123 return false; /* SELECT FOR UPDATE/SHARE */
131 elog(WARNING, "unrecognized commandType: %d",
132 (int) stmt->commandType);
136 /* For now, treat all utility commands as read/write */
141 * check_xact_readonly: is a utility command read-only?
143 * Here we use the loose rules of XactReadOnly mode: no permanent effects
144 * on the database are allowed.
147 check_xact_readonly(Node *parsetree)
153 * Note: Commands that need to do more complicated checking are handled
154 * elsewhere, in particular COPY and plannable statements do their own
155 * checking. However they should all call PreventCommandIfReadOnly to
156 * actually throw the error.
159 switch (nodeTag(parsetree))
161 case T_AlterDatabaseStmt:
162 case T_AlterDatabaseSetStmt:
163 case T_AlterDomainStmt:
164 case T_AlterFunctionStmt:
165 case T_AlterRoleStmt:
166 case T_AlterRoleSetStmt:
167 case T_AlterObjectSchemaStmt:
168 case T_AlterOwnerStmt:
170 case T_AlterTableStmt:
174 case T_CreateCastStmt:
175 case T_CreateConversionStmt:
177 case T_CreateDomainStmt:
178 case T_CreateFunctionStmt:
179 case T_CreateRoleStmt:
181 case T_CreatePLangStmt:
182 case T_CreateOpClassStmt:
183 case T_CreateOpFamilyStmt:
184 case T_AlterOpFamilyStmt:
186 case T_CreateSchemaStmt:
187 case T_CreateSeqStmt:
189 case T_CreateTableSpaceStmt:
190 case T_CreateTrigStmt:
191 case T_CompositeTypeStmt:
192 case T_CreateEnumStmt:
197 case T_DropTableSpaceStmt:
198 case T_RemoveFuncStmt:
200 case T_DropPLangStmt:
201 case T_RemoveOpClassStmt:
202 case T_RemoveOpFamilyStmt:
203 case T_DropPropertyStmt:
205 case T_GrantRoleStmt:
206 case T_AlterDefaultPrivilegesStmt:
208 case T_DropOwnedStmt:
209 case T_ReassignOwnedStmt:
210 case T_AlterTSDictionaryStmt:
211 case T_AlterTSConfigurationStmt:
212 case T_CreateFdwStmt:
215 case T_CreateForeignServerStmt:
216 case T_AlterForeignServerStmt:
217 case T_DropForeignServerStmt:
218 case T_CreateUserMappingStmt:
219 case T_AlterUserMappingStmt:
220 case T_DropUserMappingStmt:
221 case T_AlterTableSpaceOptionsStmt:
223 PreventCommandIfReadOnly(CreateCommandTag(parsetree));
232 * PreventCommandIfReadOnly: throw error if XactReadOnly
234 * This is useful mainly to ensure consistency of the error message wording;
235 * most callers have checked XactReadOnly for themselves.
238 PreventCommandIfReadOnly(const char *cmdname)
242 (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
243 /* translator: %s is name of a SQL command, eg CREATE */
244 errmsg("cannot execute %s in a read-only transaction",
249 * PreventCommandDuringRecovery: throw error if RecoveryInProgress
251 * The majority of operations that are unsafe in a Hot Standby slave
252 * will be rejected by XactReadOnly tests. However there are a few
253 * commands that are allowed in "read-only" xacts but cannot be allowed
254 * in Hot Standby mode. Those commands should call this function.
257 PreventCommandDuringRecovery(const char *cmdname)
259 if (RecoveryInProgress())
261 (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
262 /* translator: %s is name of a SQL command, eg CREATE */
263 errmsg("cannot execute %s during recovery",
268 * CheckRestrictedOperation: throw error for hazardous command if we're
269 * inside a security restriction context.
271 * This is needed to protect session-local state for which there is not any
272 * better-defined protection mechanism, such as ownership.
275 CheckRestrictedOperation(const char *cmdname)
277 if (InSecurityRestrictedOperation())
279 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
280 /* translator: %s is name of a SQL command, eg PREPARE */
281 errmsg("cannot execute %s within security-restricted operation",
288 * general utility function invoker
290 * parsetree: the parse tree for the utility statement
291 * queryString: original source text of command
292 * params: parameters to use during execution
293 * isTopLevel: true if executing a "top level" (interactively issued) command
294 * dest: where to send results
295 * completionTag: points to a buffer of size COMPLETION_TAG_BUFSIZE
296 * in which to store a command completion status string.
298 * Notes: as of PG 8.4, caller MUST supply a queryString; it is not
299 * allowed anymore to pass NULL. (If you really don't have source text,
300 * you can pass a constant string, perhaps "(query not available)".)
302 * completionTag is only set nonempty if we want to return a nondefault status.
304 * completionTag may be NULL if caller doesn't want a status string.
307 ProcessUtility(Node *parsetree,
308 const char *queryString,
309 ParamListInfo params,
314 Assert(queryString != NULL); /* required as of 8.4 */
317 * We provide a function hook variable that lets loadable plugins get
318 * control when ProcessUtility is called. Such a plugin would normally
319 * call standard_ProcessUtility().
321 if (ProcessUtility_hook)
322 (*ProcessUtility_hook) (parsetree, queryString, params,
323 isTopLevel, dest, completionTag);
325 standard_ProcessUtility(parsetree, queryString, params,
326 isTopLevel, dest, completionTag);
330 standard_ProcessUtility(Node *parsetree,
331 const char *queryString,
332 ParamListInfo params,
337 check_xact_readonly(parsetree);
340 completionTag[0] = '\0';
342 switch (nodeTag(parsetree))
345 * ******************** transactions ********************
347 case T_TransactionStmt:
349 TransactionStmt *stmt = (TransactionStmt *) parsetree;
354 * START TRANSACTION, as defined by SQL99: Identical
355 * to BEGIN. Same code for both.
357 case TRANS_STMT_BEGIN:
358 case TRANS_STMT_START:
362 BeginTransactionBlock();
363 foreach(lc, stmt->options)
365 DefElem *item = (DefElem *) lfirst(lc);
367 if (strcmp(item->defname, "transaction_isolation") == 0)
368 SetPGVariable("transaction_isolation",
369 list_make1(item->arg),
371 else if (strcmp(item->defname, "transaction_read_only") == 0)
372 SetPGVariable("transaction_read_only",
373 list_make1(item->arg),
379 case TRANS_STMT_COMMIT:
380 if (!EndTransactionBlock())
382 /* report unsuccessful commit in completionTag */
384 strcpy(completionTag, "ROLLBACK");
388 case TRANS_STMT_PREPARE:
389 PreventCommandDuringRecovery("PREPARE TRANSACTION");
390 if (!PrepareTransactionBlock(stmt->gid))
392 /* report unsuccessful commit in completionTag */
394 strcpy(completionTag, "ROLLBACK");
398 case TRANS_STMT_COMMIT_PREPARED:
399 PreventTransactionChain(isTopLevel, "COMMIT PREPARED");
400 PreventCommandDuringRecovery("COMMIT PREPARED");
401 FinishPreparedTransaction(stmt->gid, true);
404 case TRANS_STMT_ROLLBACK_PREPARED:
405 PreventTransactionChain(isTopLevel, "ROLLBACK PREPARED");
406 PreventCommandDuringRecovery("ROLLBACK PREPARED");
407 FinishPreparedTransaction(stmt->gid, false);
410 case TRANS_STMT_ROLLBACK:
411 UserAbortTransactionBlock();
414 case TRANS_STMT_SAVEPOINT:
419 RequireTransactionChain(isTopLevel, "SAVEPOINT");
421 foreach(cell, stmt->options)
423 DefElem *elem = lfirst(cell);
425 if (strcmp(elem->defname, "savepoint_name") == 0)
426 name = strVal(elem->arg);
429 Assert(PointerIsValid(name));
431 DefineSavepoint(name);
435 case TRANS_STMT_RELEASE:
436 RequireTransactionChain(isTopLevel, "RELEASE SAVEPOINT");
437 ReleaseSavepoint(stmt->options);
440 case TRANS_STMT_ROLLBACK_TO:
441 RequireTransactionChain(isTopLevel, "ROLLBACK TO SAVEPOINT");
442 RollbackToSavepoint(stmt->options);
445 * CommitTransactionCommand is in charge of
446 * re-defining the savepoint again
454 * Portal (cursor) manipulation
456 * Note: DECLARE CURSOR is processed mostly as a SELECT, and
457 * therefore what we will get here is a PlannedStmt not a bare
462 PlannedStmt *stmt = (PlannedStmt *) parsetree;
464 if (stmt->utilityStmt == NULL ||
465 !IsA(stmt->utilityStmt, DeclareCursorStmt))
466 elog(ERROR, "non-DECLARE CURSOR PlannedStmt passed to ProcessUtility");
467 PerformCursorOpen(stmt, params, queryString, isTopLevel);
471 case T_ClosePortalStmt:
473 ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
475 CheckRestrictedOperation("CLOSE");
476 PerformPortalClose(stmt->portalname);
481 PerformPortalFetch((FetchStmt *) parsetree, dest,
486 * relation and attribute manipulation
488 case T_CreateSchemaStmt:
489 CreateSchemaCommand((CreateSchemaStmt *) parsetree,
499 /* Run parse analysis ... */
500 stmts = transformCreateStmt((CreateStmt *) parsetree,
506 Node *stmt = (Node *) lfirst(l);
508 if (IsA(stmt, CreateStmt))
511 static char *validnsps[] = HEAP_RELOPT_NAMESPACES;
513 /* Create the table itself */
514 relOid = DefineRelation((CreateStmt *) stmt,
519 * If "IF NOT EXISTS" was specified and the relation
520 * already exists, do nothing further.
522 if (relOid == InvalidOid)
526 * Let AlterTableCreateToastTable decide if this one
527 * needs a secondary relation too.
529 CommandCounterIncrement();
531 /* parse and validate reloptions for the toast table */
532 toast_options = transformRelOptions((Datum) 0,
533 ((CreateStmt *) stmt)->options,
537 (void) heap_reloptions(RELKIND_TOASTVALUE, toast_options,
540 AlterTableCreateToastTable(relOid, toast_options);
544 /* Recurse for anything else */
553 /* Need CCI between commands */
554 if (lnext(l) != NULL)
555 CommandCounterIncrement();
560 case T_CreateTableSpaceStmt:
561 PreventTransactionChain(isTopLevel, "CREATE TABLESPACE");
562 CreateTableSpace((CreateTableSpaceStmt *) parsetree);
565 case T_DropTableSpaceStmt:
566 PreventTransactionChain(isTopLevel, "DROP TABLESPACE");
567 DropTableSpace((DropTableSpaceStmt *) parsetree);
570 case T_AlterTableSpaceOptionsStmt:
571 AlterTableSpaceOptions((AlterTableSpaceOptionsStmt *) parsetree);
574 case T_CreateFdwStmt:
575 CreateForeignDataWrapper((CreateFdwStmt *) parsetree);
579 AlterForeignDataWrapper((AlterFdwStmt *) parsetree);
583 RemoveForeignDataWrapper((DropFdwStmt *) parsetree);
586 case T_CreateForeignServerStmt:
587 CreateForeignServer((CreateForeignServerStmt *) parsetree);
590 case T_AlterForeignServerStmt:
591 AlterForeignServer((AlterForeignServerStmt *) parsetree);
594 case T_DropForeignServerStmt:
595 RemoveForeignServer((DropForeignServerStmt *) parsetree);
598 case T_CreateUserMappingStmt:
599 CreateUserMapping((CreateUserMappingStmt *) parsetree);
602 case T_AlterUserMappingStmt:
603 AlterUserMapping((AlterUserMappingStmt *) parsetree);
606 case T_DropUserMappingStmt:
607 RemoveUserMapping((DropUserMappingStmt *) parsetree);
612 DropStmt *stmt = (DropStmt *) parsetree;
614 switch (stmt->removeType)
617 case OBJECT_SEQUENCE:
620 RemoveRelations(stmt);
628 case OBJECT_CONVERSION:
629 DropConversionsCommand(stmt);
636 case OBJECT_TSPARSER:
637 RemoveTSParsers(stmt);
640 case OBJECT_TSDICTIONARY:
641 RemoveTSDictionaries(stmt);
644 case OBJECT_TSTEMPLATE:
645 RemoveTSTemplates(stmt);
648 case OBJECT_TSCONFIGURATION:
649 RemoveTSConfigurations(stmt);
653 elog(ERROR, "unrecognized drop object type: %d",
654 (int) stmt->removeType);
661 ExecuteTruncate((TruncateStmt *) parsetree);
665 CommentObject((CommentStmt *) parsetree);
669 ExecSecLabelStmt((SecLabelStmt *) parsetree);
676 processed = DoCopy((CopyStmt *) parsetree, queryString);
678 snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
679 "COPY " UINT64_FORMAT, processed);
684 CheckRestrictedOperation("PREPARE");
685 PrepareQuery((PrepareStmt *) parsetree, queryString);
689 ExecuteQuery((ExecuteStmt *) parsetree, queryString, params,
690 dest, completionTag);
693 case T_DeallocateStmt:
694 CheckRestrictedOperation("DEALLOCATE");
695 DeallocateQuery((DeallocateStmt *) parsetree);
702 ExecRenameStmt((RenameStmt *) parsetree);
705 case T_AlterObjectSchemaStmt:
706 ExecAlterObjectSchemaStmt((AlterObjectSchemaStmt *) parsetree);
709 case T_AlterOwnerStmt:
710 ExecAlterOwnerStmt((AlterOwnerStmt *) parsetree);
713 case T_AlterTableStmt:
718 /* Run parse analysis ... */
719 stmts = transformAlterTableStmt((AlterTableStmt *) parsetree,
725 Node *stmt = (Node *) lfirst(l);
727 if (IsA(stmt, AlterTableStmt))
729 /* Do the table alteration proper */
730 AlterTable((AlterTableStmt *) stmt);
734 /* Recurse for anything else */
743 /* Need CCI between commands */
744 if (lnext(l) != NULL)
745 CommandCounterIncrement();
750 case T_AlterDomainStmt:
752 AlterDomainStmt *stmt = (AlterDomainStmt *) parsetree;
755 * Some or all of these functions are recursive to cover
756 * inherited things, so permission checks are done there.
758 switch (stmt->subtype)
760 case 'T': /* ALTER DOMAIN DEFAULT */
763 * Recursively alter column default for table and, if
764 * requested, for descendants
766 AlterDomainDefault(stmt->typeName,
769 case 'N': /* ALTER DOMAIN DROP NOT NULL */
770 AlterDomainNotNull(stmt->typeName,
773 case 'O': /* ALTER DOMAIN SET NOT NULL */
774 AlterDomainNotNull(stmt->typeName,
777 case 'C': /* ADD CONSTRAINT */
778 AlterDomainAddConstraint(stmt->typeName,
781 case 'X': /* DROP CONSTRAINT */
782 AlterDomainDropConstraint(stmt->typeName,
787 elog(ERROR, "unrecognized alter domain type: %d",
788 (int) stmt->subtype);
795 ExecuteGrantStmt((GrantStmt *) parsetree);
798 case T_GrantRoleStmt:
799 GrantRole((GrantRoleStmt *) parsetree);
802 case T_AlterDefaultPrivilegesStmt:
803 ExecAlterDefaultPrivilegesStmt((AlterDefaultPrivilegesStmt *) parsetree);
807 * **************** object creation / destruction *****************
811 DefineStmt *stmt = (DefineStmt *) parsetree;
815 case OBJECT_AGGREGATE:
816 DefineAggregate(stmt->defnames, stmt->args,
817 stmt->oldstyle, stmt->definition);
819 case OBJECT_OPERATOR:
820 Assert(stmt->args == NIL);
821 DefineOperator(stmt->defnames, stmt->definition);
824 Assert(stmt->args == NIL);
825 DefineType(stmt->defnames, stmt->definition);
827 case OBJECT_TSPARSER:
828 Assert(stmt->args == NIL);
829 DefineTSParser(stmt->defnames, stmt->definition);
831 case OBJECT_TSDICTIONARY:
832 Assert(stmt->args == NIL);
833 DefineTSDictionary(stmt->defnames, stmt->definition);
835 case OBJECT_TSTEMPLATE:
836 Assert(stmt->args == NIL);
837 DefineTSTemplate(stmt->defnames, stmt->definition);
839 case OBJECT_TSCONFIGURATION:
840 Assert(stmt->args == NIL);
841 DefineTSConfiguration(stmt->defnames, stmt->definition);
844 elog(ERROR, "unrecognized define stmt type: %d",
851 case T_CompositeTypeStmt: /* CREATE TYPE (composite) */
853 CompositeTypeStmt *stmt = (CompositeTypeStmt *) parsetree;
855 DefineCompositeType(stmt->typevar, stmt->coldeflist);
859 case T_CreateEnumStmt: /* CREATE TYPE (enum) */
860 DefineEnum((CreateEnumStmt *) parsetree);
863 case T_ViewStmt: /* CREATE VIEW */
864 DefineView((ViewStmt *) parsetree, queryString);
867 case T_CreateFunctionStmt: /* CREATE FUNCTION */
868 CreateFunction((CreateFunctionStmt *) parsetree, queryString);
871 case T_AlterFunctionStmt: /* ALTER FUNCTION */
872 AlterFunction((AlterFunctionStmt *) parsetree);
875 case T_IndexStmt: /* CREATE INDEX */
877 IndexStmt *stmt = (IndexStmt *) parsetree;
879 if (stmt->concurrent)
880 PreventTransactionChain(isTopLevel,
881 "CREATE INDEX CONCURRENTLY");
883 CheckRelationOwnership(stmt->relation, true);
885 /* Run parse analysis ... */
886 stmt = transformIndexStmt(stmt, queryString);
889 DefineIndex(stmt->relation, /* relation */
890 stmt->idxname, /* index name */
891 InvalidOid, /* no predefined OID */
892 stmt->accessMethod, /* am name */
894 stmt->indexParams, /* parameters */
895 (Expr *) stmt->whereClause,
897 stmt->excludeOpNames,
903 false, /* is_alter_table */
904 true, /* check_rights */
905 false, /* skip_build */
907 stmt->concurrent); /* concurrent */
911 case T_RuleStmt: /* CREATE RULE */
912 DefineRule((RuleStmt *) parsetree, queryString);
915 case T_CreateSeqStmt:
916 DefineSequence((CreateSeqStmt *) parsetree);
920 AlterSequence((AlterSeqStmt *) parsetree);
923 case T_RemoveFuncStmt:
925 RemoveFuncStmt *stmt = (RemoveFuncStmt *) parsetree;
929 case OBJECT_FUNCTION:
930 RemoveFunction(stmt);
932 case OBJECT_AGGREGATE:
933 RemoveAggregate(stmt);
935 case OBJECT_OPERATOR:
936 RemoveOperator(stmt);
939 elog(ERROR, "unrecognized object type: %d",
947 ExecuteDoStmt((DoStmt *) parsetree);
951 PreventTransactionChain(isTopLevel, "CREATE DATABASE");
952 createdb((CreatedbStmt *) parsetree);
955 case T_AlterDatabaseStmt:
956 AlterDatabase((AlterDatabaseStmt *) parsetree, isTopLevel);
959 case T_AlterDatabaseSetStmt:
960 AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
965 DropdbStmt *stmt = (DropdbStmt *) parsetree;
967 PreventTransactionChain(isTopLevel, "DROP DATABASE");
968 dropdb(stmt->dbname, stmt->missing_ok);
972 /* Query-level asynchronous notification */
975 NotifyStmt *stmt = (NotifyStmt *) parsetree;
977 PreventCommandDuringRecovery("NOTIFY");
978 Async_Notify(stmt->conditionname, stmt->payload);
984 ListenStmt *stmt = (ListenStmt *) parsetree;
986 PreventCommandDuringRecovery("LISTEN");
987 CheckRestrictedOperation("LISTEN");
988 Async_Listen(stmt->conditionname);
994 UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
996 PreventCommandDuringRecovery("UNLISTEN");
997 CheckRestrictedOperation("UNLISTEN");
998 if (stmt->conditionname)
999 Async_Unlisten(stmt->conditionname);
1001 Async_UnlistenAll();
1007 LoadStmt *stmt = (LoadStmt *) parsetree;
1009 closeAllVfds(); /* probably not necessary... */
1010 /* Allowed names are restricted if you're not superuser */
1011 load_file(stmt->filename, !superuser());
1016 /* we choose to allow this during "read only" transactions */
1017 PreventCommandDuringRecovery("CLUSTER");
1018 cluster((ClusterStmt *) parsetree, isTopLevel);
1022 /* we choose to allow this during "read only" transactions */
1023 PreventCommandDuringRecovery("VACUUM");
1024 vacuum((VacuumStmt *) parsetree, InvalidOid, true, NULL, false,
1029 ExplainQuery((ExplainStmt *) parsetree, queryString, params, dest);
1032 case T_VariableSetStmt:
1033 ExecSetVariableStmt((VariableSetStmt *) parsetree);
1036 case T_VariableShowStmt:
1038 VariableShowStmt *n = (VariableShowStmt *) parsetree;
1040 GetPGVariable(n->name, dest);
1045 /* should we allow DISCARD PLANS? */
1046 CheckRestrictedOperation("DISCARD");
1047 DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
1050 case T_CreateTrigStmt:
1051 (void) CreateTrigger((CreateTrigStmt *) parsetree, queryString,
1052 InvalidOid, InvalidOid, false);
1055 case T_DropPropertyStmt:
1057 DropPropertyStmt *stmt = (DropPropertyStmt *) parsetree;
1060 relId = RangeVarGetRelid(stmt->relation, false);
1062 switch (stmt->removeType)
1065 /* RemoveRewriteRule checks permissions */
1066 RemoveRewriteRule(relId, stmt->property,
1067 stmt->behavior, stmt->missing_ok);
1069 case OBJECT_TRIGGER:
1070 /* DropTrigger checks permissions */
1071 DropTrigger(relId, stmt->property,
1072 stmt->behavior, stmt->missing_ok);
1075 elog(ERROR, "unrecognized object type: %d",
1076 (int) stmt->removeType);
1082 case T_CreatePLangStmt:
1083 CreateProceduralLanguage((CreatePLangStmt *) parsetree);
1086 case T_DropPLangStmt:
1087 DropProceduralLanguage((DropPLangStmt *) parsetree);
1091 * ******************************** DOMAIN statements ****
1093 case T_CreateDomainStmt:
1094 DefineDomain((CreateDomainStmt *) parsetree);
1098 * ******************************** ROLE statements ****
1100 case T_CreateRoleStmt:
1101 CreateRole((CreateRoleStmt *) parsetree);
1104 case T_AlterRoleStmt:
1105 AlterRole((AlterRoleStmt *) parsetree);
1108 case T_AlterRoleSetStmt:
1109 AlterRoleSet((AlterRoleSetStmt *) parsetree);
1112 case T_DropRoleStmt:
1113 DropRole((DropRoleStmt *) parsetree);
1116 case T_DropOwnedStmt:
1117 DropOwnedObjects((DropOwnedStmt *) parsetree);
1120 case T_ReassignOwnedStmt:
1121 ReassignOwnedObjects((ReassignOwnedStmt *) parsetree);
1127 * Since the lock would just get dropped immediately, LOCK TABLE
1128 * outside a transaction block is presumed to be user error.
1130 RequireTransactionChain(isTopLevel, "LOCK TABLE");
1131 LockTableCommand((LockStmt *) parsetree);
1134 case T_ConstraintsSetStmt:
1135 AfterTriggerSetState((ConstraintsSetStmt *) parsetree);
1138 case T_CheckPointStmt:
1141 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1142 errmsg("must be superuser to do CHECKPOINT")));
1145 * You might think we should have a PreventCommandDuringRecovery()
1146 * here, but we interpret a CHECKPOINT command during recovery as
1147 * a request for a restartpoint instead. We allow this since it
1148 * can be a useful way of reducing switchover time when using
1149 * various forms of replication.
1151 RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_WAIT |
1152 (RecoveryInProgress() ? 0 : CHECKPOINT_FORCE));
1157 ReindexStmt *stmt = (ReindexStmt *) parsetree;
1159 /* we choose to allow this during "read only" transactions */
1160 PreventCommandDuringRecovery("REINDEX");
1164 ReindexIndex(stmt->relation);
1167 ReindexTable(stmt->relation);
1169 case OBJECT_DATABASE:
1172 * This cannot run inside a user transaction block; if
1173 * we were inside a transaction, then its commit- and
1174 * start-transaction-command calls would not have the
1177 PreventTransactionChain(isTopLevel,
1178 "REINDEX DATABASE");
1179 ReindexDatabase(stmt->name,
1180 stmt->do_system, stmt->do_user);
1183 elog(ERROR, "unrecognized object type: %d",
1191 case T_CreateConversionStmt:
1192 CreateConversionCommand((CreateConversionStmt *) parsetree);
1195 case T_CreateCastStmt:
1196 CreateCast((CreateCastStmt *) parsetree);
1199 case T_DropCastStmt:
1200 DropCast((DropCastStmt *) parsetree);
1203 case T_CreateOpClassStmt:
1204 DefineOpClass((CreateOpClassStmt *) parsetree);
1207 case T_CreateOpFamilyStmt:
1208 DefineOpFamily((CreateOpFamilyStmt *) parsetree);
1211 case T_AlterOpFamilyStmt:
1212 AlterOpFamily((AlterOpFamilyStmt *) parsetree);
1215 case T_RemoveOpClassStmt:
1216 RemoveOpClass((RemoveOpClassStmt *) parsetree);
1219 case T_RemoveOpFamilyStmt:
1220 RemoveOpFamily((RemoveOpFamilyStmt *) parsetree);
1223 case T_AlterTSDictionaryStmt:
1224 AlterTSDictionary((AlterTSDictionaryStmt *) parsetree);
1227 case T_AlterTSConfigurationStmt:
1228 AlterTSConfiguration((AlterTSConfigurationStmt *) parsetree);
1232 elog(ERROR, "unrecognized node type: %d",
1233 (int) nodeTag(parsetree));
1239 * UtilityReturnsTuples
1240 * Return "true" if this utility statement will send output to the
1243 * Generally, there should be a case here for each case in ProcessUtility
1244 * where "dest" is passed on.
1247 UtilityReturnsTuples(Node *parsetree)
1249 switch (nodeTag(parsetree))
1253 FetchStmt *stmt = (FetchStmt *) parsetree;
1258 portal = GetPortalByName(stmt->portalname);
1259 if (!PortalIsValid(portal))
1260 return false; /* not our business to raise error */
1261 return portal->tupDesc ? true : false;
1266 ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1267 PreparedStatement *entry;
1271 entry = FetchPreparedStatement(stmt->name, false);
1273 return false; /* not our business to raise error */
1274 if (entry->plansource->resultDesc)
1282 case T_VariableShowStmt:
1291 * UtilityTupleDescriptor
1292 * Fetch the actual output tuple descriptor for a utility statement
1293 * for which UtilityReturnsTuples() previously returned "true".
1295 * The returned descriptor is created in (or copied into) the current memory
1299 UtilityTupleDescriptor(Node *parsetree)
1301 switch (nodeTag(parsetree))
1305 FetchStmt *stmt = (FetchStmt *) parsetree;
1310 portal = GetPortalByName(stmt->portalname);
1311 if (!PortalIsValid(portal))
1312 return NULL; /* not our business to raise error */
1313 return CreateTupleDescCopy(portal->tupDesc);
1318 ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
1319 PreparedStatement *entry;
1323 entry = FetchPreparedStatement(stmt->name, false);
1325 return NULL; /* not our business to raise error */
1326 return FetchPreparedStatementResultDesc(entry);
1330 return ExplainResultDesc((ExplainStmt *) parsetree);
1332 case T_VariableShowStmt:
1334 VariableShowStmt *n = (VariableShowStmt *) parsetree;
1336 return GetPGVariableResultDesc(n->name);
1346 * QueryReturnsTuples
1347 * Return "true" if this Query will send output to the destination.
1351 QueryReturnsTuples(Query *parsetree)
1353 switch (parsetree->commandType)
1356 /* returns tuples ... unless it's DECLARE CURSOR or SELECT INTO */
1357 if (parsetree->utilityStmt == NULL &&
1358 parsetree->intoClause == NULL)
1364 /* the forms with RETURNING return tuples */
1365 if (parsetree->returningList)
1369 return UtilityReturnsTuples(parsetree->utilityStmt);
1372 /* probably shouldn't get here */
1375 return false; /* default */
1382 * utility to get a string representation of the command operation,
1383 * given either a raw (un-analyzed) parsetree or a planned query.
1385 * This must handle all command types, but since the vast majority
1386 * of 'em are utility commands, it seems sensible to keep it here.
1388 * NB: all result strings must be shorter than COMPLETION_TAG_BUFSIZE.
1389 * Also, the result must point at a true constant (permanent storage).
1392 CreateCommandTag(Node *parsetree)
1396 switch (nodeTag(parsetree))
1398 /* raw plannable queries */
1415 /* utility statements --- same whether raw or cooked */
1416 case T_TransactionStmt:
1418 TransactionStmt *stmt = (TransactionStmt *) parsetree;
1422 case TRANS_STMT_BEGIN:
1426 case TRANS_STMT_START:
1427 tag = "START TRANSACTION";
1430 case TRANS_STMT_COMMIT:
1434 case TRANS_STMT_ROLLBACK:
1435 case TRANS_STMT_ROLLBACK_TO:
1439 case TRANS_STMT_SAVEPOINT:
1443 case TRANS_STMT_RELEASE:
1447 case TRANS_STMT_PREPARE:
1448 tag = "PREPARE TRANSACTION";
1451 case TRANS_STMT_COMMIT_PREPARED:
1452 tag = "COMMIT PREPARED";
1455 case TRANS_STMT_ROLLBACK_PREPARED:
1456 tag = "ROLLBACK PREPARED";
1466 case T_DeclareCursorStmt:
1467 tag = "DECLARE CURSOR";
1470 case T_ClosePortalStmt:
1472 ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
1474 if (stmt->portalname == NULL)
1475 tag = "CLOSE CURSOR ALL";
1477 tag = "CLOSE CURSOR";
1483 FetchStmt *stmt = (FetchStmt *) parsetree;
1485 tag = (stmt->ismove) ? "MOVE" : "FETCH";
1489 case T_CreateDomainStmt:
1490 tag = "CREATE DOMAIN";
1493 case T_CreateSchemaStmt:
1494 tag = "CREATE SCHEMA";
1498 tag = "CREATE TABLE";
1501 case T_CreateTableSpaceStmt:
1502 tag = "CREATE TABLESPACE";
1505 case T_DropTableSpaceStmt:
1506 tag = "DROP TABLESPACE";
1509 case T_AlterTableSpaceOptionsStmt:
1510 tag = "ALTER TABLESPACE";
1513 case T_CreateFdwStmt:
1514 tag = "CREATE FOREIGN DATA WRAPPER";
1517 case T_AlterFdwStmt:
1518 tag = "ALTER FOREIGN DATA WRAPPER";
1522 tag = "DROP FOREIGN DATA WRAPPER";
1525 case T_CreateForeignServerStmt:
1526 tag = "CREATE SERVER";
1529 case T_AlterForeignServerStmt:
1530 tag = "ALTER SERVER";
1533 case T_DropForeignServerStmt:
1534 tag = "DROP SERVER";
1537 case T_CreateUserMappingStmt:
1538 tag = "CREATE USER MAPPING";
1541 case T_AlterUserMappingStmt:
1542 tag = "ALTER USER MAPPING";
1545 case T_DropUserMappingStmt:
1546 tag = "DROP USER MAPPING";
1550 switch (((DropStmt *) parsetree)->removeType)
1555 case OBJECT_SEQUENCE:
1556 tag = "DROP SEQUENCE";
1568 tag = "DROP DOMAIN";
1570 case OBJECT_CONVERSION:
1571 tag = "DROP CONVERSION";
1574 tag = "DROP SCHEMA";
1576 case OBJECT_TSPARSER:
1577 tag = "DROP TEXT SEARCH PARSER";
1579 case OBJECT_TSDICTIONARY:
1580 tag = "DROP TEXT SEARCH DICTIONARY";
1582 case OBJECT_TSTEMPLATE:
1583 tag = "DROP TEXT SEARCH TEMPLATE";
1585 case OBJECT_TSCONFIGURATION:
1586 tag = "DROP TEXT SEARCH CONFIGURATION";
1593 case T_TruncateStmt:
1594 tag = "TRUNCATE TABLE";
1601 case T_SecLabelStmt:
1602 tag = "SECURITY LABEL";
1610 switch (((RenameStmt *) parsetree)->renameType)
1612 case OBJECT_AGGREGATE:
1613 tag = "ALTER AGGREGATE";
1615 case OBJECT_CONVERSION:
1616 tag = "ALTER CONVERSION";
1618 case OBJECT_DATABASE:
1619 tag = "ALTER DATABASE";
1621 case OBJECT_FUNCTION:
1622 tag = "ALTER FUNCTION";
1625 tag = "ALTER INDEX";
1627 case OBJECT_LANGUAGE:
1628 tag = "ALTER LANGUAGE";
1630 case OBJECT_OPCLASS:
1631 tag = "ALTER OPERATOR CLASS";
1633 case OBJECT_OPFAMILY:
1634 tag = "ALTER OPERATOR FAMILY";
1640 tag = "ALTER SCHEMA";
1642 case OBJECT_SEQUENCE:
1643 tag = "ALTER SEQUENCE";
1647 tag = "ALTER TABLE";
1649 case OBJECT_TABLESPACE:
1650 tag = "ALTER TABLESPACE";
1652 case OBJECT_TRIGGER:
1653 tag = "ALTER TRIGGER";
1658 case OBJECT_TSPARSER:
1659 tag = "ALTER TEXT SEARCH PARSER";
1661 case OBJECT_TSDICTIONARY:
1662 tag = "ALTER TEXT SEARCH DICTIONARY";
1664 case OBJECT_TSTEMPLATE:
1665 tag = "ALTER TEXT SEARCH TEMPLATE";
1667 case OBJECT_TSCONFIGURATION:
1668 tag = "ALTER TEXT SEARCH CONFIGURATION";
1670 case OBJECT_ATTRIBUTE:
1680 case T_AlterObjectSchemaStmt:
1681 switch (((AlterObjectSchemaStmt *) parsetree)->objectType)
1683 case OBJECT_AGGREGATE:
1684 tag = "ALTER AGGREGATE";
1687 tag = "ALTER DOMAIN";
1689 case OBJECT_FUNCTION:
1690 tag = "ALTER FUNCTION";
1692 case OBJECT_SEQUENCE:
1693 tag = "ALTER SEQUENCE";
1696 tag = "ALTER TABLE";
1701 case OBJECT_TSPARSER:
1702 tag = "ALTER TEXT SEARCH PARSER";
1704 case OBJECT_TSDICTIONARY:
1705 tag = "ALTER TEXT SEARCH DICTIONARY";
1707 case OBJECT_TSTEMPLATE:
1708 tag = "ALTER TEXT SEARCH TEMPLATE";
1710 case OBJECT_TSCONFIGURATION:
1711 tag = "ALTER TEXT SEARCH CONFIGURATION";
1722 case T_AlterOwnerStmt:
1723 switch (((AlterOwnerStmt *) parsetree)->objectType)
1725 case OBJECT_AGGREGATE:
1726 tag = "ALTER AGGREGATE";
1728 case OBJECT_CONVERSION:
1729 tag = "ALTER CONVERSION";
1731 case OBJECT_DATABASE:
1732 tag = "ALTER DATABASE";
1735 tag = "ALTER DOMAIN";
1737 case OBJECT_FUNCTION:
1738 tag = "ALTER FUNCTION";
1740 case OBJECT_LANGUAGE:
1741 tag = "ALTER LANGUAGE";
1743 case OBJECT_LARGEOBJECT:
1744 tag = "ALTER LARGE OBJECT";
1746 case OBJECT_OPERATOR:
1747 tag = "ALTER OPERATOR";
1749 case OBJECT_OPCLASS:
1750 tag = "ALTER OPERATOR CLASS";
1752 case OBJECT_OPFAMILY:
1753 tag = "ALTER OPERATOR FAMILY";
1756 tag = "ALTER SCHEMA";
1758 case OBJECT_TABLESPACE:
1759 tag = "ALTER TABLESPACE";
1764 case OBJECT_TSCONFIGURATION:
1765 tag = "ALTER TEXT SEARCH CONFIGURATION";
1767 case OBJECT_TSDICTIONARY:
1768 tag = "ALTER TEXT SEARCH DICTIONARY";
1771 tag = "ALTER FOREIGN DATA WRAPPER";
1773 case OBJECT_FOREIGN_SERVER:
1774 tag = "ALTER SERVER";
1782 case T_AlterTableStmt:
1783 switch (((AlterTableStmt *) parsetree)->relkind)
1786 tag = "ALTER TABLE";
1789 tag = "ALTER INDEX";
1791 case OBJECT_SEQUENCE:
1792 tag = "ALTER SEQUENCE";
1806 case T_AlterDomainStmt:
1807 tag = "ALTER DOMAIN";
1810 case T_AlterFunctionStmt:
1811 tag = "ALTER FUNCTION";
1816 GrantStmt *stmt = (GrantStmt *) parsetree;
1818 tag = (stmt->is_grant) ? "GRANT" : "REVOKE";
1822 case T_GrantRoleStmt:
1824 GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;
1826 tag = (stmt->is_grant) ? "GRANT ROLE" : "REVOKE ROLE";
1830 case T_AlterDefaultPrivilegesStmt:
1831 tag = "ALTER DEFAULT PRIVILEGES";
1835 switch (((DefineStmt *) parsetree)->kind)
1837 case OBJECT_AGGREGATE:
1838 tag = "CREATE AGGREGATE";
1840 case OBJECT_OPERATOR:
1841 tag = "CREATE OPERATOR";
1844 tag = "CREATE TYPE";
1846 case OBJECT_TSPARSER:
1847 tag = "CREATE TEXT SEARCH PARSER";
1849 case OBJECT_TSDICTIONARY:
1850 tag = "CREATE TEXT SEARCH DICTIONARY";
1852 case OBJECT_TSTEMPLATE:
1853 tag = "CREATE TEXT SEARCH TEMPLATE";
1855 case OBJECT_TSCONFIGURATION:
1856 tag = "CREATE TEXT SEARCH CONFIGURATION";
1863 case T_CompositeTypeStmt:
1864 tag = "CREATE TYPE";
1867 case T_CreateEnumStmt:
1868 tag = "CREATE TYPE";
1872 tag = "CREATE VIEW";
1875 case T_CreateFunctionStmt:
1876 tag = "CREATE FUNCTION";
1880 tag = "CREATE INDEX";
1884 tag = "CREATE RULE";
1887 case T_CreateSeqStmt:
1888 tag = "CREATE SEQUENCE";
1891 case T_AlterSeqStmt:
1892 tag = "ALTER SEQUENCE";
1895 case T_RemoveFuncStmt:
1896 switch (((RemoveFuncStmt *) parsetree)->kind)
1898 case OBJECT_FUNCTION:
1899 tag = "DROP FUNCTION";
1901 case OBJECT_AGGREGATE:
1902 tag = "DROP AGGREGATE";
1904 case OBJECT_OPERATOR:
1905 tag = "DROP OPERATOR";
1916 case T_CreatedbStmt:
1917 tag = "CREATE DATABASE";
1920 case T_AlterDatabaseStmt:
1921 tag = "ALTER DATABASE";
1924 case T_AlterDatabaseSetStmt:
1925 tag = "ALTER DATABASE";
1929 tag = "DROP DATABASE";
1940 case T_UnlistenStmt:
1953 if (((VacuumStmt *) parsetree)->options & VACOPT_VACUUM)
1963 case T_VariableSetStmt:
1964 switch (((VariableSetStmt *) parsetree)->kind)
1967 case VAR_SET_CURRENT:
1968 case VAR_SET_DEFAULT:
1981 case T_VariableShowStmt:
1986 switch (((DiscardStmt *) parsetree)->target)
1989 tag = "DISCARD ALL";
1992 tag = "DISCARD PLANS";
1995 tag = "DISCARD TEMP";
2002 case T_CreateTrigStmt:
2003 tag = "CREATE TRIGGER";
2006 case T_DropPropertyStmt:
2007 switch (((DropPropertyStmt *) parsetree)->removeType)
2009 case OBJECT_TRIGGER:
2010 tag = "DROP TRIGGER";
2020 case T_CreatePLangStmt:
2021 tag = "CREATE LANGUAGE";
2024 case T_DropPLangStmt:
2025 tag = "DROP LANGUAGE";
2028 case T_CreateRoleStmt:
2029 tag = "CREATE ROLE";
2032 case T_AlterRoleStmt:
2036 case T_AlterRoleSetStmt:
2040 case T_DropRoleStmt:
2044 case T_DropOwnedStmt:
2048 case T_ReassignOwnedStmt:
2049 tag = "REASSIGN OWNED";
2056 case T_ConstraintsSetStmt:
2057 tag = "SET CONSTRAINTS";
2060 case T_CheckPointStmt:
2068 case T_CreateConversionStmt:
2069 tag = "CREATE CONVERSION";
2072 case T_CreateCastStmt:
2073 tag = "CREATE CAST";
2076 case T_DropCastStmt:
2080 case T_CreateOpClassStmt:
2081 tag = "CREATE OPERATOR CLASS";
2084 case T_CreateOpFamilyStmt:
2085 tag = "CREATE OPERATOR FAMILY";
2088 case T_AlterOpFamilyStmt:
2089 tag = "ALTER OPERATOR FAMILY";
2092 case T_RemoveOpClassStmt:
2093 tag = "DROP OPERATOR CLASS";
2096 case T_RemoveOpFamilyStmt:
2097 tag = "DROP OPERATOR FAMILY";
2100 case T_AlterTSDictionaryStmt:
2101 tag = "ALTER TEXT SEARCH DICTIONARY";
2104 case T_AlterTSConfigurationStmt:
2105 tag = "ALTER TEXT SEARCH CONFIGURATION";
2116 case T_DeallocateStmt:
2118 DeallocateStmt *stmt = (DeallocateStmt *) parsetree;
2120 if (stmt->name == NULL)
2121 tag = "DEALLOCATE ALL";
2127 /* already-planned queries */
2130 PlannedStmt *stmt = (PlannedStmt *) parsetree;
2132 switch (stmt->commandType)
2137 * We take a little extra care here so that the result
2138 * will be useful for complaints about read-only
2141 if (stmt->utilityStmt != NULL)
2143 Assert(IsA(stmt->utilityStmt, DeclareCursorStmt));
2144 tag = "DECLARE CURSOR";
2146 else if (stmt->intoClause != NULL)
2147 tag = "SELECT INTO";
2148 else if (stmt->rowMarks != NIL)
2150 /* not 100% but probably close enough */
2151 if (((PlanRowMark *) linitial(stmt->rowMarks))->markType == ROW_MARK_EXCLUSIVE)
2152 tag = "SELECT FOR UPDATE";
2154 tag = "SELECT FOR SHARE";
2169 elog(WARNING, "unrecognized commandType: %d",
2170 (int) stmt->commandType);
2177 /* parsed-and-rewritten-but-not-planned queries */
2180 Query *stmt = (Query *) parsetree;
2182 switch (stmt->commandType)
2187 * We take a little extra care here so that the result
2188 * will be useful for complaints about read-only
2191 if (stmt->utilityStmt != NULL)
2193 Assert(IsA(stmt->utilityStmt, DeclareCursorStmt));
2194 tag = "DECLARE CURSOR";
2196 else if (stmt->intoClause != NULL)
2197 tag = "SELECT INTO";
2198 else if (stmt->rowMarks != NIL)
2200 /* not 100% but probably close enough */
2201 if (((RowMarkClause *) linitial(stmt->rowMarks))->forUpdate)
2202 tag = "SELECT FOR UPDATE";
2204 tag = "SELECT FOR SHARE";
2219 tag = CreateCommandTag(stmt->utilityStmt);
2222 elog(WARNING, "unrecognized commandType: %d",
2223 (int) stmt->commandType);
2231 elog(WARNING, "unrecognized node type: %d",
2232 (int) nodeTag(parsetree));
2242 * GetCommandLogLevel
2243 * utility to get the minimum log_statement level for a command,
2244 * given either a raw (un-analyzed) parsetree or a planned query.
2246 * This must handle all command types, but since the vast majority
2247 * of 'em are utility commands, it seems sensible to keep it here.
2250 GetCommandLogLevel(Node *parsetree)
2254 switch (nodeTag(parsetree))
2256 /* raw plannable queries */
2264 if (((SelectStmt *) parsetree)->intoClause)
2265 lev = LOGSTMT_DDL; /* CREATE AS, SELECT INTO */
2270 /* utility statements --- same whether raw or cooked */
2271 case T_TransactionStmt:
2275 case T_DeclareCursorStmt:
2279 case T_ClosePortalStmt:
2287 case T_CreateSchemaStmt:
2295 case T_CreateTableSpaceStmt:
2299 case T_DropTableSpaceStmt:
2303 case T_AlterTableSpaceOptionsStmt:
2307 case T_CreateFdwStmt:
2308 case T_AlterFdwStmt:
2310 case T_CreateForeignServerStmt:
2311 case T_AlterForeignServerStmt:
2312 case T_DropForeignServerStmt:
2313 case T_CreateUserMappingStmt:
2314 case T_AlterUserMappingStmt:
2315 case T_DropUserMappingStmt:
2323 case T_TruncateStmt:
2331 case T_SecLabelStmt:
2336 if (((CopyStmt *) parsetree)->is_from)
2344 PrepareStmt *stmt = (PrepareStmt *) parsetree;
2346 /* Look through a PREPARE to the contained stmt */
2347 lev = GetCommandLogLevel(stmt->query);
2353 ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
2354 PreparedStatement *ps;
2356 /* Look through an EXECUTE to the referenced stmt */
2357 ps = FetchPreparedStatement(stmt->name, false);
2359 lev = GetCommandLogLevel(ps->plansource->raw_parse_tree);
2365 case T_DeallocateStmt:
2373 case T_AlterObjectSchemaStmt:
2377 case T_AlterOwnerStmt:
2381 case T_AlterTableStmt:
2385 case T_AlterDomainStmt:
2393 case T_GrantRoleStmt:
2397 case T_AlterDefaultPrivilegesStmt:
2405 case T_CompositeTypeStmt:
2409 case T_CreateEnumStmt:
2417 case T_CreateFunctionStmt:
2421 case T_AlterFunctionStmt:
2433 case T_CreateSeqStmt:
2437 case T_AlterSeqStmt:
2441 case T_RemoveFuncStmt:
2449 case T_CreatedbStmt:
2453 case T_AlterDatabaseStmt:
2457 case T_AlterDatabaseSetStmt:
2473 case T_UnlistenStmt:
2491 ExplainStmt *stmt = (ExplainStmt *) parsetree;
2492 bool analyze = false;
2495 /* Look through an EXPLAIN ANALYZE to the contained stmt */
2496 foreach(lc, stmt->options)
2498 DefElem *opt = (DefElem *) lfirst(lc);
2500 if (strcmp(opt->defname, "analyze") == 0)
2501 analyze = defGetBoolean(opt);
2502 /* don't "break", as explain.c will use the last value */
2505 return GetCommandLogLevel(stmt->query);
2507 /* Plain EXPLAIN isn't so interesting */
2512 case T_VariableSetStmt:
2516 case T_VariableShowStmt:
2524 case T_CreateTrigStmt:
2528 case T_DropPropertyStmt:
2532 case T_CreatePLangStmt:
2536 case T_DropPLangStmt:
2540 case T_CreateDomainStmt:
2544 case T_CreateRoleStmt:
2548 case T_AlterRoleStmt:
2552 case T_AlterRoleSetStmt:
2556 case T_DropRoleStmt:
2560 case T_DropOwnedStmt:
2564 case T_ReassignOwnedStmt:
2572 case T_ConstraintsSetStmt:
2576 case T_CheckPointStmt:
2581 lev = LOGSTMT_ALL; /* should this be DDL? */
2584 case T_CreateConversionStmt:
2588 case T_CreateCastStmt:
2592 case T_DropCastStmt:
2596 case T_CreateOpClassStmt:
2600 case T_CreateOpFamilyStmt:
2604 case T_AlterOpFamilyStmt:
2608 case T_RemoveOpClassStmt:
2612 case T_RemoveOpFamilyStmt:
2616 case T_AlterTSDictionaryStmt:
2620 case T_AlterTSConfigurationStmt:
2624 /* already-planned queries */
2627 PlannedStmt *stmt = (PlannedStmt *) parsetree;
2629 switch (stmt->commandType)
2632 if (stmt->intoClause != NULL)
2633 lev = LOGSTMT_DDL; /* CREATE AS, SELECT INTO */
2635 lev = LOGSTMT_ALL; /* SELECT or DECLARE CURSOR */
2645 elog(WARNING, "unrecognized commandType: %d",
2646 (int) stmt->commandType);
2653 /* parsed-and-rewritten-but-not-planned queries */
2656 Query *stmt = (Query *) parsetree;
2658 switch (stmt->commandType)
2661 if (stmt->intoClause != NULL)
2662 lev = LOGSTMT_DDL; /* CREATE AS, SELECT INTO */
2664 lev = LOGSTMT_ALL; /* SELECT or DECLARE CURSOR */
2674 lev = GetCommandLogLevel(stmt->utilityStmt);
2678 elog(WARNING, "unrecognized commandType: %d",
2679 (int) stmt->commandType);
2688 elog(WARNING, "unrecognized node type: %d",
2689 (int) nodeTag(parsetree));