Specific Query Error: runtime error: index out of range [1] with length 0

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 特定查询会报错: runtime error: index out of range [1] with length 0

| username: dba-kit

[TiDB Usage Environment] Production Environment
[TiDB Version] v6.5.1
The query is a complex one, not convenient to share. According to the error message, it is related to index_lookup_join.go. The same SQL query will report an error when executed on TiKV, but it can be executed normally when switched to TiFlash.

[ERROR] [index_lookup_join.go:484] ["innerWorker panicked"] [conn=4629071496286076969] 
[recover="runtime error: index out of range [1] with length 0"]
[stack="github.com/pingcap/tidb/executor.(*innerWorker).run.func1
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/index_lookup_join.go:484
runtime.gopanic
	/usr/local/go/src/runtime/panic.go:884
runtime.goPanicIndex
	/usr/local/go/src/runtime/panic.go:113
github.com/pingcap/tidb/util/chunk.setMutRowBytes
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/mutrow.go:335
github.com/pingcap/tidb/util/chunk.MutRow.SetDatum
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/mutrow.go:305
github.com/pingcap/tidb/util/chunk.MutRow.SetDatums
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/mutrow.go:288
github.com/pingcap/tidb/table/tables.(*partitionedTable).locateRangeColumnPartition.func1
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/table/tables/partition.go:1010
sort.Search
	/usr/local/go/src/sort/search.go:65
github.com/pingcap/tidb/table/tables.(*partitionedTable).locateRangeColumnPartition
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/table/tables/partition.go:1009
github.com/pingcap/tidb/table/tables.(*partitionedTable).locatePartition
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/table/tables/partition.go:991
github.com/pingcap/tidb/table/tables.(*partitionedTable).GetPartitionByRow
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/table/tables/partition.go:1159
github.com/pingcap/tidb/executor.(*dataReaderBuilder).buildTableReaderForIndexJoin
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:4171
github.com/pingcap/tidb/executor.(*dataReaderBuilder).buildExecutorForIndexJoinInternal
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:4066
github.com/pingcap/tidb/executor.(*dataReaderBuilder).buildExecutorForIndexJoin
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:4059
github.com/pingcap/tidb/executor.(*innerWorker).fetchInnerResults
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/index_lookup_join.go:690
github.com/pingcap/tidb/executor.(*innerWorker).handleTask
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/index_lookup_join.go:528
github.com/pingcap/tidb/executor.(*innerWorker).run
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/index_lookup_join.go:502"]
| username: CuteRay | Original post link

This kind of error, 90% likely hit a bug. If you have time, you can anonymize the table structure and SQL statements and share them so we can study them together.

| username: TiDBer_pkQ5q1l0 | Original post link

It is probably a bug.

| username: yilong | Original post link

Please provide the table structure and SQL for easier reproduction. If you cannot provide the original SQL, please use test SQL to reproduce the issue in the simplest way possible. Thank you.

| username: liuis | Original post link

This error is 100% a bug. The Golang map reported an error, probably because a certain scenario was not covered.