Skip to content

Commit

Permalink
cherry pick pingcap#26905 to release-5.1
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
morgo authored and ti-srebot committed Aug 19, 2021
1 parent 09d3925 commit 330faf6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,13 @@ func (cc *clientConn) prefetchPointPlanKeys(ctx context.Context, stmts []ast.Stm
var rowKeys []kv.Key
sc := vars.StmtCtx
for i, stmt := range stmts {
switch stmt.(type) {
case *ast.UseStmt:
// If there is a "use db" statement, we shouldn't cache even if it's possible.
// Consider the scenario where there are statements that could execute on multiple
// schemas, but the schema is actually different.
return nil, nil
}
// TODO: the preprocess is run twice, we should find some way to avoid do it again.
// TODO: handle the PreprocessorReturn.
if err = plannercore.Preprocess(cc.ctx, stmt); err != nil {
Expand Down
19 changes: 19 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,25 @@ func (cli *testServerClient) runTestMultiStatements(c *C) {
} else {
dbt.Error("no data")
}

// Test issue #26688
// First we "reset" the CurrentDB by using a database and then dropping it.
dbt.mustExec("CREATE DATABASE dropme")
dbt.mustExec("USE dropme")
dbt.mustExec("DROP DATABASE dropme")
var usedb string
rows = dbt.mustQuery("SELECT IFNULL(DATABASE(),'success')")
if rows.Next() {
err = rows.Scan(&usedb)
c.Assert(err, IsNil)
c.Assert(usedb, Equals, "success")
} else {
dbt.Error("no database() result")
}
// Because no DB is selected, if the use multistmtuse is not successful, then
// the create table + drop table statements will return errors.
dbt.mustExec("CREATE DATABASE multistmtuse")
dbt.mustExec("use multistmtuse; create table if not exists t1 (id int); drop table t1;")
})
}

Expand Down

0 comments on commit 330faf6

Please sign in to comment.