Header And Logo

PostgreSQL
| The world's most advanced open source database.

Typedefs | Enumerations | Functions | Variables

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 )(Node *parsetree, const char *queryString, ProcessUtilityContext context, ParamListInfo params, DestReceiver *dest, char *completionTag)

Enumerations

enum  ProcessUtilityContext { PROCESS_UTILITY_TOPLEVEL, PROCESS_UTILITY_QUERY, PROCESS_UTILITY_SUBCOMMAND }

Functions

void ProcessUtility (Node *parsetree, const char *queryString, ProcessUtilityContext context, ParamListInfo params, DestReceiver *dest, char *completionTag)
void standard_ProcessUtility (Node *parsetree, const char *queryString, ProcessUtilityContext context, ParamListInfo params, 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 (Node *parsetree)
void CheckRelationOwnership (RangeVar *rel, bool noCatalogs)

Variables

PGDLLIMPORT
ProcessUtility_hook_type 
ProcessUtility_hook

Typedef Documentation

typedef void(* ProcessUtility_hook_type)(Node *parsetree, const char *queryString, ProcessUtilityContext context, ParamListInfo params, DestReceiver *dest, char *completionTag)

Definition at line 27 of file utility.h.


Enumeration Type Documentation

Enumerator:
PROCESS_UTILITY_TOPLEVEL 
PROCESS_UTILITY_QUERY 
PROCESS_UTILITY_SUBCOMMAND 

Definition at line 19 of file utility.h.

{
    PROCESS_UTILITY_TOPLEVEL,       /* toplevel interactive command */
    PROCESS_UTILITY_QUERY,          /* a complete query, but not toplevel */
    PROCESS_UTILITY_SUBCOMMAND      /* a portion of a query */
} ProcessUtilityContext;


Function Documentation

void CheckRelationOwnership ( RangeVar rel,
bool  noCatalogs 
)

Definition at line 88 of file utility.c.

References ACL_KIND_CLASS, aclcheck_error(), ACLCHECK_NOT_OWNER, allowSystemTableMods, elog, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, GetUserId(), HeapTupleIsValid, IsSystemClass(), NoLock, ObjectIdGetDatum, pg_class_ownercheck(), RangeVarGetRelid, ReleaseSysCache(), RangeVar::relname, RELOID, and SearchSysCache1.

Referenced by ProcessUtilitySlow().

{
    Oid         relOid;
    HeapTuple   tuple;

    /*
     * XXX: This is unsafe in the presence of concurrent DDL, since it is
     * called before acquiring any lock on the target relation.  However,
     * locking the target relation (especially using something like
     * AccessExclusiveLock) before verifying that the user has permissions is
     * not appealing either.
     */
    relOid = RangeVarGetRelid(rel, NoLock, false);

    tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relOid));
    if (!HeapTupleIsValid(tuple))       /* should not happen */
        elog(ERROR, "cache lookup failed for relation %u", relOid);

    if (!pg_class_ownercheck(relOid, GetUserId()))
        aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
                       rel->relname);

    if (noCatalogs)
    {
        if (!allowSystemTableMods &&
            IsSystemClass((Form_pg_class) GETSTRUCT(tuple)))
            ereport(ERROR,
                    (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
                     errmsg("permission denied: \"%s\" is a system catalog",
                            rel->relname)));
    }

    ReleaseSysCache(tuple);
}

bool CommandIsReadOnly ( Node parsetree  ) 

Definition at line 134 of file utility.c.

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

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

{
    if (IsA(parsetree, PlannedStmt))
    {
        PlannedStmt *stmt = (PlannedStmt *) parsetree;

        switch (stmt->commandType)
        {
            case CMD_SELECT:
                if (stmt->rowMarks != NIL)
                    return false;       /* SELECT FOR [KEY] UPDATE/SHARE */
                else if (stmt->hasModifyingCTE)
                    return false;       /* data-modifying CTE */
                else
                    return true;
            case CMD_UPDATE:
            case CMD_INSERT:
            case CMD_DELETE:
                return false;
            default:
                elog(WARNING, "unrecognized commandType: %d",
                     (int) stmt->commandType);
                break;
        }
    }
    /* For now, treat all utility commands as read/write */
    return false;
}

const char* CreateCommandTag ( Node parsetree  ) 

Definition at line 1697 of file utility.c.

References AlterObjectTypeCommandTag(), Assert, CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, Query::commandType, PlannedStmt::commandType, CreateCommandTag(), DISCARD_ALL, DISCARD_PLANS, DISCARD_TEMP, elog, GrantRoleStmt::is_grant, GrantStmt::is_grant, IsA, FetchStmt::ismove, TransactionStmt::kind, LCS_FORKEYSHARE, LCS_FORNOKEYUPDATE, LCS_FORSHARE, LCS_FORUPDATE, linitial, DeallocateStmt::name, NIL, nodeTag, NULL, 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_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ClosePortalStmt::portalname, ROW_MARK_COPY, ROW_MARK_EXCLUSIVE, ROW_MARK_KEYSHARE, ROW_MARK_NOKEYEXCLUSIVE, ROW_MARK_REFERENCE, ROW_MARK_SHARE, Query::rowMarks, PlannedStmt::rowMarks, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectSchemaStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterUserMappingStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, 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_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, 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_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PrepareStmt, T_Query, 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, Query::utilityStmt, PlannedStmt::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(), init_execution_state(), PrepareQuery(), and SPI_cursor_open_internal().

