analyze table出现runtime error: slice bounds out of range [-1:]的错误


报错内容是:

[2022/12/14 17:23:21.151 +08:00] [ERROR] [analyze.go:1435] ["analyze worker panicked"] [recover="runtime error: slice bounds out of range [-1:]"] [stack="github.com/pingcap/tidb/executor.(*AnalyzeColumnsExec).subBuildWorker.func1\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/analyze.go:1435\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:838\nruntime.goPanicSliceB\n\t/usr/local/go/src/runtime/panic.go:117\ngithub.com/pingcap/tidb/statistics.BuildHistAndTopN\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/statistics/builder.go:346\ngithub.com/pingcap/tidb/executor.(*AnalyzeColumnsExec).subBuildWorker\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/analyze.go:1559\ngithub.com/pingcap/tidb/executor.(*AnalyzeColumnsExec).buildSamplingStats.func3\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/analyze.go:1136\ngithub.com/pingcap/tidb/executor.(*notifyErrorWaitGroupWrapper).Run.func1\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/analyze.go:2653"]
[2022/12/14 17:23:21.152 +08:00] [ERROR] [analyze.go:151] ["analyze failed"] [error="runtime error: slice bounds out of range [-1:]"]
[2022/12/14 17:23:21.156 +08:00] [INFO] [analyze.go:252] ["analyze table `****`.`****` has failed"] [partition=] ["job info"="auto analyze table all columns with 256 buckets, 500 topn, 1 samplerate"] ["start time"=2022/12/14 17:23:21.052 +08:00] ["end time"=2022/12/14 17:23:21.152 +08:00] [cost=99.980454ms]
[2022/12/14 17:23:21.156 +08:00] [INFO] [tidb.go:264] ["rollbackTxn called due to ddl/autocommit failure"]
[2022/12/14 17:23:21.156 +08:00] [WARN] [session.go:1949] ["run statement failed"] [schemaVersion=963] [error="runtime error: slice bounds out of range [-1:]"] [session="{\n  \"currDBName\": \"\",\n  \"id\": 4481862282489364483,\n  \"status\": 2,\n  \"strictMode\": true,\n  \"user\": null\n}"]
[2022/12/14 17:23:21.156 +08:00] [ERROR] [update.go:1218] ["[stats] auto analyze failed"] [sql="analyze table `****`.`****`"] [cost_time=111.698937ms] [error="runtime error: slice bounds out of range [-1:]"]

这个表很小,select *没有问题,业务使用也没问题,但是analyze table会报错

其他所有的表收集统计信息都报一样的错吗?还是只有这个表?把这个表的表结构贴一下吧,方便的话。

CREATE TABLE `account_stat` (
  `service_account_id` varchar(30) NOT NULL COMMENT '服务账户ID',
  `cal_date` date NOT NULL COMMENT '计算日期',
  `broker` varchar(10) NOT NULL COMMENT '渠道编号',
  `broker_user_id` varchar(255) NOT NULL COMMENT '上层客户编号',
  `po_code` varchar(10) NOT NULL COMMENT '投顾策略代码',
  `open_position_flag` varchar(1) NOT NULL COMMENT '是否建仓中 Y是 N否',
  `deviation_rate` decimal(20,4) NOT NULL DEFAULT '0.0000' COMMENT 'ca实际偏离率',
  `refer_deviation_rate` decimal(20,4) NOT NULL DEFAULT '0.0000' COMMENT '定制账户参考偏离率',
  `total_asset` decimal(20,6) NOT NULL COMMENT '账号当日总资产',
  `turnover_rate` decimal(14,8) DEFAULT '0.00000000' COMMENT '换手率',
  `processing_amount` decimal(14,8) DEFAULT '0.00000000' COMMENT '在途资产 = total_asset-market_value',
  `fund_details` json NOT NULL COMMENT '[{"fundCode":"000509","amountSum":123.24,"shareSum":1234.23,"percentInPoAsset":0.2342}]',
  `txn_account_ids` varchar(1024) NOT NULL DEFAULT '' COMMENT '交易账户集合,逗号分割',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`service_account_id`,`cal_date`) /*T![clustered_index] CLUSTERED */,
  KEY `idx_po_code` (`cal_date`,`po_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='定制账户pms指标存储表'

现在是只有这一个表有问题,其他表都正常的。

表结构没问题,我这里可以收集,你select * from account_stat这个全表能都展示出来吗?,我看就3000多行

能的,这个已经试过了,不是数据上的问题


admin check也是正常的

好怪异,估计是触发了tidb的bug了,建议重新建一张表,把现在的数据灌过去看一下。。。


使用ANALYZE TABLE TableName COLUMNS ColumnNameList 的语法,试出来是json字段导致的报错,难道是指json中数组越界了?

我手工添加了几个超大的json进去,并没有复现这个问题。。。

这个线上也是运行了一个月才出现的,我试着把数据导入到新表里也不能复现,估计得代码级别分析了


神奇,过了一天,analyze table不会报错,但是对那个json字段来进行analyze,还是会报错

你好
应该是 BUG,相关 issue https://github.com/pingcap/tidb/issues/35948 ,正在努力修复,暂无 workaround。

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