TiDB 5.0 查询报错[Code: 1105, SQL State: HY000] runtime error: index out of range [0] with length 0

为提高效率,请提供以下信息,问题描述清晰能够更快得到解决:

【TiDB 版本】
5.0.0
【问题描述】
一个简单的单表查询,表结构如下

create TABLE
queue_item
(
id bigint NOT NULL,
sort_no decimal(10,4),
created_by bigint NOT NULL,
created_date TIMESTAMP NULL,
creator VARCHAR(50) NOT NULL,
cur_status INT NOT NULL,
is_deleted INT NOT NULL,
last_modified_by bigint NOT NULL,
last_modified_date TIMESTAMP NULL,
last_modifier VARCHAR(50) NOT NULL,
batch_no VARCHAR(255),
bind_time DATETIME,
name VARCHAR(255),
pid bigint,
pull_time DATETIME,
status INT,
take_time DATETIME,
term_ip VARCHAR(255),
instance_id bigint,
queue_id bigint,
take_no VARCHAR(20),
done_time TIMESTAMP NULL,
org_id bigint,
version INT DEFAULT 0 NOT NULL,
PRIMARY KEY (id)
)

执行单表查询

SELECT
COUNT(queueitem0_.id) AS col_0_0_
FROM
queue_item queueitem0_
WHERE
queueitem0_.instance_id=339567356370381021
AND queueitem0_.cur_status=1
AND queueitem0_.sort_no<1012.10

偶发,报以下错误

[Code: 1105, SQL State: HY000] runtime error: index out of range [0] with length 0

TiDB日志如下