{
    const char *tag;

    switch (nodeTag(parsetree))
    {
            /* raw plannable queries */
        case T_InsertStmt:
            tag = "INSERT";
            break;

        case T_DeleteStmt:
            tag = "DELETE";
            break;

        case T_UpdateStmt:
            tag = "UPDATE";
            break;

        case T_SelectStmt:
            tag = "SELECT";
            break;

            /* utility statements --- same whether raw or cooked */
        case T_TransactionStmt:
            {
                TransactionStmt *stmt = (TransactionStmt *) parsetree;

                switch (stmt->kind)
                {
                    case TRANS_STMT_BEGIN:
                        tag = "BEGIN";
                        break;

                    case TRANS_STMT_START:
                        tag = "START TRANSACTION";
                        break;

                    case TRANS_STMT_COMMIT:
                        tag = "COMMIT";
                        break;

                    case TRANS_STMT_ROLLBACK:
                    case TRANS_STMT_ROLLBACK_TO:
                        tag = "ROLLBACK";
                        break;

                    case TRANS_STMT_SAVEPOINT:
                        tag = "SAVEPOINT";
                        break;

                    case TRANS_STMT_RELEASE:
                        tag = "RELEASE";
                        break;

                    case TRANS_STMT_PREPARE:
                        tag = "PREPARE TRANSACTION";
                        break;

                    case TRANS_STMT_COMMIT_PREPARED:
                        tag = "COMMIT PREPARED";
                        break;

                    case TRANS_STMT_ROLLBACK_PREPARED:
                        tag = "ROLLBACK PREPARED";
                        break;

                    default:
                        tag = "???";
                        break;
                }
            }
            break;

        case T_DeclareCursorStmt:
            tag = "DECLARE CURSOR";
            break;

        case T_ClosePortalStmt:
            {
                ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;

                if (stmt->portalname == NULL)
                    tag = "CLOSE CURSOR ALL";
                else
                    tag = "CLOSE CURSOR";
            }
            break;

        case T_FetchStmt:
            {
                FetchStmt  *stmt = (FetchStmt *) parsetree;

                tag = (stmt->ismove) ? "MOVE" : "FETCH";
            }
            break;

        case T_CreateDomainStmt:
            tag = "CREATE DOMAIN";
            break;

        case T_CreateSchemaStmt:
            tag = "CREATE SCHEMA";
            break;

        case T_CreateStmt:
            tag = "CREATE TABLE";
            break;

        case T_CreateTableSpaceStmt:
            tag = "CREATE TABLESPACE";
            break;

        case T_DropTableSpaceStmt:
            tag = "DROP TABLESPACE";
            break;

        case T_AlterTableSpaceOptionsStmt:
            tag = "ALTER TABLESPACE";
            break;

        case T_CreateExtensionStmt:
            tag = "CREATE EXTENSION";
            break;

        case T_AlterExtensionStmt:
            tag = "ALTER EXTENSION";
            break;

        case T_AlterExtensionContentsStmt:
            tag = "ALTER EXTENSION";
            break;

        case T_CreateFdwStmt:
            tag = "CREATE FOREIGN DATA WRAPPER";
            break;

        case T_AlterFdwStmt:
            tag = "ALTER FOREIGN DATA WRAPPER";
            break;

        case T_CreateForeignServerStmt:
            tag = "CREATE SERVER";
            break;

        case T_AlterForeignServerStmt:
            tag = "ALTER SERVER";
            break;

        case T_CreateUserMappingStmt:
            tag = "CREATE USER MAPPING";
            break;

        case T_AlterUserMappingStmt:
            tag = "ALTER USER MAPPING";
            break;

        case T_DropUserMappingStmt:
            tag = "DROP USER MAPPING";
            break;

        case T_CreateForeignTableStmt:
            tag = "CREATE FOREIGN TABLE";
            break;

        case T_DropStmt:
            switch (((DropStmt *) parsetree)->removeType)
            {
                case OBJECT_TABLE:
                    tag = "DROP TABLE";
                    break;
                case OBJECT_SEQUENCE:
                    tag = "DROP SEQUENCE";
                    break;
                case OBJECT_VIEW:
                    tag = "DROP VIEW";
                    break;
                case OBJECT_MATVIEW:
                    tag = "DROP MATERIALIZED VIEW";
                    break;
                case OBJECT_INDEX:
                    tag = "DROP INDEX";
                    break;
                case OBJECT_TYPE:
                    tag = "DROP TYPE";
                    break;
                case OBJECT_DOMAIN:
                    tag = "DROP DOMAIN";
                    break;
                case OBJECT_COLLATION:
                    tag = "DROP COLLATION";
                    break;
                case OBJECT_CONVERSION:
                    tag = "DROP CONVERSION";
                    break;
                case OBJECT_SCHEMA:
                    tag = "DROP SCHEMA";
                    break;
                case OBJECT_TSPARSER:
                    tag = "DROP TEXT SEARCH PARSER";
                    break;
                case OBJECT_TSDICTIONARY:
                    tag = "DROP TEXT SEARCH DICTIONARY";
                    break;
                case OBJECT_TSTEMPLATE:
                    tag = "DROP TEXT SEARCH TEMPLATE";
                    break;
                case OBJECT_TSCONFIGURATION:
                    tag = "DROP TEXT SEARCH CONFIGURATION";
                    break;
                case OBJECT_FOREIGN_TABLE:
                    tag = "DROP FOREIGN TABLE";
                    break;
                case OBJECT_EXTENSION:
                    tag = "DROP EXTENSION";
                    break;
                case OBJECT_FUNCTION:
                    tag = "DROP FUNCTION";
                    break;
                case OBJECT_AGGREGATE:
                    tag = "DROP AGGREGATE";
                    break;
                case OBJECT_OPERATOR:
                    tag = "DROP OPERATOR";
                    break;
                case OBJECT_LANGUAGE:
                    tag = "DROP LANGUAGE";
                    break;
                case OBJECT_CAST:
                    tag = "DROP CAST";
                    break;
                case OBJECT_TRIGGER:
                    tag = "DROP TRIGGER";
                    break;
                case OBJECT_EVENT_TRIGGER:
                    tag = "DROP EVENT TRIGGER";
                    break;
                case OBJECT_RULE:
                    tag = "DROP RULE";
                    break;
                case OBJECT_FDW:
                    tag = "DROP FOREIGN DATA WRAPPER";
                    break;
                case OBJECT_FOREIGN_SERVER:
                    tag = "DROP SERVER";
                    break;
                case OBJECT_OPCLASS:
                    tag = "DROP OPERATOR CLASS";
                    break;
                case OBJECT_OPFAMILY:
                    tag = "DROP OPERATOR FAMILY";
                    break;
                default:
                    tag = "???";
            }
            break;

        case T_TruncateStmt:
            tag = "TRUNCATE TABLE";
            break;

        case T_CommentStmt:
            tag = "COMMENT";
            break;

        case T_SecLabelStmt:
            tag = "SECURITY LABEL";
            break;

        case T_CopyStmt:
            tag = "COPY";
            break;

        case T_RenameStmt:
            tag = AlterObjectTypeCommandTag(((RenameStmt *) parsetree)->renameType);
            break;

        case T_AlterObjectSchemaStmt:
            tag = AlterObjectTypeCommandTag(((AlterObjectSchemaStmt *) parsetree)->objectType);
            break;

        case T_AlterOwnerStmt:
            tag = AlterObjectTypeCommandTag(((AlterOwnerStmt *) parsetree)->objectType);
            break;

        case T_AlterTableStmt:
            tag = AlterObjectTypeCommandTag(((AlterTableStmt *) parsetree)->relkind);
            break;

        case T_AlterDomainStmt:
            tag = "ALTER DOMAIN";
            break;

        case T_AlterFunctionStmt:
            tag = "ALTER FUNCTION";
            break;

        case T_GrantStmt:
            {
                GrantStmt  *stmt = (GrantStmt *) parsetree;

                tag = (stmt->is_grant) ? "GRANT" : "REVOKE";
            }
            break;

        case T_GrantRoleStmt:
            {
                GrantRoleStmt *stmt = (GrantRoleStmt *) parsetree;

                tag = (stmt->is_grant) ? "GRANT ROLE" : "REVOKE ROLE";
            }
            break;

        case T_AlterDefaultPrivilegesStmt:
            tag = "ALTER DEFAULT PRIVILEGES";
            break;

        case T_DefineStmt:
            switch (((DefineStmt *) parsetree)->kind)
            {
                case OBJECT_AGGREGATE:
                    tag = "CREATE AGGREGATE";
                    break;
                case OBJECT_OPERATOR:
                    tag = "CREATE OPERATOR";
                    break;
                case OBJECT_TYPE:
                    tag = "CREATE TYPE";
                    break;
                case OBJECT_TSPARSER:
                    tag = "CREATE TEXT SEARCH PARSER";
                    break;
                case OBJECT_TSDICTIONARY:
                    tag = "CREATE TEXT SEARCH DICTIONARY";
                    break;
                case OBJECT_TSTEMPLATE:
                    tag = "CREATE TEXT SEARCH TEMPLATE";
                    break;
                case OBJECT_TSCONFIGURATION:
                    tag = "CREATE TEXT SEARCH CONFIGURATION";
                    break;
                case OBJECT_COLLATION:
                    tag = "CREATE COLLATION";
                    break;
                default:
                    tag = "???";
            }
            break;

        case T_CompositeTypeStmt:
            tag = "CREATE TYPE";
            break;

        case T_CreateEnumStmt:
            tag = "CREATE TYPE";
            break;

        case T_CreateRangeStmt:
            tag = "CREATE TYPE";
            break;

        case T_AlterEnumStmt:
            tag = "ALTER TYPE";
            break;

        case T_ViewStmt:
            tag = "CREATE VIEW";
            break;

        case T_CreateFunctionStmt:
            tag = "CREATE FUNCTION";
            break;

        case T_IndexStmt:
            tag = "CREATE INDEX";
            break;

        case T_RuleStmt:
            tag = "CREATE RULE";
            break;

        case T_CreateSeqStmt:
            tag = "CREATE SEQUENCE";
            break;

        case T_AlterSeqStmt:
            tag = "ALTER SEQUENCE";
            break;

        case T_DoStmt:
            tag = "DO";
            break;

        case T_CreatedbStmt:
            tag = "CREATE DATABASE";
            break;

        case T_AlterDatabaseStmt:
            tag = "ALTER DATABASE";
            break;

        case T_AlterDatabaseSetStmt:
            tag = "ALTER DATABASE";
            break;

        case T_DropdbStmt:
            tag = "DROP DATABASE";
            break;

        case T_NotifyStmt:
            tag = "NOTIFY";
            break;

        case T_ListenStmt:
            tag = "LISTEN";
            break;

        case T_UnlistenStmt:
            tag = "UNLISTEN";
            break;

        case T_LoadStmt:
            tag = "LOAD";
            break;

        case T_ClusterStmt:
            tag = "CLUSTER";
            break;

        case T_VacuumStmt:
            if (((VacuumStmt *) parsetree)->options & VACOPT_VACUUM)
                tag = "VACUUM";
            else
                tag = "ANALYZE";
            break;

        case T_ExplainStmt:
            tag = "EXPLAIN";
            break;

        case T_CreateTableAsStmt:
            switch (((CreateTableAsStmt *) parsetree)->relkind)
            {
                case OBJECT_TABLE:
                    if (((CreateTableAsStmt *) parsetree)->is_select_into)
                        tag = "SELECT INTO";
                    else
                        tag = "CREATE TABLE AS";
                    break;
                case OBJECT_MATVIEW:
                    tag = "CREATE MATERIALIZED VIEW";
                    break;
                default:
                    tag = "???";
            }
            break;

        case T_RefreshMatViewStmt:
            tag = "REFRESH MATERIALIZED VIEW";
            break;

        case T_VariableSetStmt:
            switch (((VariableSetStmt *) parsetree)->kind)
            {
                case VAR_SET_VALUE:
                case VAR_SET_CURRENT:
                case VAR_SET_DEFAULT:
                case VAR_SET_MULTI:
                    tag = "SET";
                    break;
                case VAR_RESET:
                case VAR_RESET_ALL:
                    tag = "RESET";
                    break;
                default:
                    tag = "???";
            }
            break;

        case T_VariableShowStmt:
            tag = "SHOW";
            break;

        case T_DiscardStmt:
            switch (((DiscardStmt *) parsetree)->target)
            {
                case DISCARD_ALL:
                    tag = "DISCARD ALL";
                    break;
                case DISCARD_PLANS:
                    tag = "DISCARD PLANS";
                    break;
                case DISCARD_TEMP:
                    tag = "DISCARD TEMP";
                    break;
                default:
                    tag = "???";
            }
            break;

        case T_CreateTrigStmt:
            tag = "CREATE TRIGGER";
            break;

        case T_CreateEventTrigStmt:
            tag = "CREATE EVENT TRIGGER";
            break;

        case T_AlterEventTrigStmt:
            tag = "ALTER EVENT TRIGGER";
            break;

        case T_CreatePLangStmt:
            tag = "CREATE LANGUAGE";
            break;

        case T_CreateRoleStmt:
            tag = "CREATE ROLE";
            break;

        case T_AlterRoleStmt:
            tag = "ALTER ROLE";
            break;

        case T_AlterRoleSetStmt:
            tag = "ALTER ROLE";
            break;

        case T_DropRoleStmt:
            tag = "DROP ROLE";
            break;

        case T_DropOwnedStmt:
            tag = "DROP OWNED";
            break;

        case T_ReassignOwnedStmt:
            tag = "REASSIGN OWNED";
            break;

        case T_LockStmt:
            tag = "LOCK TABLE";
            break;

        case T_ConstraintsSetStmt:
            tag = "SET CONSTRAINTS";
            break;

        case T_CheckPointStmt:
            tag = "CHECKPOINT";
            break;

        case T_ReindexStmt:
            tag = "REINDEX";
            break;

        case T_CreateConversionStmt:
            tag = "CREATE CONVERSION";
            break;

        case T_CreateCastStmt:
            tag = "CREATE CAST";
            break;

        case T_CreateOpClassStmt:
            tag = "CREATE OPERATOR CLASS";
            break;

        case T_CreateOpFamilyStmt:
            tag = "CREATE OPERATOR FAMILY";
            break;

        case T_AlterOpFamilyStmt:
            tag = "ALTER OPERATOR FAMILY";
            break;

        case T_AlterTSDictionaryStmt:
            tag = "ALTER TEXT SEARCH DICTIONARY";
            break;

        case T_AlterTSConfigurationStmt:
            tag = "ALTER TEXT SEARCH CONFIGURATION";
            break;

        case T_PrepareStmt:
            tag = "PREPARE";
            break;

        case T_ExecuteStmt:
            tag = "EXECUTE";
            break;

        case T_DeallocateStmt:
            {
                DeallocateStmt *stmt = (DeallocateStmt *) parsetree;

                if (stmt->name == NULL)
                    tag = "DEALLOCATE ALL";
                else
                    tag = "DEALLOCATE";
            }
            break;

            /* already-planned queries */
        case T_PlannedStmt:
            {
                PlannedStmt *stmt = (PlannedStmt *) parsetree;

                switch (stmt->commandType)
                {
                    case CMD_SELECT:

                        /*
                         * We take a little extra care here so that the result
                         * will be useful for complaints about read-only
                         * statements
                         */
                        if (stmt->utilityStmt != NULL)
                        {
                            Assert(IsA(stmt->utilityStmt, DeclareCursorStmt));
                            tag = "DECLARE CURSOR";
                        }
                        else if (stmt->rowMarks != NIL)
                        {
                            /* not 100% but probably close enough */
                            switch (((PlanRowMark *) linitial(stmt->rowMarks))->markType)
                            {
                                case ROW_MARK_EXCLUSIVE:
                                    tag = "SELECT FOR UPDATE";
                                    break;
                                case ROW_MARK_NOKEYEXCLUSIVE:
                                    tag = "SELECT FOR NO KEY UPDATE";
                                    break;
                                case ROW_MARK_SHARE:
                                    tag = "SELECT FOR SHARE";
                                    break;
                                case ROW_MARK_KEYSHARE:
                                    tag = "SELECT FOR KEY SHARE";
                                    break;
                                case ROW_MARK_REFERENCE:
                                case ROW_MARK_COPY:
                                    tag = "SELECT";
                                    break;
                                default:
                                    tag = "???";
                                    break;
                            }
                        }
                        else
                            tag = "SELECT";
                        break;
                    case CMD_UPDATE:
                        tag = "UPDATE";
                        break;
                    case CMD_INSERT:
                        tag = "INSERT";
                        break;
                    case CMD_DELETE:
                        tag = "DELETE";
                        break;
                    default:
                        elog(WARNING, "unrecognized commandType: %d",
                             (int) stmt->commandType);
                        tag = "???";
                        break;
                }
            }
            break;

            /* parsed-and-rewritten-but-not-planned queries */
        case T_Query:
            {
                Query      *stmt = (Query *) parsetree;

                switch (stmt->commandType)
                {
                    case CMD_SELECT:

                        /*
                         * We take a little extra care here so that the result
                         * will be useful for complaints about read-only
                         * statements
                         */
                        if (stmt->utilityStmt != NULL)
                        {
                            Assert(IsA(stmt->utilityStmt, DeclareCursorStmt));
                            tag = "DECLARE CURSOR";
                        }
                        else if (stmt->rowMarks != NIL)
                        {
                            /* not 100% but probably close enough */
                            switch (((RowMarkClause *) linitial(stmt->rowMarks))->strength)
                            {
                                case LCS_FORKEYSHARE:
                                    tag = "SELECT FOR KEY SHARE";
                                    break;
                                case LCS_FORSHARE:
                                    tag = "SELECT FOR SHARE";
                                    break;
                                case LCS_FORNOKEYUPDATE:
                                    tag = "SELECT FOR NO KEY UPDATE";
                                    break;
                                case LCS_FORUPDATE:
                                    tag = "SELECT FOR UPDATE";
                                    break;
                                default:
                                    tag = "???";
                                    break;
                            }
                        }
                        else
                            tag = "SELECT";
                        break;
                    case CMD_UPDATE:
                        tag = "UPDATE";
                        break;
                    case CMD_INSERT:
                        tag = "INSERT";
                        break;
                    case CMD_DELETE:
                        tag = "DELETE";
                        break;
                    case CMD_UTILITY:
                        tag = CreateCommandTag(stmt->utilityStmt);
                        break;
                    default:
                        elog(WARNING, "unrecognized commandType: %d",
                             (int) stmt->commandType);
                        tag = "???";
                        break;
                }
            }
            break;

        default:
            elog(WARNING, "unrecognized node type: %d",
                 (int) nodeTag(parsetree));
            tag = "???";
            break;
    }

    return tag;
}

