7.1.1 集群执行sql ERROR 1105 (HY000): runtime error: index out of range [0] with length 0

【 TiDB 使用环境】测试/ Poc
【 TiDB 版本】7.1.1

【遇到的问题:问题现象及影响】5.0.4版本执行没问题,7.1.1版本执行查询报错。

  • sql
SELECT `estimate_year_month`,
       `a_manager_yid`                                               AS `manager_yid`,
       `real_t1_volume`,
       `real_t0_volume`,
       `a_estimate_volume` + IFNULL(`b_estimate_volume`, 0)          AS `estimate_volume`,
       IFNULL(`a`.`increase_sum`, 0) + IFNULL(`b`.`increase_sum`, 0) AS `increase_sum`,
       IFNULL(`a`.`decrease_sum`, 0) + IFNULL(`b`.`decrease_sum`, 0) AS `decrease_sum`
FROM (SELECT `estimate_year_month`,
             `manager_yid`          AS `a_manager_yid`,
             SUM(`real_t1_volume`)  AS `real_t1_volume`,
             SUM(`real_t0_volume`)  AS `real_t0_volume`,
             SUM(`estimate_volume`) AS `a_estimate_volume`,
             SUM(IF(`estimate_volume` > `real_t1_volume`,
                    `estimate_volume` - `real_t1_volume`,
                    0))             AS `increase_sum`,
             SUM(IF(`estimate_volume` <`real_t1_volume`,
                    `estimate_volume` - `real_t1_volume`,
                    0))             AS `decrease_sum`
      FROM `rd_crm`.`signed_estimate_volume`
      WHERE `estimate_year_month` = DATE_FORMAT(NOW(), _UTF8MB4'%Y%m')
        AND `is_dropped` = 0
        AND `data_type` = 1
      GROUP BY `manager_yid`) AS `a`
         LEFT JOIN (SELECT `manager_yid`          AS `b_manager_yid`,
                           SUM(`estimate_volume`) AS `b_estimate_volume`,
                           SUM(`estimate_volume`) AS `increase_sum`,
                           0                      AS `decrease_sum`
                    FROM `rd_crm`.`unsigned_estimate_volume`
                    WHERE `estimate_year_month` = DATE_FORMAT(NOW(), _UTF8MB4'%Y%m')
                      AND `is_dropped` = 0
                      AND `data_type` = 1
                    GROUP BY `manager_yid`) AS `b`
                   ON a.`a_manager_yid` = b.`b_manager_yid`

【附件:截图/日志/监控】
错误日志:

[2023/08/02 16:46:46.037 +08:00] [ERROR] [adapter.go:148] ["execute sql panic"] [conn=844026906930753967] [sql="SELECT `estimate_year_month`,\n       `a_manager_yid`
                                       AS `manager_yid`,\n       `real_t1_volume`,\n       `real_t0_volume`,\n       `a_estimate_volume` + IFNULL(`b_estimate_volume`, 0)
      AS `estimate_volume`,\n       IFNULL(`a`.`increase_sum`, 0) + IFNULL(`b`.`increase_sum`, 0) AS `increase_sum`,\n       IFNULL(`a`.`decrease_sum`, 0) + IFNULL(`b`.`decr
ease_sum`, 0) AS `decrease_sum`\nFROM (SELECT `estimate_year_month`,\n             `manager_yid`          AS `a_manager_yid`,\n             SUM(`real_t1_volume`)  AS `real_t
1_volume`,\n             SUM(`real_t0_volume`)  AS `real_t0_volume`,\n             SUM(`estimate_volume`) AS `a_estimate_volume`,\n             SUM(IF(`estimate_volume` > `r
eal_t1_volume`,\n                    `estimate_volume` - `real_t1_volume`,\n                    0))             AS `increase_sum`,\n             SUM(IF(`estimate_volume` <`
real_t1_volume`,\n                    `estimate_volume` - `real_t1_volume`,\n                    0))             AS `decrease_sum`\n      FROM `rd_crm`.`signed_estimate_volu
me`\n      WHERE `estimate_year_month` = DATE_FORMAT(NOW(), _UTF8MB4'%Y%m')\n        AND `is_dropped` = 0\n        AND `data_type` = 1\n      GROUP BY `manager_yid`) AS `a`\
n         LEFT JOIN (SELECT `manager_yid`          AS `b_manager_yid`,\n                           SUM(`estimate_volume`) AS `b_estimate_volume`,\n
 SUM(`estimate_volume`) AS `increase_sum`,\n                           0                      AS `decrease_sum`\n                    FROM `rd_crm`.`unsigned_estimate_volume`
\n                    WHERE `estimate_year_month` = DATE_FORMAT(NOW(), _UTF8MB4'%Y%m')\n                      AND `is_dropped` = 0\n                      AND `data_type` = 1
\n                    GROUP BY `manager_yid`) AS `b`\n                   ON a.`a_manager_yid` = b.`b_manager_yid`"] [stack="github.com/pingcap/tidb/executor.(*recordSet).Nex
t.func1\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:148\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:884\nrunt
ime.goPanicIndex\n\t/usr/local/go/src/runtime/panic.go:113\ngithub.com/pingcap/tidb/util/chunk.(*Column).IsNull\n\t/home/jenkins/agent/workspace/build-common/go/src/github.c
om/pingcap/tidb/util/chunk/column.go:169\ngithub.com/pingcap/tidb/expression.(*builtinIfNullIntSig).vecEvalInt\n\t/home/jenkins/agent/workspace/build-common/go/src/github.co
m/pingcap/tidb/expression/builtin_control_vec_generated.go:846\ngithub.com/pingcap/tidb/expression.(*ScalarFunction).VecEvalInt\n\t/home/jenkins/agent/workspace/build-common
/go/src/github.com/pingcap/tidb/expression/scalar_function.go:48\ngithub.com/pingcap/tidb/expression.(*builtinCastIntAsDecimalSig).vecEvalDecimal\n\t/home/jenkins/agent/work
space/build-common/go/src/github.com/pingcap/tidb/expression/builtin_cast_vec.go:1081\ngithub.com/pingcap/tidb/expression.(*ScalarFunction).VecEvalDecimal\n\t/home/jenkins/a
gent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/scalar_function.go:63\ngithub.com/pingcap/tidb/expression.(*builtinArithmeticPlusDecimalSig).vecEvalDec
imal\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/builtin_arithmetic_vec.go:994\ngithub.com/pingcap/tidb/expression.(*ScalarFuncti
on).VecEvalDecimal\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/scalar_function.go:63\ngithub.com/pingcap/tidb/expression.evalOneV
ec\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/chunk_executor.go:163\ngithub.com/pingcap/tidb/expression.(*defaultEvaluator).run\
n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/evaluator.go:53\ngithub.com/pingcap/tidb/expression.(*EvaluatorSuite).Run\n\t/home/je
nkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/evaluator.go:125\ngithub.com/pingcap/tidb/executor.(*ProjectionExec).unParallelExecute\n\t/home/
jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/projection.go:205\ngithub.com/pingcap/tidb/executor.(*ProjectionExec).Next\n\t/home/jenkins/agen
t/workspace/build-common/go/src/github.com/pingcap/tidb/executor/projection.go:183\ngithub.com/pingcap/tidb/executor.Next\n\t/home/jenkins/agent/workspace/build-common/go/sr
c/github.com/pingcap/tidb/executor/executor.go:326\ngithub.com/pingcap/tidb/executor.(*ExecStmt).next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap
/tidb/executor/adapter.go:1202\ngithub.com/pingcap/tidb/executor.(*recordSet).Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adap
ter.go:151\ngithub.com/pingcap/tidb/server.(*tidbResultSet).Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/driver_tidb.go:469\ngith
ub.com/pingcap/tidb/server.(*clientConn).writeChunks\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2313\ngithub.com/pingcap/tid
b/server.(*clientConn).writeResultSet\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2256\ngithub.com/pingcap/tidb/server.(*clie
ntConn).handleStmt\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2124\ngithub.com/pingcap/tidb/server.(*clientConn).handleQuery
\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1885\ngithub.com/pingcap/tidb/server.(*clientConn).dispatch\n\t/home/jenkins/age
nt/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1372\ngithub.com/pingcap/tidb/server.(*clientConn).Run\n\t/home/jenkins/agent/workspace/build-common/
go/src/github.com/pingcap/tidb/server/conn.go:1153\ngithub.com/pingcap/tidb/server.(*Server).onConn\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/t
idb/server/server.go:677"]

根据您提供的错误信息,这个错误通常是由于 TiDB 执行 SQL 语句时出现了运行时错误,导致索引越界。这个错误可能是由于多种原因引起的,例如 SQL 语法错误、表不存在、列不存在等等。

为了更好地定位问题,建议您先检查 SQL 语句是否正确,包括语法、表名、列名等等。您可以使用 explain 命令来查看 SQL 语句的执行计划,以便更好地理解 SQL 语句的执行过程。例如:

explain select * from my_table where id = 1;

如果 SQL 语句正确,那么您可以尝试查看 TiDB 的日志,以便更好地了解错误的原因。您可以在 TiDB 的配置文件中设置日志级别,然后查看 TiDB 的日志文件。例如,您可以在配置文件中添加以下配置:

[log]
level = “debug”

然后重启 TiDB,查看 TiDB 的日志文件,以便更好地了解错误的原因。

核心 bug 又出现了,不过需要排除下环境和数据问题… :rofl:

没有明显的额外报错

[2023/08/02 19:25:55.342 +08:00] [ERROR] [adapter.go:148] ["execute sql panic"] [conn=2966429595181515201] [sql="SELECT `estimate_year_month`,\n`a_manager_yid`
                                 AS `manager_yid`,\n`real_t1_volume`,\n`real_t0_volume`,\n`a_estimate_volume` + IFNULL(`b_estimate_volume`, 0)          AS `estimate_volume`,
\nIFNULL(`a`.`increase_sum`, 0) + IFNULL(`b`.`increase_sum`, 0) AS `increase_sum`,\nIFNULL(`a`.`decrease_sum`, 0) + IFNULL(`b`.`decrease_sum`, 0) AS `decrease_sum`\nFROM (SE
LECT `estimate_year_month`,\n`manager_yid`          AS `a_manager_yid`,\nSUM(`real_t1_volume`)  AS `real_t1_volume`,\nSUM(`real_t0_volume`)  AS `real_t0_volume`,\nSUM(`estim
ate_volume`) AS `a_estimate_volume`,\nSUM(IF(`estimate_volume` > `real_t1_volume`,`estimate_volume` - `real_t1_volume`,0))             AS `increase_sum`,\nSUM(IF(`estimate_v
olume` < `real_t1_volume`,`estimate_volume` - `real_t1_volume`,0))             AS `decrease_sum`\nFROM `rd_crm`.`signed_estimate_volume`\nWHERE `estimate_year_month` = DATE_
FORMAT(NOW(), _UTF8MB4'%Y%m')\nAND `is_dropped` = 0\nAND `data_type` = 1\nGROUP BY `manager_yid`) AS `a`\nLEFT JOIN (SELECT `manager_yid`          AS `b_manager_yid`,\nSUM(`
estimate_volume`) AS `b_estimate_volume`,\nSUM(`estimate_volume`) AS `increase_sum`,\n0                      AS `decrease_sum`\nFROM `rd_crm`.`unsigned_estimate_volume`\nWHE
RE `estimate_year_month` = DATE_FORMAT(NOW(), '%Y%m')\nAND `is_dropped` = 0\nAND `data_type` = 1\nGROUP BY `manager_yid`) AS `b`\nON a.`a_manager_yid` = b.`b_manager_yid`"]
[stack="github.com/pingcap/tidb/executor.(*recordSet).Next.func1\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:148\nruntim
e.gopanic\n\t/usr/local/go/src/runtime/panic.go:884\nruntime.goPanicIndex\n\t/usr/local/go/src/runtime/panic.go:113\ngithub.com/pingcap/tidb/util/chunk.(*Column).IsNull\n\t/
home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/column.go:169\ngithub.com/pingcap/tidb/expression.(*builtinIfNullIntSig).vecEvalInt\n\t/h
ome/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/builtin_control_vec_generated.go:846\ngithub.com/pingcap/tidb/expression.(*ScalarFunction)
.VecEvalInt\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/scalar_function.go:48\ngithub.com/pingcap/tidb/expression.(*builtinCastIn
tAsDecimalSig).vecEvalDecimal\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/builtin_cast_vec.go:1081\ngithub.com/pingcap/tidb/expre
ssion.(*ScalarFunction).VecEvalDecimal\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/scalar_function.go:63\ngithub.com/pingcap/tidb
/expression.(*builtinArithmeticPlusDecimalSig).vecEvalDecimal\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/builtin_arithmetic_vec.
go:994\ngithub.com/pingcap/tidb/expression.(*ScalarFunction).VecEvalDecimal\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/scalar_fu
nction.go:63\ngithub.com/pingcap/tidb/expression.evalOneVec\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/chunk_executor.go:163\ngi
thub.com/pingcap/tidb/expression.(*defaultEvaluator).run\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/evaluator.go:53\ngithub.com/
pingcap/tidb/expression.(*EvaluatorSuite).Run\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/evaluator.go:125\ngithub.com/pingcap/ti
db/executor.(*ProjectionExec).unParallelExecute\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/projection.go:205\ngithub.com/pingcap/t
idb/executor.(*ProjectionExec).Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/projection.go:183\ngithub.com/pingcap/tidb/executor
.Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/executor.go:326\ngithub.com/pingcap/tidb/executor.(*ExecStmt).next\n\t/home/jenki
ns/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:1202\ngithub.com/pingcap/tidb/executor.(*recordSet).Next\n\t/home/jenkins/agent/workspace/
build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:151\ngithub.com/pingcap/tidb/server.(*tidbResultSet).Next\n\t/home/jenkins/agent/workspace/build-common/go/sr
c/github.com/pingcap/tidb/server/driver_tidb.go:469\ngithub.com/pingcap/tidb/server.(*clientConn).writeChunks\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com
/pingcap/tidb/server/conn.go:2313\ngithub.com/pingcap/tidb/server.(*clientConn).writeResultSet\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/s
erver/conn.go:2256\ngithub.com/pingcap/tidb/server.(*clientConn).handleStmt\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2124\
ngithub.com/pingcap/tidb/server.(*clientConn).handleQuery\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1885\ngithub.com/pingca
p/tidb/server.(*clientConn).dispatch\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1372\ngithub.com/pingcap/tidb/server.(*clien
tConn).Run\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1153\ngithub.com/pingcap/tidb/server.(*Server).onConn\n\t/home/jenkins
/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/server.go:677"]

[2023/08/02 19:25:55.343 +08:00] [INFO] [conn.go:1184] ["command dispatched failed"] [conn=2966429595181515201] [connInfo="id:2966429595181515201, addr:127.0.0.1:25170 statu
s:10, collation:utf8_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="SELECT `estimate_year_month`,\n`a_manager_yid`                                               AS `manager_yid`,\n`real_t1_volume`,\n`real_t0_volume`,\n`a_estimate_volume` + IFNULL(`b_estimate_volume`, 0)          AS `estimate_volume`,\nIFNULL(`a`.`increase_sum`, 0) + IFNULL(`b`.`increase_sum`, 0) AS `increase_sum`,\nIFNULL(`a`.`decrease_sum`, 0) + IFNULL(`b`.`decrease_sum`, 0) AS `decrease_sum`\nFROM (SELECT `estimate_year_month`,\n`manager_yid`          AS `a_manager_yid`,\nSUM(`real_t1_volume`)  AS `real_t1_volume`,\nSUM(`real_t0_volume`)  AS `real_t0_volume`,\nSUM(`estimate_volume`) AS `a_estimate_volume`,\nSUM(IF(`estimate_volume` > `real_t1_volume`,`estimate_volume` - `real_t1_volume`,0))             AS `increase_sum`,\nSUM(IF(`estimate_volume` < `real_t1_volume`,`estimate_volume` - `real_t1_volume`,0))             AS `decrease_sum`\nFROM `rd_crm`.`signed_estimate_volume`\nWHERE `estimate_year_month` = DATE_FORMAT(NOW(), _UTF8MB4'%Y%m')\nAND `is_dropped` = 0\nAND `data_type` = 1\nGROUP BY `manager_yid`) AS `a`\nLEFT JOIN (SELECT `manager_yid`          AS `b_manager_yid`,\nSUM(`estimate_volume`) AS `b_estimate_volume`,\nSUM(`estimate_volume`) AS `increase_sum`,\n0                      AS `decrease_sum`\nFROM `rd_crm`.`unsigned_estimate_volume`\nWHERE `estimate_year_month` = DATE_FORMAT(NOW(), '%Y%m')\nAND `is_dropped` = 0\nAND `data_type` = 1\nGROUP BY `manager_yid`) AS `b`\nON a.`a_manager_yid` = b.`b_manager_yid`"] [txn_mode=PESSIMISTIC] [timestamp=443279095937105953] [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/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:147\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:884\nruntime.goPanicIndex\n\t/usr/local/go/src/runtime/panic.go:113\ngithub.com/pingcap/tidb/util/chunk.(*Column).IsNull\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/column.go:169\ngithub.com/pingcap/tidb/expression.(*builtinIfNullIntSig).vecEvalInt\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/builtin_control_vec_generated.go:846\ngithub.com/pingcap/tidb/expression.(*ScalarFunction).VecEvalInt\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/scalar_function.go:48\ngithub.com/pingcap/tidb/expression.(*builtinCastIntAsDecimalSig).vecEvalDecimal\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/builtin_cast_vec.go:1081\ngithub.com/pingcap/tidb/expression.(*ScalarFunction).VecEvalDecimal\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/scalar_function.go:63\ngithub.com/pingcap/tidb/expression.(*builtinArithmeticPlusDecimalSig).vecEvalDecimal\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/builtin_arithmetic_vec.go:994\ngithub.com/pingcap/tidb/expression.(*ScalarFunction).VecEvalDecimal\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/scalar_function.go:63\ngithub.com/pingcap/tidb/expression.evalOneVec\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/chunk_executor.go:163\ngithub.com/pingcap/tidb/expression.(*defaultEvaluator).run\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/evaluator.go:53\ngithub.com/pingcap/tidb/expression.(*EvaluatorSuite).Run\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/evaluator.go:125\ngithub.com/pingcap/tidb/executor.(*ProjectionExec).unParallelExecute\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/projection.go:205\ngithub.com/pingcap/tidb/executor.(*ProjectionExec).Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/projection.go:183\ngithub.com/pingcap/tidb/executor.Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/executor.go:326\ngithub.com/pingcap/tidb/executor.(*ExecStmt).next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:1202\ngithub.com/pingcap/tidb/executor.(*recordSet).Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:151\ngithub.com/pingcap/tidb/server.(*tidbResultSet).Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/driver_tidb.go:469\ngithub.com/pingcap/tidb/server.(*clientConn).writeChunks\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2313\ngithub.com/pingcap/tidb/server.(*clientConn).writeResultSet\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2256\ngithub.com/pingcap/tidb/server.(*clientConn).handleStmt\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2124\ngithub.com/pingcap/tidb/server.(*clientConn).handleQuery\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1885\ngithub.com/pingcap/tidb/server.(*clientConn).dispatch\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1372\ngithub.com/pingcap/tidb/server.(*clientConn).Run\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1153\ngithub.com/pingcap/tidb/server.(*Server).onConn\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/server.go:677\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1598"]

sql 去掉其中一部分,会执行成功

SUM(IF(`estimate_volume` < `real_t1_volume`,`estimate_volume` - `real_t1_volume`,0))             AS `decrease_sum`

有bug地址吗

报错信息
runtime error: index out of range [0] with length 0

补充说明,7.1.0能执行成功


sql 本身确实有冗余的地方,7.1.1 可能进行了某种优化,引入了这个bug

去掉最外层查询的 IFNULL(b.increase_sum, 0) 也可以执行成功

嗯,这个提示是,数据库中的数据不一致

这两张表的定义可否贴下?
FROM rd_crm.signed_estimate_volume
FROM rd_crm.unsigned_estimate_volume

空表执行sql,可以执行成功。

CREATE TABLE `signed_estimate_volume` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '',
  `estimate_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `broker_id` varchar(40) NOT NULL DEFAULT '' COMMENT '',
  `broker_name` varchar(128) NOT NULL DEFAULT '' COMMENT '',
  `dealer_id` varchar(40) NOT NULL DEFAULT '' COMMENT '',
  `dealer_name` varchar(128) NOT NULL DEFAULT '' COMMENT '',
  `signed_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
  `is_t0_signed` tinyint(1) NOT NULL DEFAULT '0' COMMENT '',
  `service_status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '',
  `virtual_tag_id` varchar(128) NOT NULL DEFAULT '' COMMENT '',
  `virtual_tag_name` varchar(256) NOT NULL DEFAULT '' COMMENT '',
  `virtual_tag_label` tinyint(1) NOT NULL DEFAULT '0' COMMENT '',
  `origin_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '',
  `origin_level2` int(11) NOT NULL DEFAULT '0' COMMENT '',
  `origin_level3` int(11) NOT NULL DEFAULT '0' COMMENT '',
  `broker_enterprise_id` varchar(40) NOT NULL DEFAULT '' COMMENT '',
  `business_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `customer_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `real_t0_volume` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `real_t1_volume` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `real_t2_volume` bigint(20) NOT NULL DEFAULT '0' COMMENT ',
  `real_t3_volume` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `estimate_volume` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `estimate_real_t1_percent_rate` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `estimate_diff` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `estimate_real_t1_diff` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `estimate_real_t1_diff_reason` varchar(256) NOT NULL DEFAULT '' COMMENT '',
  `leader_estimate_volume` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `leader_manager_diff_reason` varchar(256) NOT NULL DEFAULT '' COMMENT '',
  `real_t0_estimate_percent_rate` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `estimate_cnt` int(11) NOT NULL DEFAULT '0' COMMENT '',
  `estimate_updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
  `manager_yid` varchar(32) NOT NULL DEFAULT '' COMMENT '',
  `manager_percent` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `estimate_year_month` varchar(8) NOT NULL DEFAULT '' COMMENT '',
  `is_dropped` tinyint(1) NOT NULL DEFAULT '0' COMMENT '',
  `data_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '',
  `ycrm_estimate_id` varchar(64) NOT NULL DEFAULT '' COMMENT '',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
  `created_user` varchar(32) NOT NULL DEFAULT '' COMMENT '',
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
  `updated_user` varchar(32) NOT NULL DEFAULT '' COMMENT '',
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,
  UNIQUE KEY `UNIQ_ESTIMATE_ID` (`estimate_id`),
  UNIQUE KEY `UNIQ_MONTH_YID_BROKER_DEALER_DROPPED` (`estimate_year_month`,`manager_yid`,`broker_id`,`dealer_id`,`is_dropped`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=630002 COMMENT='';


 CREATE TABLE `unsigned_estimate_volume` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '',
  `estimate_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `estimate_year_month` varchar(8) NOT NULL DEFAULT '' COMMENT '',
  `business_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `customer_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `virtual_tag_id` varchar(128) NOT NULL DEFAULT '' COMMENT '',
  `virtual_tag_name` varchar(256) NOT NULL DEFAULT '' COMMENT '',
  `broker_enterprise_id` varchar(40) NOT NULL DEFAULT '' COMMENT '',
  `broker_id` varchar(40) NOT NULL DEFAULT '' COMMENT '',
  `broker_name` varchar(128) NOT NULL DEFAULT '' COMMENT '',
  `estimate_volume` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `estimate_diff` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `leader_estimate_volume` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `leader_manager_diff_reason` varchar(256) NOT NULL DEFAULT '' COMMENT '',
  `estimate_cnt` int(11) NOT NULL DEFAULT '0' COMMENT '',
  `manager_yid` varchar(32) NOT NULL DEFAULT '' COMMENT '',
  `manager_percent` bigint(20) NOT NULL DEFAULT '0' COMMENT '',
  `remark` varchar(255) NOT NULL DEFAULT '' COMMENT '',
  `is_dropped` tinyint(1) NOT NULL DEFAULT '0' COMMENT '',
  `data_type` tinyint(4) NOT NULL DEFAULT '1' COMMENT '',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
  `created_user` varchar(32) NOT NULL DEFAULT '' COMMENT '',
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '',
  `updated_user` varchar(32) NOT NULL DEFAULT '' COMMENT '',
  `estimate_updated_at` datetime DEFAULT NULL COMMENT '',
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,
  UNIQUE KEY `UNIQ_SIGNED_ESTIMATE_ID` (`estimate_id`),
  UNIQUE KEY `UNIQ_BUSINESS_DEALER_MONTH_YID` (`estimate_year_month`,`manager_yid`,`broker_id`,`business_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=390525 COMMENT='待签约关系预估体量表';

我也遇到这个错误了,我的是由于字段(+别名)重复出现导致。目前产研在调查,可以通过修改sql临时解决。

1 个赞

大佬,相同的表结构,相同的数据在7.1.0没问题。您能确定下是否有这样情况么。

我反馈下这个问题~

是个 bug,这个 issue 跟踪:https://github.com/pingcap/tidb/issues/45805
相关帖子:select 单表报错 SQL 错误 [1105] [HY000]: runtime error: index out of range [0] with length 0

此话题已在最后回复的 60 天后被自动关闭。不再允许新回复。