[2021/04/11 20:39:01.532 +08:00] [ERROR] [adapter.go:139] [“execute sql panic”] [conn=26515] [sql=“SELECT\n COUNT(queueitem0_.id) AS col_0_0_\nFROM\n queue_item queueitem0_\nWHERE\n queueitem0_.instance_id=339567356370381021\nAND queueitem0_.cur_status=1\nAND queueitem0_.sort_no<1012.10”] [stack=“github.com/pingcap/tidb/executor.(*recordSet).Next.func1\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/adapter.go:139\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:679\nruntime.goPanicIndex\n\t/usr/local/go/src/runtime/panic.go:75\ngithub.com/pingcap/tidb/statistics.(*QueryFeedback).Update\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/statistics/feedback.go:314\ngithub.com/pingcap/tidb/distsql.(*selectResult).fetchResp\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/distsql/select_result.go:185\ngithub.com/pingcap/tidb/distsql.(*selectResult).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/distsql/select_result.go:208\ngithub.com/pingcap/tidb/executor.(*tableResultHandler).nextChunk\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/table_reader.go:309\ngithub.com/pingcap/tidb/executor.(*TableReaderExecutor).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/table_reader.go:186\ngithub.com/pingcap/tidb/executor.Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/executor.go:277\ngithub.com/pingcap/tidb/executor.(*StreamAggExec).consumeCurGroupRowsAndFetchChild\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/aggregate.go:1212\ngithub.com/pingcap/tidb/executor.(*StreamAggExec).consumeOneGroup\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/aggregate.go:1140\ngithub.com/pingcap/tidb/executor.(*StreamAggExec).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/aggregate.go:1129\ngithub.com/pingcap/tidb/executor.Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/executor.go:277\ngithub.com/pingcap/tidb/executor.(*LimitExec).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/executor.go:1064\ngithub.com/pingcap/tidb/executor.Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/executor.go:277\ngithub.com/pingcap/tidb/executor.(*recordSet).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/adapter.go:142\ngithub.com/pingcap/tidb/server.(*tidbResultSet).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/driver_tidb.go:304\ngithub.com/pingcap/tidb/server.(*clientConn).writeChunksWithFetchSize\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/conn.go:1863\ngithub.com/pingcap/tidb/server.(*clientConn).writeResultset\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/conn.go:1753\ngithub.com/pingcap/tidb/server.(*clientConn).handleStmtFetch\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/conn_stmt.go:277\ngithub.com/pingcap/tidb/server.(*clientConn).dispatch\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/conn.go:1063\ngithub.com/pingcap/tidb/server.(*clientConn).Run\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/conn.go:795\ngithub.com/pingcap/tidb/server.(*Server).onConn\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/server.go:477”]
[2021/04/11 20:39:01.533 +08:00] [INFO] [conn.go:812] [“command dispatched failed”] [conn=26515] [connInfo=“id:26515, addr:10.10.5.28:50658 status:10, collation:utf8_general_ci, user:health2_dev”] [command=Fetch] [status=“inTxn:0, autocommit:1”] [sql=“SELECT\n COUNT(queueitem0_.id) AS col_0_0_\nFROM\n queue_item queueitem0_\nWHERE\n queueitem0_.instance_id=339567356370381021\nAND queueitem0_.cur_status=1\nAND queueitem0_.sort_no<1012.10”] [txn_mode=OPTIMISTIC] [err=“runtime error: index out of range [0] with length 0\ngithub.com/pingcap/tidb/executor.(*recordSet).Next.func1\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/adapter.go:138\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:679\nruntime.goPanicIndex\n\t/usr/local/go/src/runtime/panic.go:75\ngithub.com/pingcap/tidb/statistics.(*QueryFeedback).Update\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/statistics/feedback.go:314\ngithub.com/pingcap/tidb/distsql.(*selectResult).fetchResp\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/distsql/select_result.go:185\ngithub.com/pingcap/tidb/distsql.(*selectResult).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/distsql/select_result.go:208\ngithub.com/pingcap/tidb/executor.(*tableResultHandler).nextChunk\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/table_reader.go:309\ngithub.com/pingcap/tidb/executor.(*TableReaderExecutor).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/table_reader.go:186\ngithub.com/pingcap/tidb/executor.Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/executor.go:277\ngithub.com/pingcap/tidb/executor.(*StreamAggExec).consumeCurGroupRowsAndFetchChild\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/aggregate.go:1212\ngithub.com/pingcap/tidb/executor.(*StreamAggExec).consumeOneGroup\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/aggregate.go:1140\ngithub.com/pingcap/tidb/executor.(*StreamAggExec).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/aggregate.go:1129\ngithub.com/pingcap/tidb/executor.Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/executor.go:277\ngithub.com/pingcap/tidb/executor.(*LimitExec).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/executor.go:1064\ngithub.com/pingcap/tidb/executor.Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/executor.go:277\ngithub.com/pingcap/tidb/executor.(*recordSet).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/executor/adapter.go:142\ngithub.com/pingcap/tidb/server.(*tidbResultSet).Next\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/driver_tidb.go:304\ngithub.com/pingcap/tidb/server.(*clientConn).writeChunksWithFetchSize\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/conn.go:1863\ngithub.com/pingcap/tidb/server.(*clientConn).writeResultset\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/conn.go:1753\ngithub.com/pingcap/tidb/server.(*clientConn).handleStmtFetch\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/conn_stmt.go:277\ngithub.com/pingcap/tidb/server.(*clientConn).dispatch\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/conn.go:1063\ngithub.com/pingcap/tidb/server.(*clientConn).Run\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/conn.go:795\ngithub.com/pingcap/tidb/server.(*Server).onConn\n\t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/server.go:477\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1357\nSELECT\n COUNT(queueitem0_.id) AS col_0_0_\nFROM\n queue_item queueitem0_\nWHERE\n queueitem0_.instance_id=339567356370381021\nAND queueitem0_.cur_status=1\nAND queueitem0_.sort_no<1012.10”]


若提问为性能优化、故障排查类问题,请下载脚本运行。终端输出的打印结果,请务必全选并复制粘贴上传。

麻烦提供下 SQL 的执行计划,并导出下表的统计信息,参考下:
https://docs.pingcap.com/zh/tidb/stable/statistics#导出统计信息

执行计划

统计信息
queue_item.json (2.3 MB)

收到,我们这边先分下下

这个是 feedback 的问题,建议通过 tidb 配置

[performance]
feedback-probability = 0.0

先饶过,5.0 集群中 feedback 功能是默认关闭的,不推荐使用。具体原因我们内部再查查。

1赞

@Tao 请问,关闭 feedback 功能了吗? 关闭后是否问题已经解决?