LogStmtLevel GetCommandLogLevel ( Node parsetree  ) 

Definition at line 2451 of file utility.c.

References analyze(), CMD_DELETE, CMD_INSERT, CMD_SELECT, CMD_UPDATE, CMD_UTILITY, Query::commandType, PlannedStmt::commandType, defGetBoolean(), DefElem::defname, elog, FetchPreparedStatement(), GetCommandLogLevel(), lfirst, ExecuteStmt::name, nodeTag, ExplainStmt::options, PreparedStatement::plansource, ExplainStmt::query, PrepareStmt::query, CachedPlanSource::raw_parse_tree, T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterDefaultPrivilegesStmt, T_AlterDomainStmt, T_AlterEnumStmt, T_AlterEventTrigStmt, T_AlterExtensionContentsStmt, T_AlterExtensionStmt, T_AlterFdwStmt, T_AlterForeignServerStmt, T_AlterFunctionStmt, T_AlterObjectSchemaStmt, T_AlterOpFamilyStmt, T_AlterOwnerStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterSeqStmt, T_AlterTableSpaceOptionsStmt, T_AlterTableStmt, T_AlterTSConfigurationStmt, T_AlterTSDictionaryStmt, T_AlterUserMappingStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_CompositeTypeStmt, T_ConstraintsSetStmt, T_CopyStmt, 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_CreateRangeStmt, T_CreateRoleStmt, T_CreateSchemaStmt, T_CreateSeqStmt, T_CreateStmt, T_CreateTableAsStmt, T_CreateTableSpaceStmt, 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_DropTableSpaceStmt, T_DropUserMappingStmt, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_GrantRoleStmt, T_GrantStmt, T_IndexStmt, T_InsertStmt, T_ListenStmt, T_LoadStmt, T_LockStmt, T_NotifyStmt, T_PlannedStmt, T_PrepareStmt, T_Query, 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, Query::utilityStmt, and WARNING.

Referenced by check_log_statement(), and GetCommandLogLevel().

{
    LogStmtLevel lev;

    switch (nodeTag(parsetree))
    {
            /* raw plannable queries */
        case T_InsertStmt:
        case T_DeleteStmt:
        case T_UpdateStmt:
            lev = LOGSTMT_MOD;
            break;

        case T_SelectStmt:
            if (((SelectStmt *) parsetree)->intoClause)
                lev = LOGSTMT_DDL;      /* SELECT INTO */
            else
                lev = LOGSTMT_ALL;
            break;

            /* utility statements --- same whether raw or cooked */
        case T_TransactionStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_DeclareCursorStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_ClosePortalStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_FetchStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_CreateSchemaStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateStmt:
        case T_CreateForeignTableStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateTableSpaceStmt:
        case T_DropTableSpaceStmt:
        case T_AlterTableSpaceOptionsStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateExtensionStmt:
        case T_AlterExtensionStmt:
        case T_AlterExtensionContentsStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateFdwStmt:
        case T_AlterFdwStmt:
        case T_CreateForeignServerStmt:
        case T_AlterForeignServerStmt:
        case T_CreateUserMappingStmt:
        case T_AlterUserMappingStmt:
        case T_DropUserMappingStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_DropStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_TruncateStmt:
            lev = LOGSTMT_MOD;
            break;

        case T_CommentStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_SecLabelStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CopyStmt:
            if (((CopyStmt *) parsetree)->is_from)
                lev = LOGSTMT_MOD;
            else
                lev = LOGSTMT_ALL;
            break;

        case T_PrepareStmt:
            {
                PrepareStmt *stmt = (PrepareStmt *) parsetree;

                /* Look through a PREPARE to the contained stmt */
                lev = GetCommandLogLevel(stmt->query);
            }
            break;

        case T_ExecuteStmt:
            {
                ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
                PreparedStatement *ps;

                /* Look through an EXECUTE to the referenced stmt */
                ps = FetchPreparedStatement(stmt->name, false);
                if (ps)
                    lev = GetCommandLogLevel(ps->plansource->raw_parse_tree);
                else
                    lev = LOGSTMT_ALL;
            }
            break;

        case T_DeallocateStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_RenameStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterObjectSchemaStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterOwnerStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterTableStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterDomainStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_GrantStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_GrantRoleStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterDefaultPrivilegesStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_DefineStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CompositeTypeStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateEnumStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateRangeStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterEnumStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_ViewStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateFunctionStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterFunctionStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_IndexStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_RuleStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateSeqStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterSeqStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_DoStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_CreatedbStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterDatabaseStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterDatabaseSetStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_DropdbStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_NotifyStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_ListenStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_UnlistenStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_LoadStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_ClusterStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_VacuumStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_ExplainStmt:
            {
                ExplainStmt *stmt = (ExplainStmt *) parsetree;
                bool        analyze = false;
                ListCell   *lc;

                /* Look through an EXPLAIN ANALYZE to the contained stmt */
                foreach(lc, stmt->options)
                {
                    DefElem    *opt = (DefElem *) lfirst(lc);

                    if (strcmp(opt->defname, "analyze") == 0)
                        analyze = defGetBoolean(opt);
                    /* don't "break", as explain.c will use the last value */
                }
                if (analyze)
                    return GetCommandLogLevel(stmt->query);

                /* Plain EXPLAIN isn't so interesting */
                lev = LOGSTMT_ALL;
            }
            break;

        case T_CreateTableAsStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_RefreshMatViewStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_VariableSetStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_VariableShowStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_DiscardStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_CreateTrigStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateEventTrigStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterEventTrigStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreatePLangStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateDomainStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateRoleStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterRoleStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterRoleSetStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_DropRoleStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_DropOwnedStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_ReassignOwnedStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_LockStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_ConstraintsSetStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_CheckPointStmt:
            lev = LOGSTMT_ALL;
            break;

        case T_ReindexStmt:
            lev = LOGSTMT_ALL;  /* should this be DDL? */
            break;

        case T_CreateConversionStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateCastStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateOpClassStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_CreateOpFamilyStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterOpFamilyStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterTSDictionaryStmt:
            lev = LOGSTMT_DDL;
            break;

        case T_AlterTSConfigurationStmt:
            lev = LOGSTMT_DDL;
            break;

            /* already-planned queries */
        case T_PlannedStmt:
            {
                PlannedStmt *stmt = (PlannedStmt *) parsetree;

                switch (stmt->commandType)
                {
                    case CMD_SELECT:
                        lev = LOGSTMT_ALL;
                        break;

                    case CMD_UPDATE:
                    case CMD_INSERT:
                    case CMD_DELETE:
                        lev = LOGSTMT_MOD;
                        break;

                    default:
                        elog(WARNING, "unrecognized commandType: %d",
                             (int) stmt->commandType);
                        lev = LOGSTMT_ALL;
                        break;
                }
            }
            break;

            /* parsed-and-rewritten-but-not-planned queries */
        case T_Query:
            {
                Query      *stmt = (Query *) parsetree;

                switch (stmt->commandType)
                {
                    case CMD_SELECT:
                        lev = LOGSTMT_ALL;
                        break;

                    case CMD_UPDATE:
                    case CMD_INSERT:
                    case CMD_DELETE:
                        lev = LOGSTMT_MOD;
                        break;

                    case CMD_UTILITY:
                        lev = GetCommandLogLevel(stmt->utilityStmt);
                        break;

                    default:
                        elog(WARNING, "unrecognized commandType: %d",
                             (int) stmt->commandType);
                        lev = LOGSTMT_ALL;
                        break;
                }

            }
            break;

        default:
            elog(WARNING, "unrecognized node type: %d",
                 (int) nodeTag(parsetree));
            lev = LOGSTMT_ALL;
            break;
    }

    return lev;
}

void ProcessUtility ( Node parsetree,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
DestReceiver dest,
char *  completionTag 
)

Definition at line 333 of file utility.c.

References Assert, NULL, ProcessUtility_hook, and standard_ProcessUtility().

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

{
    Assert(queryString != NULL);    /* required as of 8.4 */

    /*
     * We provide a function hook variable that lets loadable plugins get
     * control when ProcessUtility is called.  Such a plugin would normally
     * call standard_ProcessUtility().
     */
    if (ProcessUtility_hook)
        (*ProcessUtility_hook) (parsetree, queryString,
                                context, params,
                                dest, completionTag);
    else
        standard_ProcessUtility(parsetree, queryString,
                                context, params,
                                dest, completionTag);
}

void standard_ProcessUtility ( Node parsetree,
const char *  queryString,
ProcessUtilityContext  context,
ParamListInfo  params,
DestReceiver dest,
char *  completionTag 
)

Definition at line 369 of file utility.c.

References AfterTriggerSetState(), AlterDatabase(), AlterDatabaseSet(), AlterEventTrigger(), AlterRole(), AlterRoleSet(), AlterTableSpaceOptions(), DefElem::arg, Assert, Async_Listen(), Async_Notify(), Async_Unlisten(), Async_UnlistenAll(), BeginTransactionBlock(), check_xact_readonly(), CHECKPOINT_FORCE, CHECKPOINT_IMMEDIATE, CHECKPOINT_WAIT, CheckRestrictedOperation(), closeAllVfds(), cluster(), CommentObject(), COMPLETION_TAG_BUFSIZE, UnlistenStmt::conditionname, ListenStmt::conditionname, NotifyStmt::conditionname, createdb(), CreateEventTrigger(), CreateRole(), CreateTableSpace(), DropdbStmt::dbname, DeallocateQuery(), DefineSavepoint(), DefElem::defname, DiscardCommand(), ReindexStmt::do_system, ReindexStmt::do_user, DoCopy(), dropdb(), DropRole(), DropTableSpace(), elog, EndTransactionBlock(), ereport, errcode(), errmsg(), ERROR, EventTriggerSupportsObjectType(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecDropStmt(), ExecRenameStmt(), ExecSecLabelStmt(), ExecSetVariableStmt(), ExecuteDoStmt(), ExecuteGrantStmt(), ExecuteQuery(), ExecuteTruncate(), ExplainQuery(), LoadStmt::filename, FinishPreparedTransaction(), GetPGVariable(), TransactionStmt::gid, GrantRole(), InvalidOid, IsA, ReindexStmt::kind, TransactionStmt::kind, lfirst, list_make1, load_file(), LockTableCommand(), DropdbStmt::missing_ok, ReindexStmt::name, VariableShowStmt::name, name, nodeTag, NULL, OBJECT_DATABASE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_TABLE, AlterOwnerStmt::objectType, AlterObjectSchemaStmt::objectType, VacuumStmt::options, TransactionStmt::options, NotifyStmt::payload, PerformCursorOpen(), PerformPortalClose(), PerformPortalFetch(), PointerIsValid, ClosePortalStmt::portalname, PrepareQuery(), PrepareTransactionBlock(), PreventCommandDuringRecovery(), PreventTransactionChain(), ProcessUtilitySlow(), ReassignOwnedObjects(), RecoveryInProgress(), ReindexDatabase(), ReindexIndex(), ReindexTable(), ReindexStmt::relation, ReleaseSavepoint(), DropStmt::removeType, RenameStmt::renameType, RequestCheckpoint(), RequireTransactionChain(), RollbackToSavepoint(), SetPGVariable(), snprintf(), strVal, superuser(), T_AlterDatabaseSetStmt, T_AlterDatabaseStmt, T_AlterEventTrigStmt, T_AlterObjectSchemaStmt, T_AlterOwnerStmt, T_AlterRoleSetStmt, T_AlterRoleStmt, T_AlterTableSpaceOptionsStmt, T_CheckPointStmt, T_ClosePortalStmt, T_ClusterStmt, T_CommentStmt, T_ConstraintsSetStmt, T_CopyStmt, T_CreatedbStmt, T_CreateEventTrigStmt, T_CreateRoleStmt, T_CreateTableSpaceStmt, T_DeallocateStmt, 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_PlannedStmt, 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, UserAbortTransactionBlock(), PlannedStmt::utilityStmt, VACOPT_VACUUM, and vacuum().

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

{
    bool        isTopLevel = (context == PROCESS_UTILITY_TOPLEVEL);

    check_xact_readonly(parsetree);

    if (completionTag)
        completionTag[0] = '\0';

    switch (nodeTag(parsetree))
    {
            /*
             * ******************** transactions ********************
             */
        case T_TransactionStmt:
            {
                TransactionStmt *stmt = (TransactionStmt *) parsetree;

                switch (stmt->kind)
                {
                        /*
                         * START TRANSACTION, as defined by SQL99: Identical
                         * to BEGIN.  Same code for both.
                         */
                    case TRANS_STMT_BEGIN:
                    case TRANS_STMT_START:
                        {
                            ListCell   *lc;

                            BeginTransactionBlock();
                            foreach(lc, stmt->options)
                            {
                                DefElem    *item = (DefElem *) lfirst(lc);

                                if (strcmp(item->defname, "transaction_isolation") == 0)
                                    SetPGVariable("transaction_isolation",
                                                  list_make1(item->arg),
                                                  true);
                                else if (strcmp(item->defname, "transaction_read_only") == 0)
                                    SetPGVariable("transaction_read_only",
                                                  list_make1(item->arg),
                                                  true);
                                else if (strcmp(item->defname, "transaction_deferrable") == 0)
                                    SetPGVariable("transaction_deferrable",
                                                  list_make1(item->arg),
                                                  true);
                            }
                        }
                        break;

                    case TRANS_STMT_COMMIT:
                        if (!EndTransactionBlock())
                        {
                            /* report unsuccessful commit in completionTag */
                            if (completionTag)
                                strcpy(completionTag, "ROLLBACK");
                        }
                        break;

                    case TRANS_STMT_PREPARE:
                        PreventCommandDuringRecovery("PREPARE TRANSACTION");
                        if (!PrepareTransactionBlock(stmt->gid))
                        {
                            /* report unsuccessful commit in completionTag */
                            if (completionTag)
                                strcpy(completionTag, "ROLLBACK");
                        }
                        break;

                    case TRANS_STMT_COMMIT_PREPARED:
                        PreventTransactionChain(isTopLevel, "COMMIT PREPARED");
                        PreventCommandDuringRecovery("COMMIT PREPARED");
                        FinishPreparedTransaction(stmt->gid, true);
                        break;

                    case TRANS_STMT_ROLLBACK_PREPARED:
                        PreventTransactionChain(isTopLevel, "ROLLBACK PREPARED");
                        PreventCommandDuringRecovery("ROLLBACK PREPARED");
                        FinishPreparedTransaction(stmt->gid, false);
                        break;

                    case TRANS_STMT_ROLLBACK:
                        UserAbortTransactionBlock();
                        break;

                    case TRANS_STMT_SAVEPOINT:
                        {
                            ListCell   *cell;
                            char       *name = NULL;

                            RequireTransactionChain(isTopLevel, "SAVEPOINT");

                            foreach(cell, stmt->options)
                            {
                                DefElem    *elem = lfirst(cell);

                                if (strcmp(elem->defname, "savepoint_name") == 0)
                                    name = strVal(elem->arg);
                            }

                            Assert(PointerIsValid(name));

                            DefineSavepoint(name);
                        }
                        break;

                    case TRANS_STMT_RELEASE:
                        RequireTransactionChain(isTopLevel, "RELEASE SAVEPOINT");
                        ReleaseSavepoint(stmt->options);
                        break;

                    case TRANS_STMT_ROLLBACK_TO:
                        RequireTransactionChain(isTopLevel, "ROLLBACK TO SAVEPOINT");
                        RollbackToSavepoint(stmt->options);

                        /*
                         * CommitTransactionCommand is in charge of
                         * re-defining the savepoint again
                         */
                        break;
                }
            }
            break;

            /*
             * Portal (cursor) manipulation
             *
             * Note: DECLARE CURSOR is processed mostly as a SELECT, and
             * therefore what we will get here is a PlannedStmt not a bare
             * DeclareCursorStmt.
             */
        case T_PlannedStmt:
            {
                PlannedStmt *stmt = (PlannedStmt *) parsetree;

                if (stmt->utilityStmt == NULL ||
                    !IsA(stmt->utilityStmt, DeclareCursorStmt))
                    elog(ERROR, "non-DECLARE CURSOR PlannedStmt passed to ProcessUtility");
                PerformCursorOpen(stmt, params, queryString, isTopLevel);
            }
            break;

        case T_ClosePortalStmt:
            {
                ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;

                CheckRestrictedOperation("CLOSE");
                PerformPortalClose(stmt->portalname);
            }
            break;

        case T_FetchStmt:
            PerformPortalFetch((FetchStmt *) parsetree, dest,
                               completionTag);
            break;

        case T_DoStmt:
            ExecuteDoStmt((DoStmt *) parsetree);
            break;

        case T_CreateTableSpaceStmt:
            /* no event triggers for global objects */
            PreventTransactionChain(isTopLevel, "CREATE TABLESPACE");
            CreateTableSpace((CreateTableSpaceStmt *) parsetree);
            break;

        case T_DropTableSpaceStmt:
            /* no event triggers for global objects */
            PreventTransactionChain(isTopLevel, "DROP TABLESPACE");
            DropTableSpace((DropTableSpaceStmt *) parsetree);
            break;

        case T_AlterTableSpaceOptionsStmt:
            /* no event triggers for global objects */
            AlterTableSpaceOptions((AlterTableSpaceOptionsStmt *) parsetree);
            break;

        case T_TruncateStmt:
            ExecuteTruncate((TruncateStmt *) parsetree);
            break;

        case T_CommentStmt:
            CommentObject((CommentStmt *) parsetree);
            break;

        case T_SecLabelStmt:
            ExecSecLabelStmt((SecLabelStmt *) parsetree);
            break;

        case T_CopyStmt:
            {
                uint64      processed;

                DoCopy((CopyStmt *) parsetree, queryString, &processed);
                if (completionTag)
                    snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
                             "COPY " UINT64_FORMAT, processed);
            }
            break;

        case T_PrepareStmt:
            CheckRestrictedOperation("PREPARE");
            PrepareQuery((PrepareStmt *) parsetree, queryString);
            break;

        case T_ExecuteStmt:
            ExecuteQuery((ExecuteStmt *) parsetree, NULL,
                         queryString, params,
                         dest, completionTag);
            break;

        case T_DeallocateStmt:
            CheckRestrictedOperation("DEALLOCATE");
            DeallocateQuery((DeallocateStmt *) parsetree);
            break;

        case T_GrantStmt:
            /* no event triggers for global objects */
            ExecuteGrantStmt((GrantStmt *) parsetree);
            break;

        case T_GrantRoleStmt:
            /* no event triggers for global objects */
            GrantRole((GrantRoleStmt *) parsetree);
            break;

        case T_CreatedbStmt:
            /* no event triggers for global objects */
            PreventTransactionChain(isTopLevel, "CREATE DATABASE");
            createdb((CreatedbStmt *) parsetree);
            break;

        case T_AlterDatabaseStmt:
            /* no event triggers for global objects */
            AlterDatabase((AlterDatabaseStmt *) parsetree, isTopLevel);
            break;

        case T_AlterDatabaseSetStmt:
            /* no event triggers for global objects */
            AlterDatabaseSet((AlterDatabaseSetStmt *) parsetree);
            break;

        case T_DropdbStmt:
            {
                DropdbStmt *stmt = (DropdbStmt *) parsetree;

                /* no event triggers for global objects */
                PreventTransactionChain(isTopLevel, "DROP DATABASE");
                dropdb(stmt->dbname, stmt->missing_ok);
            }
            break;

            /* Query-level asynchronous notification */
        case T_NotifyStmt:
            {
                NotifyStmt *stmt = (NotifyStmt *) parsetree;

                PreventCommandDuringRecovery("NOTIFY");
                Async_Notify(stmt->conditionname, stmt->payload);
            }
            break;

        case T_ListenStmt:
            {
                ListenStmt *stmt = (ListenStmt *) parsetree;

                PreventCommandDuringRecovery("LISTEN");
                CheckRestrictedOperation("LISTEN");
                Async_Listen(stmt->conditionname);
            }
            break;

        case T_UnlistenStmt:
            {
                UnlistenStmt *stmt = (UnlistenStmt *) parsetree;

                PreventCommandDuringRecovery("UNLISTEN");
                CheckRestrictedOperation("UNLISTEN");
                if (stmt->conditionname)
                    Async_Unlisten(stmt->conditionname);
                else
                    Async_UnlistenAll();
            }
            break;

        case T_LoadStmt:
            {
                LoadStmt   *stmt = (LoadStmt *) parsetree;

                closeAllVfds(); /* probably not necessary... */
                /* Allowed names are restricted if you're not superuser */
                load_file(stmt->filename, !superuser());
            }
            break;

        case T_ClusterStmt:
            /* we choose to allow this during "read only" transactions */
            PreventCommandDuringRecovery("CLUSTER");
            cluster((ClusterStmt *) parsetree, isTopLevel);
            break;

        case T_VacuumStmt:
            {
                VacuumStmt *stmt = (VacuumStmt *) parsetree;

                /* we choose to allow this during "read only" transactions */
                PreventCommandDuringRecovery((stmt->options & VACOPT_VACUUM) ?
                                             "VACUUM" : "ANALYZE");
                vacuum(stmt, InvalidOid, true, NULL, false, isTopLevel);
            }
            break;

        case T_ExplainStmt:
            ExplainQuery((ExplainStmt *) parsetree, queryString, params, dest);
            break;

        case T_VariableSetStmt:
            ExecSetVariableStmt((VariableSetStmt *) parsetree);
            break;

        case T_VariableShowStmt:
            {
                VariableShowStmt *n = (VariableShowStmt *) parsetree;

                GetPGVariable(n->name, dest);
            }
            break;

        case T_DiscardStmt:
            /* should we allow DISCARD PLANS? */
            CheckRestrictedOperation("DISCARD");
            DiscardCommand((DiscardStmt *) parsetree, isTopLevel);
            break;

        case T_CreateEventTrigStmt:
            /* no event triggers on event triggers */
            CreateEventTrigger((CreateEventTrigStmt *) parsetree);
            break;

        case T_AlterEventTrigStmt:
            /* no event triggers on event triggers */
            AlterEventTrigger((AlterEventTrigStmt *) parsetree);
            break;

            /*
             * ******************************** ROLE statements ****
             */
        case T_CreateRoleStmt:
            /* no event triggers for global objects */
            CreateRole((CreateRoleStmt *) parsetree);
            break;

        case T_AlterRoleStmt:
            /* no event triggers for global objects */
            AlterRole((AlterRoleStmt *) parsetree);
            break;

        case T_AlterRoleSetStmt:
            /* no event triggers for global objects */
            AlterRoleSet((AlterRoleSetStmt *) parsetree);
            break;

        case T_DropRoleStmt:
            /* no event triggers for global objects */
            DropRole((DropRoleStmt *) parsetree);
            break;

        case T_ReassignOwnedStmt:
            /* no event triggers for global objects */
            ReassignOwnedObjects((ReassignOwnedStmt *) parsetree);
            break;

        case T_LockStmt:

            /*
             * Since the lock would just get dropped immediately, LOCK TABLE
             * outside a transaction block is presumed to be user error.
             */
            RequireTransactionChain(isTopLevel, "LOCK TABLE");
            LockTableCommand((LockStmt *) parsetree);
            break;

        case T_ConstraintsSetStmt:
            AfterTriggerSetState((ConstraintsSetStmt *) parsetree);
            break;

        case T_CheckPointStmt:
            if (!superuser())
                ereport(ERROR,
                        (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
                         errmsg("must be superuser to do CHECKPOINT")));

            /*
             * You might think we should have a PreventCommandDuringRecovery()
             * here, but we interpret a CHECKPOINT command during recovery as
             * a request for a restartpoint instead. We allow this since it
             * can be a useful way of reducing switchover time when using
             * various forms of replication.
             */
            RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_WAIT |
                              (RecoveryInProgress() ? 0 : CHECKPOINT_FORCE));
            break;

        case T_ReindexStmt:
            {
                ReindexStmt *stmt = (ReindexStmt *) parsetree;

                /* we choose to allow this during "read only" transactions */
                PreventCommandDuringRecovery("REINDEX");
                switch (stmt->kind)
                {
                    case OBJECT_INDEX:
                        ReindexIndex(stmt->relation);
                        break;
                    case OBJECT_TABLE:
                    case OBJECT_MATVIEW:
                        ReindexTable(stmt->relation);
                        break;
                    case OBJECT_DATABASE:

                        /*
                         * This cannot run inside a user transaction block; if
                         * we were inside a transaction, then its commit- and
                         * start-transaction-command calls would not have the
                         * intended effect!
                         */
                        PreventTransactionChain(isTopLevel,
                                                "REINDEX DATABASE");
                        ReindexDatabase(stmt->name,
                                        stmt->do_system, stmt->do_user);
                        break;
                    default:
                        elog(ERROR, "unrecognized object type: %d",
                             (int) stmt->kind);
                        break;
                }
            }
            break;

            /*
             * The following statements are supported by Event Triggers only
             * in some cases, so we "fast path" them in the other cases.
             */

        case T_DropStmt:
            {
                DropStmt   *stmt = (DropStmt *) parsetree;

                if (EventTriggerSupportsObjectType(stmt->removeType))
                    ProcessUtilitySlow(parsetree, queryString,
                                       context, params,
                                       dest, completionTag);
                else
                    ExecDropStmt(stmt, isTopLevel);
            }
            break;

        case T_RenameStmt:
            {
                RenameStmt *stmt = (RenameStmt *) parsetree;

                if (EventTriggerSupportsObjectType(stmt->renameType))
                    ProcessUtilitySlow(parsetree, queryString,
                                       context, params,
                                       dest, completionTag);
                else
                    ExecRenameStmt(stmt);
            }
            break;

        case T_AlterObjectSchemaStmt:
            {
                AlterObjectSchemaStmt *stmt = (AlterObjectSchemaStmt *) parsetree;

                if (EventTriggerSupportsObjectType(stmt->objectType))
                    ProcessUtilitySlow(parsetree, queryString,
                                       context, params,
                                       dest, completionTag);
                else
                    ExecAlterObjectSchemaStmt(stmt);
            }
            break;

        case T_AlterOwnerStmt:
            {
                AlterOwnerStmt *stmt = (AlterOwnerStmt *) parsetree;

                if (EventTriggerSupportsObjectType(stmt->objectType))
                    ProcessUtilitySlow(parsetree, queryString,
                                       context, params,
                                       dest, completionTag);
                else
                    ExecAlterOwnerStmt(stmt);
            }
            break;

        default:
            /* All other statement types have event trigger support */
            ProcessUtilitySlow(parsetree, queryString,
                               context, params,
                               dest, completionTag);
            break;
    }
}

