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

CREATE TABLE failed: ERROR 1105 (HY000): runtime error: index out if range [0] with length 0 #38894

Closed
Flynn-Zh opened this issue Nov 4, 2022 · 4 comments · Fixed by #38966
Closed
Labels
affects-5.0 This bug affects 5.0.x versions. 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 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@Flynn-Zh
Copy link

Flynn-Zh commented Nov 4, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

a. use mysql connect tidb
b. execute sql: use test;
CREATE TABLE item_map (
id VARCHAR(128) NOT NULL,
created_at DATETIME(6),
updated_at DATETIME(6),
deleted_at DATETIME(6),
deleted BOOL,
item_id INTEGER NOT NULL AUTO_INCREMENT,
provider VARCHAR(255),
attribute VARCHAR(255),
PRIMARY KEY (id, item_id),
CHECK (deleted IN (0, 1)),
KEY idx_autoinc_item_id (item_id)
)ENGINE=InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;

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

Query OK

3. What did you see instead (Required)

ERROR 1105 (HY000): runtime error: index out if range [0] with length 0

4. What is your TiDB version? (Required)

| Release Version: v6.1.1
Edition: Community
Git Commit Hash: 5263a0abda61f102122735049fd0dfabc7b7f8b2
Git Branch: heads/refs/tags/v6.1.1
UTC Build Time: 2022-08-25 10:42:41
GoVersion: go1.18.5
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false

@Flynn-Zh Flynn-Zh added the type/bug The issue is confirmed as a bug. label Nov 4, 2022
@canonhuber
Copy link

mark

@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.0 may-affects-6.1 may-affects-6.2 may-affects-6.3 labels Nov 5, 2022
@ChenPeng2013 ChenPeng2013 added affects-5.0 This bug affects 5.0.x versions. 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 5.4.x versions. affects-6.0 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.0 may-affects-6.1 may-affects-6.2 may-affects-6.3 labels Nov 5, 2022
@fixdb
Copy link
Contributor

fixdb commented Nov 7, 2022

The issue still exists on master branch.

@YangKeao
Copy link
Member

YangKeao commented Nov 8, 2022

The stack:

github.com/pingcap/tidb/server.(*clientConn).Run.func1
        /home/yangkeao/Project/github.com/YangKeao/tidb/server/conn.go:1061
runtime.gopanic
        /usr/lib/golang/src/runtime/panic.go:890
github.com/pingcap/tidb/executor.(*Compiler).Compile.func1
        /home/yangkeao/Project/github.com/YangKeao/tidb/executor/compiler.go:70
runtime.gopanic
        /usr/lib/golang/src/runtime/panic.go:890
runtime.goPanicIndex
        /usr/lib/golang/src/runtime/panic.go:113
github.com/pingcap/tidb/planner/core.isConstraintKeyTp
        /home/yangkeao/Project/github.com/YangKeao/tidb/planner/core/preprocess.go:678
github.com/pingcap/tidb/planner/core.(*preprocessor).checkAutoIncrement
        /home/yangkeao/Project/github.com/YangKeao/tidb/planner/core/preprocess.go:731
github.com/pingcap/tidb/planner/core.(*preprocessor).Leave
        /home/yangkeao/Project/github.com/YangKeao/tidb/planner/core/preprocess.go:546
github.com/pingcap/tidb/parser/ast.(*CreateTableStmt).Accept
        /home/yangkeao/Project/github.com/YangKeao/tidb/parser/ast/ddl.go:1184
github.com/pingcap/tidb/planner/core.Preprocess
        /home/yangkeao/Project/github.com/YangKeao/tidb/planner/core/preprocess.go:136
github.com/pingcap/tidb/executor.(*Compiler).Compile
        /home/yangkeao/Project/github.com/YangKeao/tidb/executor/compiler.go:79
github.com/pingcap/tidb/session.(*session).ExecuteStmt
        /home/yangkeao/Project/github.com/YangKeao/tidb/session/session.go:2163
github.com/pingcap/tidb/server.(*TiDBContext).ExecuteStmt
        /home/yangkeao/Project/github.com/YangKeao/tidb/server/driver_tidb.go:233
github.com/pingcap/tidb/server.(*clientConn).handleStmt
        /home/yangkeao/Project/github.com/YangKeao/tidb/server/conn.go:2082
github.com/pingcap/tidb/server.(*clientConn).handleQuery
        /home/yangkeao/Project/github.com/YangKeao/tidb/server/conn.go:1932
github.com/pingcap/tidb/server.(*clientConn).dispatch
        /home/yangkeao/Project/github.com/YangKeao/tidb/server/conn.go:1374
github.com/pingcap/tidb/server.(*clientConn).Run
        /home/yangkeao/Project/github.com/YangKeao/tidb/server/conn.go:1123
github.com/pingcap/tidb/server.(*Server).onConn
        /home/yangkeao/Project/github.com/YangKeao/tidb/server/server.go:624

@YangKeao
Copy link
Member

YangKeao commented Nov 8, 2022

A work around is to remove the CHECK constraint (as TiDB actually doesn't support it), or move the CHECK constraint to the last one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. 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 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 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.

6 participants