Compatibility Issues of Implicit Conversion Between TiDB and MySQL

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 关于TIDB与MySQL隐式转换兼容性问题

| username: TiDBer_fy4M8OAI

[TiDB Usage Environment] Online
[TiDB Version] 5.7.25-TiDB-v6.1.0
[Encountered Problem] Due to historical reasons, the foreign key type of the main table is varchar, while the associated key type of the secondary table is Bigint. When performing a join, an implicit conversion occurs, converting both keys to double type for matching, resulting in precision loss and joining to other rows in the secondary table.
[Reproduction Path]
Due to confidentiality of the business database, I created two tables to reproduce the scenario:

CREATE TABLE `tmp_t1`  (
  `id` bigint(20) NOT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Compact;
INSERT INTO `tmp_t1` VALUES (1295772036504131620);
INSERT INTO `tmp_t1` VALUES (1295772036504131621);

CREATE TABLE `tmp_t2`  (
  `id` bigint(20) NOT NULL,
  `id_f` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Compact;
INSERT INTO `tmp_t2` VALUES (11, '1295772036504131620');

[Problem Phenomenon and Impact]
[Query Statement]

SELECT * from tmp_t2 t2 LEFT JOIN tmp_t1 t1 on t2.id_f = t1.id

[Query Result]

|11|1295772036504131620|1295772036504131620|
|11|1295772036504131620|1295772036504131621|

[Personal Thoughts]
I later forced a conversion, and it worked fine. I understand the cause of the issue, and although it stems from some non-standard practices during development, I still want to bring it up. This query runs without issues on MySQL. If a business database is switched from MySQL to TiDB, this problem might not be easily detected and could lead to severe production incidents. TiDB has indeed made many efforts to be compatible with MySQL, and I hope TiDB continues to improve. Small issues like this can damage its reputation, and different companies and individuals may not be able to accept it. Encountering small issues that are not easy to troubleshoot might lead to the perception that the product is immature.

| username: yilong | Original post link

Thank you very much for your feedback. We have recorded an issue, and you can follow it.

Once there is a response to this issue, you can directly check the replies in the issue. Thank you.

| username: 张雨齐0720 | Original post link

Mark it.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.