Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: use stmt should apply to subsequent stmts in multi-stmt mode (#26905) #27395

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,13 @@ func (cc *clientConn) prefetchPointPlanKeys(ctx context.Context, stmts []ast.Stm
is := domain.GetDomain(cc.ctx).InfoSchema()
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.
if err = plannercore.Preprocess(cc.ctx, stmt, is); err != nil {
return nil, err
Expand Down
19 changes: 19 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,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