# [Know Issue] 分区表在 dynamic 模式下 analyze table 报错 ERROR 1105 (HY000): runtime error: index out of range

## Key Words

 dynamic, index out of range

## Description

 分区表在 dynamic 模式下 analyze table 时遇到报错 ERROR 1105 (HY000): runtime error: index out of range

 ```sql
 CREATE TABLE t1 ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, num float(9,8) DEFAULT NULL, PRIMARY KEY (id)  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin PARTITION BY HASH (id) PARTITIONS 128;
 source t1.sql;
 analyze table t1;
 ERROR 1105 (HY000): runtime error: index out of range [24] with length 24 
 ```

## Root Cause

代码 BUG，具体参考 Github Issue：<https://github.com/pingcap/tidb/issues/35910>
In fieldType2Flag, both TypeFloat and TypeDouble will set datum flag as FloatFlag. However, TypeFloat will add Float32 in chunk while we directly GetFloat64 in DecodeOne function, which caused out of range error

## Diagnostic Steps

1.查看分区表模式为 [dynamic](https://docs.pingcap.com/tidb/stable/partitioned-table#dynamic-pruning-mode)

```sql
select @@session.tidb_partition_prune_mode
```

2.查看 tidb.log 日志，报错的错误栈和以下信息匹配

 ```sql
 [2022/07/01 19:03:47.901 +08:00] [ERROR] [conn.go:1031] ["connection running loop panic"] [conn=18195] [lastSQL="analyze table t1"] [err="runtime error: index out of range [24] with length 24"] [stack="goroutine 30613891 [running]:\ngithub.com/pingcap/tidb/server.(*clientConn).Run.func1(0x4511bd0, 0xc00779a690, 0xc0044492c0)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1029 +0xf5\npanic(0x3d4b9c0, 0xc0037455a8)\n\t/usr/local/go/src/runtime/panic.go:965 +0x1b9\ngithub.com/pingcap/tidb/executor.(*ExecStmt).Exec.func1(0xc005566c30, 0xc00aae6a18, 0xc00aae69f8)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:362 +0x4d4\npanic(0x3d4b9c0, 0xc0037455a8)\n\t/usr/local/go/src/runtime/panic.go:965 +0x1b9\ngithub.com/pingcap/tidb/util/chunk.(*Column).GetFloat64(...)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/column.go:555\ngithub.com/pingcap/tidb/util/chunk.Row.GetFloat64(...)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/row.go:68\ngithub.com/pingcap/tidb/util/chunk.Compare(0xc00984d590, 0x3, 0x0, 0xc00aae5450, 0x0)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/compare.go:195 +0xb65\ngithub.com/pingcap/tidb/util/chunk.(*Chunk).LowerBound.func1(0x3, 0x9)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/compare.go:227 +0x6b\nsort.Search(0x6, 0xc00aae53b8, 0x16)\n\t/usr/local/go/src/sort/search.go:66 +0x58\ngithub.com/pingcap/tidb/util/chunk.(*Chunk).LowerBound(0xc00984d590, 0x0, 0xc00aae5450, 0x264eb80, 0x0)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/compare.go:226 +0x8d\ngithub.com/pingcap/tidb/statistics.(*Histogram).equalRowCount(0xc005b944d0, 0x4, 0x3f24a781e0000000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/statistics/histogram.go:433 +0x46\ngithub.com/pingcap/tidb/statistics.MergePartTopN2GlobalTopN(0xc00470cc60, 0x2, 0xc002ffcc00, 0x80, 0x80, 0x1f4, 0xc001c11400, 0x80, 0x80, 0xc003796000, ...)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/statistics/cmsketch.go:771 +0x590\ngithub.com/pingcap/tidb/statistics/handle.(*Handle).mergePartitionStats2GlobalStats(0xc001aa6000, 0x4588688, 0xc002d01600, 0xc009a14d20, 0x45524d8, 0xc02cad01c0, 0xc005a41520, 0x0, 0xc0087347a0, 0x2, ...)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/statistics/handle/handle.go:469 +0x1499\ngithub.com/pingcap/tidb/statistics/handle.(*Handle).MergePartitionStats2GlobalStatsByTableID(0xc001aa6000, 0x4588688, 0xc002d01600, 0xc009a14d20, 0x45524d8, 0xc02cad01c0, 0xdde, 0x0, 0xc0087347a0, 0x2, ...)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/statistics/handle/handle.go:365 +0x14c\ngithub.com/pingcap/tidb/executor.(*AnalyzeExec).Next(0xc00549f040, 0x4511bd0, 0xc009a15380, 0xc006a511d0, 0x0, 0xc005dea628)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/analyze.go:197 +0x13c5\ngithub.com/pingcap/tidb/executor.Next(0x4511bd0, 0xc009a15380, 0x4516940, 0xc00549f040, 0xc006a511d0, 0x0, 0x0)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/executor.go:286 +0x2de\ngithub.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelayExecutor(0xc005566c30, 0x4511bd0, 0xc009a15380, 0x4516940, 0xc00549f040, 0x0, 0x0, 0x0, 0x0)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:635 +0x33c\ngithub.com/pingcap/tidb/executor.(*ExecStmt).handleNoDelay(0xc005566c30, 0x4511bd0, 0xc009a15380, 0x4516940, 0xc00549f040, 0x644cb00, 0x4511b01, 0x0, 0x0, 0x0, ...)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:490 +0x1e5\ngithub.com/pingcap/tidb/executor.(*ExecStmt).Exec(0xc005566c30, 0x4511bd0, 0xc009a15380, 0x0, 0x0, 0x0, 0x0)\n\t/home/jenkins/aget/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:439 +0x72e\ngithub.com/pingcap/tidb/session.runStmt(0x4511bd0, 0xc009a14480, 0xc002d01600, 0x4528c00, 0xc005566c30, 0x0, 0x0, 0x0, 0x0)\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com"]
 ```

## Resolution

升级到 v5.4.3 或 v6.1.1 及以上版本

## Workaround

N/A

## Affected Versions

 [~, v5.4.3)，6.0.0，6.1.0
