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

Multi-statements prefetchPointPlanKeys panic #50012

Closed
tangenta opened this issue Jan 3, 2024 · 1 comment · Fixed by #50037
Closed

Multi-statements prefetchPointPlanKeys panic #50012

tangenta opened this issue Jan 3, 2024 · 1 comment · Fixed by #50037

Comments

@tangenta
Copy link
Contributor

tangenta commented Jan 3, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

package main

import (
	"context"
	"database/sql"

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

func main() {
	db, err := sql.Open("mysql", "root@tcp(127.0.0.1:4000)/test")
	mustNil(err)
	defer db.Close()
	ctx := context.Background()
	conn, err := db.Conn(ctx)
	mustNil(err)
	defer conn.Close()
	_, err = conn.ExecContext(ctx, "SET tidb_multi_statement_mode='ON';")
	mustNil(err)
	_, err = conn.ExecContext(ctx, "drop table if exists t;")
	mustNil(err)
	_, err = conn.ExecContext(ctx, `CREATE TABLE t (
		a bigint(20),
		b int(10),
		PRIMARY KEY (b, a),
		UNIQUE KEY uk_a (a)
	  );
	  `)
	mustNil(err)

	_, err = conn.ExecContext(ctx, `insert into t values (1, 1);`)
	mustNil(err)

	_, err = conn.ExecContext(ctx, "BEGIN;")
	mustNil(err)
	_, err = conn.QueryContext(ctx, "delete from t where a = 1; select 1;")
	mustNil(err)
}

func mustNil(err error) {
	if err != nil {
		panic(err)
	}
}

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

1

3. What did you see instead (Required)

Error 1105 (HY000): runtime error: index out of range [7] with length 0
[ERROR] [conn.go:1072] ["connection running loop panic"] [conn=8503385434707984879] [lastSQL="delete from t where a = 1; select 1;"] [err="runtime error: index out of range [7] with length 0"] [stack="github.com/pingcap/tidb/server.(*clientConn).Run.func1\n\t/home/tangenta/tidb/server/conn.go:1075\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:920\nruntime.goPanicIndex\n\t/usr/local/go/src/runtime/panic.go:114\nencoding/binary.bigEndian.Uint64\n\t/usr/local/go/src/encoding/binary/binary.go:179\ngit.luolix.top/pingcap/tidb/tablecodec.DecodeHandleInUniqueIndexValue\n\t/home/tangenta/tidb/tablecodec/tablecodec.go:1650\ngit.luolix.top/pingcap/tidb/server.(*clientConn).prefetchPointPlanKeys\n\t/home/tangenta/tidb/server/conn.go:2063\ngit.luolix.top/pingcap/tidb/server.(*clientConn).handleQuery\n\t/home/tangenta/tidb/server/conn.go:1855\ngit.luolix.top/pingcap/tidb/server.(*clientConn).dispatch\n\t/home/tangenta/tidb/server/conn.go:1372\ngit.luolix.top/pingcap/tidb/server.(*clientConn).Run\n\t/home/tangenta/tidb/server/conn.go:1153\ngit.luolix.top/pingcap/tidb/server.(*Server).onConn\n\t/home/tangenta/tidb/server/server.go:677"]

4. What is your TiDB version? (Required)

v7.1.0, master(33480e8)

@tangenta
Copy link
Contributor Author

tangenta commented Jan 3, 2024

There is no problem with version v6.1.0

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.

3 participants