diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-02-26 22:47:12 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-02-26 22:47:12 +0000 |
commit | 56ee2ecba96a742bb6e18dfe8ee48054e90ebaa9 (patch) | |
tree | 905c72dc3db475d47d04472a1de7ab715b5725c7 /src/backend/tcop/utility.c | |
parent | f71dc6d0e28a855f2d782ec48f950ffeaca1307d (diff) | |
download | postgresql-56ee2ecba96a742bb6e18dfe8ee48054e90ebaa9.tar.gz postgresql-56ee2ecba96a742bb6e18dfe8ee48054e90ebaa9.zip |
Restructure command-completion-report code so that there is just one
report for each received SQL command, regardless of rewriting activity.
Also ensure that this report comes from the 'original' command, not the
last command generated by rewrite; this fixes 7.2 breakage for INSERT
commands that have actions added by rules. Fernando Nasser and Tom Lane.
Diffstat (limited to 'src/backend/tcop/utility.c')
-rw-r--r-- | src/backend/tcop/utility.c | 130 |
1 files changed, 21 insertions, 109 deletions
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index f80a6bdca44..a6a8b561e02 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.126 2002/02/24 20:20:20 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.127 2002/02/26 22:47:09 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -44,7 +44,6 @@ #include "rewrite/rewriteRemove.h" #include "tcop/utility.h" #include "utils/acl.h" -#include "utils/ps_status.h" #include "utils/syscache.h" #include "utils/temprel.h" #include "access/xlog.h" @@ -130,18 +129,31 @@ CheckDropPermissions(char *name, char rightkind) } -/* ---------------- +/* + * ProcessUtility * general utility function invoker - * ---------------- + * + * parsetree: the parse tree for the utility statement + * dest: where to send results + * completionTag: points to a buffer of size COMPLETION_TAG_BUFSIZE + * in which to store a command completion status string. + * + * completionTag is only set nonempty if we want to return a nondefault + * status (currently, only used for MOVE/FETCH). + * + * completionTag may be NULL if caller doesn't want a status string. */ void ProcessUtility(Node *parsetree, - CommandDest dest) + CommandDest dest, + char *completionTag) { - char *commandTag = NULL; char *relname; char *relationName; + if (completionTag) + completionTag[0] = '\0'; + switch (nodeTag(parsetree)) { /* @@ -155,17 +167,14 @@ ProcessUtility(Node *parsetree, switch (stmt->command) { case BEGIN_TRANS: - set_ps_display(commandTag = "BEGIN"); BeginTransactionBlock(); break; case COMMIT: - set_ps_display(commandTag = "COMMIT"); EndTransactionBlock(); break; case ROLLBACK: - set_ps_display(commandTag = "ROLLBACK"); UserAbortTransactionBlock(); break; } @@ -180,8 +189,6 @@ ProcessUtility(Node *parsetree, { ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree; - set_ps_display(commandTag = "CLOSE"); - PerformPortalClose(stmt->portalname, dest); } break; @@ -193,8 +200,6 @@ ProcessUtility(Node *parsetree, bool forward; int count; - set_ps_display(commandTag = (stmt->ismove) ? "MOVE" : "FETCH"); - SetQuerySnapshot(); forward = (bool) (stmt->direction == FORWARD); @@ -204,8 +209,9 @@ ProcessUtility(Node *parsetree, */ count = stmt->howMany; - PerformPortalFetch(portalName, forward, count, commandTag, - (stmt->ismove) ? None : dest); /* /dev/null for MOVE */ + PerformPortalFetch(portalName, forward, count, + (stmt->ismove) ? None : dest, + completionTag); } break; @@ -215,8 +221,6 @@ ProcessUtility(Node *parsetree, * */ case T_CreateStmt: - set_ps_display(commandTag = "CREATE"); - DefineRelation((CreateStmt *) parsetree, RELKIND_RELATION); /* @@ -234,8 +238,6 @@ ProcessUtility(Node *parsetree, List *args = stmt->names; List *arg; - set_ps_display(commandTag = "DROP"); - foreach(arg, args) { relname = strVal(lfirst(arg)); @@ -296,8 +298,6 @@ ProcessUtility(Node *parsetree, { Relation rel; - set_ps_display(commandTag = "TRUNCATE"); - relname = ((TruncateStmt *) parsetree)->relName; if (!allowSystemTableMods && IsSystemRelationName(relname)) elog(ERROR, "TRUNCATE cannot be used on system tables. '%s' is a system table", @@ -325,8 +325,6 @@ ProcessUtility(Node *parsetree, statement = ((CommentStmt *) parsetree); - set_ps_display(commandTag = "COMMENT"); - CommentObject(statement->objtype, statement->objname, statement->objproperty, statement->objlist, statement->comment); @@ -337,8 +335,6 @@ ProcessUtility(Node *parsetree, { CopyStmt *stmt = (CopyStmt *) parsetree; - set_ps_display(commandTag = "COPY"); - if (stmt->direction != FROM) SetQuerySnapshot(); @@ -365,8 +361,6 @@ ProcessUtility(Node *parsetree, { RenameStmt *stmt = (RenameStmt *) parsetree; - set_ps_display(commandTag = "ALTER"); - relname = stmt->relname; if (!allowSystemTableMods && IsSystemRelationName(relname)) elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog", @@ -413,8 +407,6 @@ ProcessUtility(Node *parsetree, { AlterTableStmt *stmt = (AlterTableStmt *) parsetree; - set_ps_display(commandTag = "ALTER"); - /* * Some or all of these functions are recursive to cover * inherited things, so permission checks are done there. @@ -475,9 +467,6 @@ ProcessUtility(Node *parsetree, { GrantStmt *stmt = (GrantStmt *) parsetree; - commandTag = stmt->is_grant ? "GRANT" : "REVOKE"; - set_ps_display(commandTag); - ExecuteGrantStmt(stmt); } break; @@ -491,8 +480,6 @@ ProcessUtility(Node *parsetree, { DefineStmt *stmt = (DefineStmt *) parsetree; - set_ps_display(commandTag = "CREATE"); - switch (stmt->defType) { case OPERATOR: @@ -514,15 +501,11 @@ ProcessUtility(Node *parsetree, { ViewStmt *stmt = (ViewStmt *) parsetree; - set_ps_display(commandTag = "CREATE"); - DefineView(stmt->viewname, stmt->query); /* retrieve parsetree */ } break; case T_ProcedureStmt: /* CREATE FUNCTION */ - set_ps_display(commandTag = "CREATE"); - CreateFunction((ProcedureStmt *) parsetree); break; @@ -530,8 +513,6 @@ ProcessUtility(Node *parsetree, { IndexStmt *stmt = (IndexStmt *) parsetree; - set_ps_display(commandTag = "CREATE"); - relname = stmt->relname; if (!allowSystemTableMods && IsSystemRelationName(relname)) elog(ERROR, "CREATE INDEX: relation \"%s\" is a system catalog", @@ -559,15 +540,12 @@ ProcessUtility(Node *parsetree, aclcheck_result = pg_aclcheck(relname, GetUserId(), ACL_RULE); if (aclcheck_result != ACLCHECK_OK) elog(ERROR, "%s: %s", relname, aclcheck_error_strings[aclcheck_result]); - set_ps_display(commandTag = "CREATE"); DefineQueryRewrite(stmt); } break; case T_CreateSeqStmt: - set_ps_display(commandTag = "CREATE"); - DefineSequence((CreateSeqStmt *) parsetree); break; @@ -576,8 +554,6 @@ ProcessUtility(Node *parsetree, RemoveAggrStmt *stmt = (RemoveAggrStmt *) parsetree; char *typename = (char *) NULL; - set_ps_display(commandTag = "DROP"); - if (stmt->aggtype != NULL) typename = TypeNameToInternalName((TypeName *) stmt->aggtype); @@ -589,8 +565,6 @@ ProcessUtility(Node *parsetree, { RemoveFuncStmt *stmt = (RemoveFuncStmt *) parsetree; - set_ps_display(commandTag = "DROP"); - RemoveFunction(stmt->funcname, stmt->args); } break; @@ -603,8 +577,6 @@ ProcessUtility(Node *parsetree, char *typename1 = (char *) NULL; char *typename2 = (char *) NULL; - set_ps_display(commandTag = "DROP"); - if (typenode1 != NULL) typename1 = TypeNameToInternalName(typenode1); if (typenode2 != NULL) @@ -622,8 +594,6 @@ ProcessUtility(Node *parsetree, { CreatedbStmt *stmt = (CreatedbStmt *) parsetree; - set_ps_display(commandTag = "CREATE DATABASE"); - createdb(stmt->dbname, stmt->dbowner, stmt->dbpath, stmt->dbtemplate, stmt->encoding); @@ -634,8 +604,6 @@ ProcessUtility(Node *parsetree, { DropdbStmt *stmt = (DropdbStmt *) parsetree; - set_ps_display(commandTag = "DROP DATABASE"); - dropdb(stmt->dbname); } break; @@ -645,8 +613,6 @@ ProcessUtility(Node *parsetree, { NotifyStmt *stmt = (NotifyStmt *) parsetree; - set_ps_display(commandTag = "NOTIFY"); - Async_Notify(stmt->relname); } break; @@ -655,8 +621,6 @@ ProcessUtility(Node *parsetree, { ListenStmt *stmt = (ListenStmt *) parsetree; - set_ps_display(commandTag = "LISTEN"); - Async_Listen(stmt->relname, MyProcPid); } break; @@ -665,8 +629,6 @@ ProcessUtility(Node *parsetree, { UnlistenStmt *stmt = (UnlistenStmt *) parsetree; - set_ps_display(commandTag = "UNLISTEN"); - Async_Unlisten(stmt->relname, MyProcPid); } break; @@ -679,8 +641,6 @@ ProcessUtility(Node *parsetree, { LoadStmt *stmt = (LoadStmt *) parsetree; - set_ps_display(commandTag = "LOAD"); - closeAllVfds(); /* probably not necessary... */ load_file(stmt->filename); } @@ -690,8 +650,6 @@ ProcessUtility(Node *parsetree, { ClusterStmt *stmt = (ClusterStmt *) parsetree; - set_ps_display(commandTag = "CLUSTER"); - relname = stmt->relname; if (IsSystemRelationName(relname)) elog(ERROR, "CLUSTER: relation \"%s\" is a system catalog", @@ -704,12 +662,6 @@ ProcessUtility(Node *parsetree, break; case T_VacuumStmt: - if (((VacuumStmt *) parsetree)->vacuum) - commandTag = "VACUUM"; - else - commandTag = "ANALYZE"; - set_ps_display(commandTag); - vacuum((VacuumStmt *) parsetree); break; @@ -717,8 +669,6 @@ ProcessUtility(Node *parsetree, { ExplainStmt *stmt = (ExplainStmt *) parsetree; - set_ps_display(commandTag = "EXPLAIN"); - ExplainQuery(stmt->query, stmt->verbose, stmt->analyze, dest); } break; @@ -732,8 +682,6 @@ ProcessUtility(Node *parsetree, { RecipeStmt *stmt = (RecipeStmt *) parsetree; - set_ps_display(commandTag = "EXECUTE RECIPE"); - beginRecipe(stmt); } break; @@ -747,7 +695,6 @@ ProcessUtility(Node *parsetree, VariableSetStmt *n = (VariableSetStmt *) parsetree; SetPGVariable(n->name, n->args); - set_ps_display(commandTag = "SET VARIABLE"); } break; @@ -756,7 +703,6 @@ ProcessUtility(Node *parsetree, VariableShowStmt *n = (VariableShowStmt *) parsetree; GetPGVariable(n->name); - set_ps_display(commandTag = "SHOW VARIABLE"); } break; @@ -765,7 +711,6 @@ ProcessUtility(Node *parsetree, VariableResetStmt *n = (VariableResetStmt *) parsetree; ResetPGVariable(n->name); - set_ps_display(commandTag = "RESET VARIABLE"); } break; @@ -773,14 +718,10 @@ ProcessUtility(Node *parsetree, * ******************************** TRIGGER statements ******************************* */ case T_CreateTrigStmt: - set_ps_display(commandTag = "CREATE"); - CreateTrigger((CreateTrigStmt *) parsetree); break; case T_DropTrigStmt: - set_ps_display(commandTag = "DROP"); - DropTrigger((DropTrigStmt *) parsetree); break; @@ -788,14 +729,10 @@ ProcessUtility(Node *parsetree, * ************* PROCEDURAL LANGUAGE statements ***************** */ case T_CreatePLangStmt: - set_ps_display(commandTag = "CREATE"); - CreateProceduralLanguage((CreatePLangStmt *) parsetree); break; case T_DropPLangStmt: - set_ps_display(commandTag = "DROP"); - DropProceduralLanguage((DropPLangStmt *) parsetree); break; @@ -804,57 +741,39 @@ ProcessUtility(Node *parsetree, * */ case T_CreateUserStmt: - set_ps_display(commandTag = "CREATE USER"); - CreateUser((CreateUserStmt *) parsetree); break; case T_AlterUserStmt: - set_ps_display(commandTag = "ALTER USER"); - AlterUser((AlterUserStmt *) parsetree); break; case T_DropUserStmt: - set_ps_display(commandTag = "DROP USER"); - DropUser((DropUserStmt *) parsetree); break; case T_LockStmt: - set_ps_display(commandTag = "LOCK TABLE"); - LockTableCommand((LockStmt *) parsetree); break; case T_ConstraintsSetStmt: - set_ps_display(commandTag = "SET CONSTRAINTS"); - DeferredTriggerSetState((ConstraintsSetStmt *) parsetree); break; case T_CreateGroupStmt: - set_ps_display(commandTag = "CREATE GROUP"); - CreateGroup((CreateGroupStmt *) parsetree); break; case T_AlterGroupStmt: - set_ps_display(commandTag = "ALTER GROUP"); - AlterGroup((AlterGroupStmt *) parsetree, "ALTER GROUP"); break; case T_DropGroupStmt: - set_ps_display(commandTag = "DROP GROUP"); - DropGroup((DropGroupStmt *) parsetree); break; case T_CheckPointStmt: { - set_ps_display(commandTag = "CHECKPOINT"); - if (!superuser()) elog(ERROR, "permission denied"); CreateCheckPoint(false); @@ -865,8 +784,6 @@ ProcessUtility(Node *parsetree, { ReindexStmt *stmt = (ReindexStmt *) parsetree; - set_ps_display(commandTag = "REINDEX"); - switch (stmt->reindexType) { case INDEX: @@ -912,9 +829,4 @@ ProcessUtility(Node *parsetree, nodeTag(parsetree)); break; } - - /* - * tell fe/be or whatever that we're done. - */ - EndCommand(commandTag, dest); } |