Query* UtilityContainsQuery ( Node parsetree  ) 

Definition at line 1533 of file utility.c.

References Assert, CMD_UTILITY, Query::commandType, IsA, nodeTag, T_CreateTableAsStmt, T_ExplainStmt, UtilityContainsQuery(), and Query::utilityStmt.

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

{
    Query      *qry;

    switch (nodeTag(parsetree))
    {
        case T_ExplainStmt:
            qry = (Query *) ((ExplainStmt *) parsetree)->query;
            Assert(IsA(qry, Query));
            if (qry->commandType == CMD_UTILITY)
                return UtilityContainsQuery(qry->utilityStmt);
            return qry;

        case T_CreateTableAsStmt:
            qry = (Query *) ((CreateTableAsStmt *) parsetree)->query;
            Assert(IsA(qry, Query));
            if (qry->commandType == CMD_UTILITY)
                return UtilityContainsQuery(qry->utilityStmt);
            return qry;

        default:
            return NULL;
    }
}

bool UtilityReturnsTuples ( Node parsetree  ) 

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

Referenced by ChoosePortalStrategy().

{
    switch (nodeTag(parsetree))
    {
        case T_FetchStmt:
            {
                FetchStmt  *stmt = (FetchStmt *) parsetree;
                Portal      portal;

                if (stmt->ismove)
                    return false;
                portal = GetPortalByName(stmt->portalname);
                if (!PortalIsValid(portal))
                    return false;       /* not our business to raise error */
                return portal->tupDesc ? true : false;
            }

        case T_ExecuteStmt:
            {
                ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
                PreparedStatement *entry;

                entry = FetchPreparedStatement(stmt->name, false);
                if (!entry)
                    return false;       /* not our business to raise error */
                if (entry->plansource->resultDesc)
                    return true;
                return false;
            }

        case T_ExplainStmt:
            return true;

        case T_VariableShowStmt:
            return true;

        default:
            return false;
    }
}

