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

query information_schema.tables will report table not exists #42003

Closed
xiongjiwei opened this issue Mar 8, 2023 · 3 comments · Fixed by #42027
Closed

query information_schema.tables will report table not exists #42003

xiongjiwei opened this issue Mar 8, 2023 · 3 comments · Fixed by #42027
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.3 affects-6.4 affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-6.6 severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@xiongjiwei
Copy link
Contributor

xiongjiwei commented Mar 8, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. create a table that contains an auto_increament column and then drop the table
  2. run query SELECT 1 FROM information_schema.tables

parallel run these two steps several times, you may get an error Table xxx doesn't exist

this is because

if hasAutoIncID {
autoIncID, err = getAutoIncrementID(sctx, schema, table)
if err != nil {
return err
}
}

getAutoIncrementID will use the newest schema that the table has been dropped.
sleep seconds at L687 will easier to reproduce this bug

similar with #41622

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

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

@xiongjiwei xiongjiwei added the type/bug The issue is confirmed as a bug. label Mar 8, 2023
@xiongjiwei xiongjiwei changed the title query information_schema.tables will reprot table not exists query information_schema.tables will report table not exists Mar 8, 2023
@tiancaiamao
Copy link
Contributor

A test script to reproduce, go run test.go and check whether the output is "Error 1146: Table 'test.xxx' doesn't exist"

package main

import (
        "database/sql"
        "flag"
        "fmt"
        _ "github.com/go-sql-driver/mysql"
)

func main() {
        var (
                host                        string
                port                        int
                user                        string
                passwd                      string
                dbname                      string
        )
        flag.StringVar(&host, "host", "127.0.0.1", "")
        flag.IntVar(&port, "port", 4000, "")
        flag.StringVar(&user, "user", "root", "")
        flag.StringVar(&passwd, "password", "", "")
        flag.StringVar(&dbname, "dbname", "test", "")
        flag.Parse()

        db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", user, passwd, host, port, dbname))
        if err != nil {
                panic(err)
        }
        if err := db.Ping(); err != nil {
                panic(err)
        }
        defer db.Close()


        go func() {
                for {
                        res, err := db.Query("SELECT 1 FROM information_schema.tables")
                        if err != nil {
                                fmt.Println(err)
                        }
                        if res != nil {
                                res.Close()
                        }
                }
        }()

        for {
                _, err := db.Exec("create table xxx (id int key auto_increment)")
                if err != nil {
                        panic("create table failed")
                }

                _, err = db.Exec("drop table xxx")
                if err != nil {
                        panic("drop table failed")
                }
        }
}

@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 labels Mar 9, 2023
@seiya-annie seiya-annie added affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.3 affects-6.4 affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-6.6 and removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-6.1 may-affects-6.5 labels Mar 9, 2023
@tiancaiamao
Copy link
Contributor

Introduced by http://github.com/pingcap/tidb/pull/24820

@xiongjiwei
Copy link
Contributor Author

maybe also the same root cause of #42007

@VelocityLight VelocityLight added affects-5.3 This bug affects 5.3.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. labels Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.3 affects-6.4 affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-6.6 severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants