1105 - runtime error: index out of range [-1]

同样的sql,同样的数据,在tidb4版本上执行没有问题,到了tidb5执行sql的时候报“1105 - runtime error: index out of range [-1]”,不确定问题产生的原因是啥,SQL语句是“SELECT
tc.school_id,
tc.id
FROM
tb_column tc
LEFT JOIN tb_course_mini_rel tcmr ON tc.id = tcmr.column_id
AND tcmr.del_flag = 0
WHERE
tc.del_flag = 0
AND tc.column_type = 1
AND tcmr.course_source = 3
AND tcmr.off_status != 2
AND tcmr.course_id IN ( SELECT id FROM tb_course WHERE IF ( course_type = 1, parent_id = 0, 1 = 1 ) AND del_flag = 0 AND STATUS = 1 )
GROUP BY
tc.school_id
HAVING
count( tcmr.course_id ) >= 3

”,假如去掉“AND tcmr.course_source = 3
AND tcmr.off_status != 2
AND tcmr.course_id IN ( SELECT id FROM tb_course WHERE IF ( course_type = 1, parent_id = 0, 1 = 1 ) AND del_flag = 0 AND STATUS = 1 ) ”这三个条件是可以的

可以过滤 tidb 日志 index out of range 发一下包含详细堆栈的报错,另外请提供下具体的版本,是 5.0.0 还是 5.0.1

版本问题,已经有类似发帖了

可能是同一问题

[2021/05/08 11:22:26.697 +08:00] [ERROR] [conn.go:736] [“connection running loop panic”] [conn=2250217] [lastSQL=“SELECT\ \t*\ FROM\ \ttb_column tc\ \tLEFT JOIN tb_course_mini_rel tcmr ON tc.id = tcmr.column_id \ \tAND tcmr.del_flag = 0 \ WHERE\ \ttc.del_flag = 0 \ \tAND tc.column_type = 1\ \tAND tcmr.course_source = 3 \ \tAND tcmr.off_status != 2 \ \tAND tcmr.course_id IN ( SELECT id FROM tb_course WHERE IF ( course_type = 1, parent_id = 0, 1 = 1 ) AND del_flag = 0 AND STATUS = 1 ) \ GROUP BY\ \ttc.school_id \ HAVING\ \tcount( tcmr.course_id ) >= 1”] [err=“runtime error: index out of range [-1]”] [stack=“goroutine 601643761 [running]:\ngithub.com/pingcap/tidb/server.(*clientConn).Run.func1(0x3ff6060, 0xc0f23c2450, 0xc0b0ec4500)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/server/conn.go:734 +0xee\ panic(0x378df20, 0xc0cad7dd00)\ \t/usr/local/go/src/runtime/panic.go:679 +0x1b2\ngithub.com/pingcap/tidb/planner/core.(*LogicalProjection).TryToGetChildProp(0xc0548040e0, 0xc0258e0e70, 0xc0c4aa3bc0, 0x40408333333359ee)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/core/exhaust_physical_plans.go:1927 +0x39a\ngithub.com/pingcap/tidb/planner/core.(*LogicalProjection).exhaustPhysicalPlans(0xc0548040e0, 0xc0258e0e70, 0xc0106ca600, 0x29, 0x5f84760, 0xc05c1f8a01)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/core/exhaust_physical_plans.go:1939 +0x50\ngithub.com/pingcap/tidb/planner/core.(*baseLogicalPlan).findBestTask(0xc054804100, 0xc046f0f810, 0x5978228, 0x0, 0x0, 0x0, 0x0, 0x0)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/core/find_best_task.go:310 +0x1d5\ngithub.com/pingcap/tidb/planner/core.(*baseLogicalPlan).enumeratePhysicalPlans4Task(0xc0547823e0, 0xc092719e60, 0x2, 0x3, 0xc00460e930, 0xc05c1f8800, 0x5978228, 0x10, 0x36a7b20, 0x399ca37, …)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/core/find_best_task.go:213 +0x70d\ngithub.com/pingcap/tidb/planner/core.(*baseLogicalPlan).findBestTask(0xc0547823e0, 0xc00460e8c0, 0x5978228, 0x0, 0x0, 0x0, 0x0, 0x0)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/core/find_best_task.go:343 +0x32f\ngithub.com/pingcap/tidb/planner/core.(*baseLogicalPlan).enumeratePhysicalPlans4Task(0xc054775800, 0xc05c1f8840, 0x1, 0x1, 0xc00460e770, 0xc05c1f8800, 0x5978228, 0x10, 0x36a7b20, 0x0, …)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/core/find_best_task.go:213 +0x70d\ngithub.com/pingcap/tidb/planner/core.(*baseLogicalPlan).findBestTask(0xc054775800, 0xc00460e690, 0x5978228, 0x0, 0x0, 0x0, 0x0, 0x0)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/core/find_best_task.go:343 +0x32f\ngithub.com/pingcap/tidb/planner/core.(*baseLogicalPlan).enumeratePhysicalPlans4Task(0xc054461b40, 0xc05c1f8820, 0x1, 0x1, 0xc00460e620, 0xc00460e500, 0xc02cd47fa8, 0x68, 0x37cf7a0, 0xc00f042318, …)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/core/find_best_task.go:213 +0x70d\ngithub.com/pingcap/tidb/planner/core.(*baseLogicalPlan).findBestTask(0xc054461b40, 0xc00460e5b0, 0xc02cd47fa8, 0x0, 0x0, 0x0, 0x0, 0x0)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/core/find_best_task.go:343 +0x32f\ngithub.com/pingcap/tidb/planner/core.physicalOptimize(0x404ac80, 0xc054461b20, 0xc02cd47fa8, 0x404ac80, 0xc054461b20, 0x404ac80, 0xc054461b20, 0x0)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/core/optimizer.go:224 +0x131\ngithub.com/pingcap/tidb/planner/core.DoOptimize(0x3ff6060, 0xc0ec447b90, 0x404ec80, 0xc0b547e000, 0x1df6, 0x404ac80, 0xc054461b20, 0x0, 0x0, 0x0, …)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/core/optimizer.go:143 +0x13a\ngithub.com/pingcap/tidb/planner.optimize(0x3ff6060, 0xc0ec447b90, 0x404ec80, 0xc0b547e000, 0x4014c80, 0xc00c938200, 0x40412c0, 0xc01d175270, 0x0, 0x0, …)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planner/optimize.go:288 +0x66c\ngithub.com/pingcap/tidb/planner.Optimize(0x3ff6060, 0xc0ec447b90, 0x404ec80, 0xc0b547e000, 0x4014c80, 0xc00c938200, 0x40412c0, 0xc01d175270, 0x0, 0x0, …)\ \t/home/jenkins/agent/workspace/optimization-build-tidb-linux-amd/go/src/github.com/pingcap/tidb/planne”]

tidb5.0 我看现在有tidb5.0.1,升一下版本看看

看上去跟这个 issue https://github.com/pingcap/tidb/issues/24045 类似,master 版本已修复还没 cherry pick 到 5.0.1,这个问题跟 having 子句有关

可以先尝试去掉 HAVING count( tcmr.course_id ) >= 3

关闭feedback不好试

恩,等着版本升级吧

可以在本地运行 tiup playground nightly,快速验证一下 master 版本

GROUP BY xx
UNION
也有这个问题,啥时间解决啊,生产一堆问题

你好,麻烦单独发帖,可以参照填写模板,具体描述下问题的背景信息,如

【Bug 的影响】

【可能的问题复现步骤】

【看到的非预期行为】

【期望看到的行为】

【相关组件及具体版本】

我也是,不知道有没有hotfix