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

different behavior between mysql and tidb about use clause in transaction #26688

Closed
darren opened this issue Jul 28, 2021 · 4 comments · Fixed by #26905
Closed

different behavior between mysql and tidb about use clause in transaction #26688

darren opened this issue Jul 28, 2021 · 4 comments · Fixed by #26905
Assignees

Comments

@darren
Copy link
Contributor

darren commented Jul 28, 2021

Bug Report

1. Minimal reproduce step (Required)

The actual problem comes from the syncer tool which is deprecated now, we have not switched to DM yet.

package main

import (
        "database/sql"
        "log"

        _ "github.com/go-sql-driver/mysql"
)

func main() {
        db, err := sql.Open("mysql", "root@tcp(127.0.0.1:4000)/?multiStatements=true")
        if err != nil {
                log.Fatalf("open mysql err: %s", err)
        }

        txn, err := db.Begin()
        if err != nil {
                log.Fatal(err)
        }

        _, err = txn.Exec("use test; create table if not exists t1 (id int); drop table t1;")
        if err != nil {
                log.Fatal(err)
        }

        err = txn.Commit()
        if err != nil {
                log.Fatal(err)
        }

        log.Print("OK")
}

2. What did you expect to see? (Required)

MariaDB(10.3.29) produces: OK

3. What did you see instead (Required)

TiDB(v5.1.0) produces :Error 1046: No database selected

4. What is your TiDB version? (Required)

Release Version: v5.1.0
Edition: Community
Git Commit Hash: 8acd5c8
Git Branch: release-5.1
UTC Build Time: 2021-07-28 04:40:26
GoVersion: go1.16.5
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false

@darren darren added the type/bug The issue is confirmed as a bug. label Jul 28, 2021
@yudongusa yudongusa added sig/sql-infra SIG: SQL Infra and removed sig/planner SIG: Planner labels Jul 28, 2021
@AilinKid
Copy link
Contributor

@morgo do you reckon that this may have something linked with multi statement switch?

@morgo
Copy link
Contributor

morgo commented Jul 30, 2021

@morgo do you reckon that this may have something linked with multi statement switch?

I don't think it is. In this case the user has explictly opted in to multi-statement, so the switch is non-applicable.

It looks like a different bug, where the use db command probably only applies to the next statement, and not the current group of statements. I would still classify it as a protocol bug though, and I can take a look.

@morgo morgo self-assigned this Jul 30, 2021
@morgo
Copy link
Contributor

morgo commented Jul 30, 2021

I can confirm this bug still exists in 3.0 and 4.0, so it has been present for some time.

@ti-srebot
Copy link
Contributor

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants