# [FAQ] Sync_diff_inspector reported oom when trying to compare data

## Key Words

failed to check data difference, sync-diff-inspector

## Description

上游 TiDB，下游 TiDB，通过 sync-diff-inspector 进行校验的时候报 failed to check data，具体操作流程如下：

```sql
drop table if exists test.x;
create table test.x(a int, b int, primary key(a,b) nonclustered);
insert into test.x values (0,1),(1,2),(2,3),(3,4);
insert into test.x select a,b+4 from test.x;
insert into test.x select a,b+8 from test.x;
insert into test.x select a,b+16 from test.x;
insert into test.x select a,b+32 from test.x;
insert into test.x select a,b+64 from test.x;
insert into test.x select a,b+128 from test.x;
insert into test.x select a,b+256 from test.x;
insert into test.x select a,b+512 from test.x;
insert into test.x select a,b+1024 from test.x;
insert into test.x select a,b+2048 from test.x;
insert into test.x select a,b+4096 from test.x;
insert into test.x select a,b+8192 from test.x;
insert into test.x select a,b+16384 from test.x;
insert into test.x select a,b+32768 from test.x;
analyze table x;

show stats_buckets where db_name = 'test' and table_name = 'x';
/*
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Bucket_id | Count | Repeats | Lower_Bound | Upper_Bound | Ndv  |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
| test    | x          |                | PRIMARY     |        1 |         0 |   255 |       1 | (0, 2001)   | (0, 3017)   |    0 |
...
| test    | x          |                | PRIMARY     |        1 |       255 | 65036 |       1 | (3, 65496)  | (3, 65536)  |    0 |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
256 rows in set (0.00 sec)
*/

-- 更換主鍵
alter table x drop primary key;
alter table x add primary key (b);

show stats_buckets where db_name = 'test' and table_name = 'x';
/*
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Bucket_id | Count | Repeats | Lower_Bound | Upper_Bound | Ndv  |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
| test    | x          |                | PRIMARY     |        1 |         0 |   255 |       1 | (0, 2001)   | (0, 3017)   |    0 |
...
| test    | x          |                | PRIMARY     |        1 |       255 | 65535 |       1 | 65306       | 65535       |    0 |
+---------+------------+----------------+-------------+----------+-----------+-------+---------+-------------+-------------+------+
512 rows in set (0.00 sec)
*/
```

```yaml
heck-struct-only = false

[data-sources.db]
host = '127.0.0.1'
port = 4000
user = 'root'
password = ''

[task]
output-dir = '/tmp/sync-diff-inspector'
source-instances = ['db']
target-instance = 'db'
target-check-tables = ['test.x']
$ bin/sync_diff_inspector -C sdi.toml
A total of 1 tables need to be compared

Comparing the table structure of ``test`.`x`` ... equivalent
Comparing the table data of ``test`.`x`` ...
_____________________________________________________________________________
Progress [>------------------------------------------------------------] 0% 0/0
There is something error when compare data of table, please check log info in /tmp/sync-diff-inspector/sync_diff.log
[2022/09/30 18:04:33.212 +08:00] [FATAL] [main.go:135] ["failed to check data difference"] [error="analyze value (3, 6332) failed"] ...
```

## Content

sync-diff-inspector 在校验的时候使用了统计信息，但是在做了添加索引和删除索引后 stats buckets 会存在超过一份统计信息。需要删除 stats 信息然后重新收集。需要将统计信息清掉，然后重新进收集。

```sql
MySQL [test]>drop stats x;
MySQL [test]>analyze table x;
```

## Affected Versions

All