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

tidb panic while use expression index #27386

Closed
aytrack opened this issue Aug 19, 2021 · 3 comments
Closed

tidb panic while use expression index #27386

aytrack opened this issue Aug 19, 2021 · 3 comments
Labels
duplicate Issues or pull requests already exists. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@aytrack
Copy link
Contributor

aytrack commented Aug 19, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `t01` (
  `COL1` tinytext COLLATE utf8mb4_general_ci NOT NULL,
  `COL2` char(10) COLLATE utf8mb4_general_ci NOT NULL,
  `COL3` bit(45) NOT NULL,
  PRIMARY KEY (`COL1`(5),`COL2`,`COL3`), 
  UNIQUE KEY `UIDXM` (`COL1`(5),`COL2`),
  UNIQUE KEY `UIDX` (`COL2`),
  KEY `IDX3` (`COL3`),
  KEY `IDXM` (`COL3`,`COL2`),
  KEY `eidx` ((substr(`COL1`, 10, 3)))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

explain select * from t01 use index (eidx) where substr(COL1 from 10 for 3) = substr(0xE88DB9E9A78C54E7B089E58EBDE893BDE9AFA7E8BEA1E7BAB4E7A8BC from 10 for 3);

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

execute successfully.

3. What did you see instead (Required)

tidb panic

MySQL root@172.16.6.1:hchwang> select * from t01 use index (eidx) where substr(COL1 from 10 for 3) = substr(0xE88DB9E9A78C54E7B089E58EBDE893BDE9AFA7E8BEA1E7BAB4E7A8BC from 10 for 3);
                           ->
(1105, 'runtime error: index out of range [3] with length 3')

tidb.log

[2021/08/19 17:12:05.338 +08:00] [ERROR] [conn.go:919] ["connection running loop panic"] [conn=2803] [lastSQL="select * from t01 use index (eidx) where substr(COL1 from 10 for 3) = substr(0xE88DB9E9A78C54E7B089E58EBDE893BDE9AFA7E8BEA1E7BAB4E7A8BC from 10 for 3)"] [err="runtime error: index out of range [3] with length 3"] [stack="goroutine 16517451 [running]:\ngithub.com/pingcap/tidb/server.(*clientConn).Run.func1(0x402eb10, 0xc0102b2f90, 0xc023a799e0)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/server/conn.go:917 +0xf5\npanic(0x38fe020, 0xc02e938090)\n\t/usr/local/go/src/runtime/panic.go:965 +0x1b9\ngithub.com/pingcap/tidb/util/collate.decodeRune(0xc034fefb29, 0x3, 0x2, 0xc000000265, 0x2)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/util/collate/collate.go:277 +0x135\ngithub.com/pingcap/tidb/util/collate.(*generalCICollator).Compare(0x5d907d8, 0xc034fefb29, 0x3, 0xc034fefb29, 0x3, 0x0)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/util/collate/general_ci.go:30 +0x105\ngithub.com/pingcap/tidb/types.CompareString(0xc034fefb29, 0x3, 0xc034fefb29, 0x3, 0xc0060c5740, 0x12, 0xc00cdd3500)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/types/compare.go:118 +0x71\ngithub.com/pingcap/tidb/types.(*Datum).compareString(0xc01dd16050, 0xc00dcd6000, 0xc034fefb29, 0x3, 0xc0060c5740, 0x12, 0x203ce0a, 0x5, 0x0)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/types/datum.go:682 +0x495\ngithub.com/pingcap/tidb/types.(*Datum).CompareDatum(0xc01dd16050, 0xc00dcd6000, 0xc00e7697b0, 0x5, 0x0, 0xc0060c5740)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/types/datum.go:582 +0x245\ngithub.com/pingcap/tidb/util/ranger.convertPoint(0xc00dcd6000, 0xc01dd16050, 0xc01914ade0, 0xc01906ff48, 0xc038818c70, 0x2)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/util/ranger/ranger.go:118 +0x194\ngithub.com/pingcap/tidb/util/ranger.points2Ranges(0xc00dcd6000, 0xc038818c70, 0x2, 0x2, 0xc01914ade0, 0x2, 0x1, 0x2, 0xc000600000, 0x203002)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/util/ranger/ranger.go:58 +0x105\ngithub.com/pingcap/tidb/util/ranger.(*rangeDetacher).buildCNFIndexRange(0xc00e769df0, 0xc038818c60, 0x2, 0x2, 0x1, 0xc038818c10, 0x1, 0x1, 0xc02a733780, 0x1, ...)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/util/ranger/ranger.go:358 +0x33a\ngithub.com/pingcap/tidb/util/ranger.(*rangeDetacher).detachCNFCondAndBuildRangeForIndex(0xc00e769df0, 0xc038818c00, 0x1, 0x1, 0xc01906ff28, 0x1, 0x1, 0xc01906ff01, 0x7f88b0162108, 0x2244e9c, ...)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/util/ranger/detacher.go:284 +0x23e\ngithub.com/pingcap/tidb/util/ranger.(*rangeDetacher).detachCondAndBuildRangeForCols(0xc00e769df0, 0x1, 0x0, 0x1)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/util/ranger/detacher.go:779 +0x225\ngithub.com/pingcap/tidb/util/ranger.DetachCondAndBuildRangeForIndex(0x4074f38, 0xc01f032000, 0xc038818c00, 0x1, 0x1, 0xc01906ff18, 0x1, 0x1, 0xc02a733780, 0x1, ...)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/util/ranger/detacher.go:744 +0xf5\ngithub.com/pingcap/tidb/planner/core.(*DataSource).fillIndexPath(0xc00c801400, 0xc007a6aea0, 0xc038818c00, 0x1, 0x1, 0x409e230, 0xc02d077e50)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/planner/core/logical_plans.go:854 +0x53f\ngithub.com/pingcap/tidb/planner/core.(*DataSource).DeriveStats(0xc00c801400, 0x5d907d8, 0x0, 0x0, 0xc02d077b80, 0x5d907d8, 0x0, 0x0, 0x0, 0x0, ...)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/planner/core/stats.go:400 +0x145\ngithub.com/pingcap/tidb/planner/core.(*baseLogicalPlan).recursiveDeriveStats(0xc00c801420, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/planner/core/stats.go:130 +0x325\ngithub.com/pingcap/tidb/planner/core.(*baseLogicalPlan).recursiveDeriveStats(0xc00dcb4800, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)\n\t/home/jenkins/agent/workspace/tidb_merged_pr_build/go/src/github.com/pingcap/tidb/planner/core/stats.go:123 +0x1b3\ngithub.com/pingcap/tidb/plan"]

4. What is your TiDB version? (Required)

tidb_version() | Release Version: v5.2.0-alpha-567-gdba8e111f
Edition: Community
Git Commit Hash: dba8e111fe26b1db0742dd5a024309137d49f5d2
Git Branch: HEAD
UTC Build Time: 2021-08-18 13:40:54
GoVersion: go1.16.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@aytrack aytrack added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner severity/major labels Aug 19, 2021
@wjhuang2016
Copy link
Member

wjhuang2016 commented Aug 19, 2021

mysql> explain select * from t01 use index (uidx) where col2 >= substr(0xE88DB9E9A78C54E7B089E58EBDE893BDE9AFA7E8BEA1E7BAB4E7A8BC from 10 for 3);
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    17
Current database: test

ERROR 1105 (HY000): runtime error: index out of range [3] with length 3

So it's not related to expression index.

@yudongusa yudongusa added sig/execution SIG execution and removed sig/planner SIG: Planner labels Aug 19, 2021
@aytrack
Copy link
Contributor Author

aytrack commented Aug 20, 2021

similar to #23506

@wjhuang2016 wjhuang2016 removed their assignment Aug 24, 2021
@wjhuang2016
Copy link
Member

Duplicate with #23506

@wjhuang2016 wjhuang2016 added the duplicate Issues or pull requests already exists. label Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues or pull requests already exists. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

3 participants