From f00fe4db0c2b52c61aa9bd1e8a7fd8915b5e63e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 21 Apr 2025 04:42:58 +0200 Subject: [PATCH] planner: drop procedure (#60670) close pingcap/tidb#60669 --- errors.toml | 5 +++++ pkg/planner/core/planbuilder.go | 11 +++++++++-- pkg/util/dbterror/plannererrors/planner_terror.go | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/errors.toml b/errors.toml index 4288cef08d..c5ab38e8de 100644 --- a/errors.toml +++ b/errors.toml @@ -2406,6 +2406,11 @@ error = ''' The target table %-.100s of the %s is not updatable ''' +["planner:1305"] +error = ''' +%s %s does not exist +''' + ["planner:1345"] error = ''' EXPLAIN/SHOW can not be issued; lacking privileges for underlying table diff --git a/pkg/planner/core/planbuilder.go b/pkg/planner/core/planbuilder.go index c376c4ce19..17626dff72 100644 --- a/pkg/planner/core/planbuilder.go +++ b/pkg/planner/core/planbuilder.go @@ -559,7 +559,7 @@ func (b *PlanBuilder) Build(ctx context.Context, node *resolve.NodeW) (base.Plan *ast.GrantStmt, *ast.DropUserStmt, *ast.AlterUserStmt, *ast.AlterRangeStmt, *ast.RevokeStmt, *ast.KillStmt, *ast.DropStatsStmt, *ast.GrantRoleStmt, *ast.RevokeRoleStmt, *ast.SetRoleStmt, *ast.SetDefaultRoleStmt, *ast.ShutdownStmt, *ast.RenameUserStmt, *ast.NonTransactionalDMLStmt, *ast.SetSessionStatesStmt, *ast.SetResourceGroupStmt, - *ast.ImportIntoActionStmt, *ast.CalibrateResourceStmt, *ast.AddQueryWatchStmt, *ast.DropQueryWatchStmt: + *ast.ImportIntoActionStmt, *ast.CalibrateResourceStmt, *ast.AddQueryWatchStmt, *ast.DropQueryWatchStmt, *ast.DropProcedureStmt: return b.buildSimple(ctx, node.Node.(ast.StmtNode)) case ast.DDLNode: return b.buildDDL(ctx, x) @@ -580,7 +580,7 @@ func (b *PlanBuilder) Build(ctx context.Context, node *resolve.NodeW) (base.Plan case *ast.RecommendIndexStmt: return b.buildRecommendIndex(x) } - return nil, plannererrors.ErrUnsupportedType.GenWithStack("Unsupported type %T", node) + return nil, plannererrors.ErrUnsupportedType.GenWithStack("Unsupported type %T", node.Node) } func (b *PlanBuilder) buildSetConfig(ctx context.Context, v *ast.SetConfigStmt) (base.Plan, error) { @@ -3752,6 +3752,13 @@ func (b *PlanBuilder) buildSimple(ctx context.Context, node ast.StmtNode) (base. err := plannererrors.ErrSpecificAccessDenied.GenWithStackByArgs("SUPER or RESOURCE_GROUP_ADMIN or RESOURCE_GROUP_USER") b.visitInfo = appendDynamicVisitInfo(b.visitInfo, []string{"RESOURCE_GROUP_ADMIN", "RESOURCE_GROUP_USER"}, false, err) } + case *ast.DropProcedureStmt: + procName := fmt.Sprintf("%s.%s", ast.NewCIStr(b.ctx.GetSessionVars().CurrentDB).O, raw.ProcedureName.Name.O) + err := plannererrors.ErrSpDoesNotExist.GenWithStackByArgs("PROCEDURE", procName) + if !raw.IfExists { + return nil, err + } + b.ctx.GetSessionVars().StmtCtx.AppendNote(err) } return p, nil } diff --git a/pkg/util/dbterror/plannererrors/planner_terror.go b/pkg/util/dbterror/plannererrors/planner_terror.go index 8bfb79be77..95fbaeba14 100644 --- a/pkg/util/dbterror/plannererrors/planner_terror.go +++ b/pkg/util/dbterror/plannererrors/planner_terror.go @@ -120,4 +120,5 @@ var ( ErrPrepareDDL = dbterror.ClassExecutor.NewStd(mysql.ErrPrepareDDL) ErrRowIsReferenced2 = dbterror.ClassOptimizer.NewStd(mysql.ErrRowIsReferenced2) ErrNoReferencedRow2 = dbterror.ClassOptimizer.NewStd(mysql.ErrNoReferencedRow2) + ErrSpDoesNotExist = dbterror.ClassOptimizer.NewStd(mysql.ErrSpDoesNotExist) )