Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: analyze table出现runtime error: slice bounds out of range [-1:]的错误
The error message is:
[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:]"]
This table is very small, select *
works fine, and there are no issues with business usage, but analyze table
reports an error.
Do all other tables report the same error when collecting statistics, or is it just this table? Please post the table structure of this table, if convenient.
CREATE TABLE `account_stat` (
`service_account_id` varchar(30) NOT NULL COMMENT 'Service Account ID',
`cal_date` date NOT NULL COMMENT 'Calculation Date',
`broker` varchar(10) NOT NULL COMMENT 'Channel Code',
`broker_user_id` varchar(255) NOT NULL COMMENT 'Upper-level Customer ID',
`po_code` varchar(10) NOT NULL COMMENT 'Investment Strategy Code',
`open_position_flag` varchar(1) NOT NULL COMMENT 'Is Open Position Y/N',
`deviation_rate` decimal(20,4) NOT NULL DEFAULT '0.0000' COMMENT 'Actual Deviation Rate',
`refer_deviation_rate` decimal(20,4) NOT NULL DEFAULT '0.0000' COMMENT 'Reference Deviation Rate for Custom Account',
`total_asset` decimal(20,6) NOT NULL COMMENT 'Total Assets of the Account for the Day',
`turnover_rate` decimal(14,8) DEFAULT '0.00000000' COMMENT 'Turnover Rate',
`processing_amount` decimal(14,8) DEFAULT '0.00000000' COMMENT 'In-transit Assets = 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 'Transaction Account Collection, Comma-separated',
`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='Custom Account PMS Indicator Storage Table'
Currently, only this table has an issue, all other tables are normal.
The table structure is fine, I can collect it here. Can you display the entire table with “select * from account_stat”? I see there are just over 3000 rows.
Yes, this has already been tried, it’s not a data issue.
admin check is also normal.
So strange, it is probably triggered by a TiDB bug. I suggest creating a new table and transferring the current data to see what happens…
Using the syntax ANALYZE TABLE TableName COLUMNS ColumnNameList
, it was found that the error was caused by the JSON field. Could it be that the array in the JSON is out of bounds?
I manually added several large JSON files, but did not reproduce this issue…
This issue only appeared after running online for a month. I tried importing the data into a new table but couldn’t reproduce it. I guess it will require code-level analysis.
Amazing, after a day, running analyze table
doesn’t report an error, but running analyze
on that JSON field still reports an error.
Hello,
It should be a BUG. The related issue is [stats] auto analyze failed · Issue #35948 · pingcap/tidb · GitHub. We are working hard to fix it, and there is no workaround at the moment.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.