Skip to content

Commit

Permalink
planner: DELETE cannot delete data in some cases when the database …
Browse files Browse the repository at this point in the history
…name is capitalized (#21202) (#21205)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
ti-srebot authored Nov 23, 2020
1 parent 2dbe7b2 commit 67446a8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
39 changes: 39 additions & 0 deletions executor/delete_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package executor_test

import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/util/testkit"
)

func (s *testSuite4) TestIssue21200(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("drop database if exists TEST1")
tk.MustExec("create database TEST1")
tk.MustExec("use TEST1")
tk.MustExec("create table t(a int)")
tk.MustExec("create table t1(a int)")
tk.MustExec("insert into t values(1)")
tk.MustExec("insert into t1 values(1)")
tk.MustExec("delete a from t a where exists (select 1 from t1 where t1.a=a.a)")
tk.MustQuery("select * from t").Check(testkit.Rows())

tk.MustExec("insert into t values(1), (2)")
tk.MustExec("insert into t1 values(2)")
tk.MustExec("prepare stmt from 'delete a from t a where exists (select 1 from t1 where a.a=t1.a and t1.a=?)'")
tk.MustExec("set @a=1")
tk.MustExec("execute stmt using @a")
tk.MustQuery("select * from t").Check(testkit.Rows("2"))
}
10 changes: 5 additions & 5 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3005,12 +3005,12 @@ func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) (
for _, tn := range delete.Tables.Tables {
foundMatch := false
for _, v := range tableList {
dbName := v.Schema.L
if dbName == "" {
dbName = b.ctx.GetSessionVars().CurrentDB
dbName := v.Schema
if dbName.L == "" {
dbName = model.NewCIStr(b.ctx.GetSessionVars().CurrentDB)
}
if (tn.Schema.L == "" || tn.Schema.L == dbName) && tn.Name.L == v.Name.L {
tn.Schema.L = dbName
if (tn.Schema.L == "" || tn.Schema.L == dbName.L) && tn.Name.L == v.Name.L {
tn.Schema = dbName
tn.DBInfo = v.DBInfo
tn.TableInfo = v.TableInfo
foundMatch = true
Expand Down

0 comments on commit 67446a8

Please sign in to comment.