# [Know Issue] Sync_diff_inspector 检查失败但未打印 fixsql 

## Key Words

zerofill, 不打印 fix.sql

## Description

使用 Sync_diff_inspector 验证上游 MySQL 下游 TiDB 数据一致性，显示数据不一致，在 `export-fix-sql = true` 的条件下只生成了 fix 文件, 但是文件中不打印任何 fixsql。

## Root Cause

1. Sync_diff_inspector 会先使用数据库内部函数直接计算 checksum 值进行对比, 如果值不同会进入行级别对比阶段，直接把上下游拉到 Sync_diff_inspector 中, 并转成 go 对应的数据类型对比。从 MySQL 8.0.17 开始，zerofill 语法被[弃用](https://dev.mysql.com/doc/refman/8.0/en/floating-point-types.html)，并且 TiDB 不支持 MySQL 中标记为弃用的功能。

2. 因为 TiDB 与 MySQL 对 zerofill 特性是否补 0 的行为存在差异, 所以直接在上下游数据库使用 checksum 函数计算的结果会不一致, 导致对比失败。但 Sync_diff_inspector 为打印 fix.sql 还需要行级对比生成具体的 delete/replace sql 语句, 而这时的行为是将上下游对应的数据拉到执行程序中, 转换成 go 语言对应的类型而非数据库中的数据类型, 比如下述测试案例: INT(8) 类型且值为 1 的行数据, 在 Sync_diff_inspector 无论上下游拉取到的结果都是 1, 对比结果一致导致不产生 fix.sql。

3. MySQL 中的测试结果

    ```sql
    mysql> CREATE TABLE jan (x INT(8) ZEROFILL);
    Query OK, 0 rows affected, 2 warnings (0.02 sec)

    mysql> show warnings;
    +---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Level   | Code | Message                                                                                                                                                                   |
    +---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Warning | 1681 | The ZEROFILL attribute is deprecated and will be removed in a future release. Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column. |
    | Warning | 1681 | Integer display width is deprecated and will be removed in a future release.                                                                                              |
    +---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    2 rows in set (0.00 sec)

    mysql> insert into jan values (1);
    Query OK, 1 row affected (0.00 sec)

    mysql> select * from jan;
    +----------+
    | x        |
    +----------+
    | 00000001 |
    +----------+
    1 row in set (0.00 sec)

    mysql> select version();
    +-----------+
    | version() |
    +-----------+
    | 8.0.33    |
    +-----------+
    1 row in set (0.00 sec)
    ```

4. TiDB 中的测试结果

    ```sql
    ysql> CREATE TABLE jan (x INT(8) ZEROFILL);
    Query OK, 0 rows affected (0.10 sec)
    
    mysql> insert into jan values (1);
    Query OK, 1 row affected (0.01 sec)
    
    mysql> select * from jan;
    +------+
    | x    |
    +------+
    |    1 |
    +------+
    1 row in set (0.00 sec)
    
    mysql> select version();
    +--------------------+
    | version()          |
    +--------------------+
    | 5.7.25-TiDB-v7.0.0 |
    +--------------------+
    1 row in set (0.00 sec)
    ```

## Diagnostic Steps

1. 对比表结构中含有 ZEROFILL 关键字
2. 检查失败但未打印 fixsql 

## Resolution

使用 [ignore-columns](https://docs.pingcap.com/zh/tidb/stable/sync-diff-inspector-overview#sync-diff-inspector-%E7%9A%84%E4%BD%BF%E7%94%A8%E9%99%90%E5%88%B6) 特性将该列忽略的方式绕过，详情参照官方使用方法。

## Affected Versions

TiDB  > v5.0.0 （精度范围内不自动补 0）