TupleDesc UtilityTupleDescriptor ( Node parsetree  ) 

Definition at line 1440 of file utility.c.

References CreateTupleDescCopy(), ExplainResultDesc(), FetchPreparedStatement(), FetchPreparedStatementResultDesc(), GetPGVariableResultDesc(), GetPortalByName(), FetchStmt::ismove, VariableShowStmt::name, ExecuteStmt::name, nodeTag, PortalIsValid, FetchStmt::portalname, T_ExecuteStmt, T_ExplainStmt, T_FetchStmt, T_VariableShowStmt, and PortalData::tupDesc.

Referenced by PlanCacheComputeResultDesc(), and PortalStart().

{
    switch (nodeTag(parsetree))
    {
        case T_FetchStmt:
            {
                FetchStmt  *stmt = (FetchStmt *) parsetree;
                Portal      portal;

                if (stmt->ismove)
                    return NULL;
                portal = GetPortalByName(stmt->portalname);
                if (!PortalIsValid(portal))
                    return NULL;    /* not our business to raise error */
                return CreateTupleDescCopy(portal->tupDesc);
            }

        case T_ExecuteStmt:
            {
                ExecuteStmt *stmt = (ExecuteStmt *) parsetree;
                PreparedStatement *entry;

                entry = FetchPreparedStatement(stmt->name, false);
                if (!entry)
                    return NULL;    /* not our business to raise error */
                return FetchPreparedStatementResultDesc(entry);
            }

        case T_ExplainStmt:
            return ExplainResultDesc((ExplainStmt *) parsetree);

        case T_VariableShowStmt:
            {
                VariableShowStmt *n = (VariableShowStmt *) parsetree;

                return GetPGVariableResultDesc(n->name);
            }

        default:
            return NULL;
    }
}


Variable Documentation

Definition at line 69 of file utility.c.

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