Open wjhuang2016 opened 4 months ago
the warning in the tidb:
+---------+------+----------------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
+---------+------+----------------------------------------------------+
the warning in the Mysql.
+---------+------+--------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+--------------------------------------------------------------------------+
| Warning | 1411 | Incorrect string value: '`test`.`t1d90f49d`.`col_54`' for function unhex |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1411 | Incorrect string value: '`test`.`t1d90f49d`.`col_54`' for function unhex |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1411 | Incorrect string value: '`test`.`t1d90f49d`.`col_54`' for function unhex |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1411 | Incorrect string value: '`test`.`t1d90f49d`.`col_54`' for function unhex |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1411 | Incorrect string value: '`test`.`t1d90f49d`.`col_54`' for function unhex |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1411 | Incorrect string value: '`test`.`t1d90f49d`.`col_54`' for function unhex |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1411 | Incorrect string value: '`test`.`t1d90f49d`.`col_54`' for function unhex |
| Warning | 1292 | Truncated incorrect DOUBLE value: 'e#G7dW&F#*HP7!' |
| Warning | 1411 | Incorrect string value: '`test`.`t1d90f49d`.`col_54`' for function unhex |
UNHEX() Function will return different values for 0 (decimal(1, 0)) and 0.0 (decimal(7, 1)).
In the SQL query, The subquery's condition t1d90f49d.col_54 IN (0) is rewritten as t1d90f49d.col_54 eq 0 (decimal(1, 0)).
Then, during predicate pushdown, "ISNULL(st_3578.r1)" condition in the WHERE clause is pushed down into the subquery, and the condition "t1d90f49d.col_54 eq 0 (decimal(1, 0))" is used to do constant propagation.
Here’s how the constant propagation works:
The final result is always false as shown below:
tidb> select ISNULL(UNHEX(cast(0 as decimal(1, 0))));
+-----------------------------------------+
| ISNULL(UNHEX(cast(0 as decimal(1, 0)))) |
+-----------------------------------------+
| 0 |
+-----------------------------------------+
1 row in set (0.01 sec)
Since the result is always false, WHERE clause: (ISNULL(UNHEX(t1d90f49d.col_54)) and t1d90f49d.col_54 IN (0)) is always false too, which makes the subquery always empty.
If we don't do predicate push down, "ISNULL(st_3578.r1)" will use col_54 ( 0.0 decimal(7, 1) ) as args like : ISNULL( UNHEX(0.0) ).
The final result is always true as shown below:
tidb> select ISNULL(UNHEX(cast(0.0 as decimal(7, 1))));
+-------------------------------------------+
| ISNULL(UNHEX(cast(0.0 as decimal(7, 1)))) |
+-------------------------------------------+
| 1 |
+-------------------------------------------+
1 row in set (0.00 sec)
To validate this, we can disable predicate push down:
tidb> INSERT INTO mysql.opt_rule_blacklist VALUES("predicate_push_down");
Query OK, 1 row affected (0.02 sec)
tidb> ADMIN reload opt_rule_blacklist;
Query OK, 0 rows affected (0.00 sec)
tidb> SELECT count(1) as cnt
-> FROM `tl14db775f`
-> JOIN
-> (
-> SELECT `t1d90f49d`.`col_54` AS `r0`,UNHEX(`t1d90f49d`.`col_54`) AS `r1`
-> FROM `t1d90f49d`
-> WHERE `t1d90f49d`.`col_54` IN (0)
-> ) AS `st_3578` ON `tl14db775f`.`col_16`=`st_3578`.`r0`
-> WHERE `tl14db775f`.`col_21` BETWEEN 2526.40073820865 AND 3321.717840116553 AND ISNULL(`st_3578`.`r1`);
+------+
| cnt |
+------+
| 1197 |
+------+
1 row in set, 1197 warnings (0.03 sec)
Also, we can modify the condition "WHERE t1d90f49d.col_54 IN (0)" to "WHERE t1d90f49d.col_54 IN (0.0)":
tidb> delete from mysql.opt_rule_blacklist;
Query OK, 1 row affected (0.00 sec)
tidb> admin reload opt_rule_blacklist;
Query OK, 0 rows affected (0.01 sec)
tidb> SELECT count(1) as cnt
-> FROM `tl14db775f`
-> JOIN
-> (
-> SELECT `t1d90f49d`.`col_54` AS `r0`,UNHEX(`t1d90f49d`.`col_54`) AS `r1`
-> FROM `t1d90f49d`
-> WHERE `t1d90f49d`.`col_54` IN (0.0)
-> ) AS `st_3578` ON `tl14db775f`.`col_16`=`st_3578`.`r0`
-> WHERE `tl14db775f`.`col_21` BETWEEN 2526.40073820865 AND 3321.717840116553 AND ISNULL(`st_3578`.`r1`);
+------+
| cnt |
+------+
| 1197 |
+------+
1 row in set, 7 warnings (0.01 sec)
Hi , @hawkingrei
Is the behavior I'm seeing with decimal(1, 0) vs decimal(7, 1) expected in TiDB? If not, what’s the recommended approach to resolve this issue?
Any guidance would be appreciated!
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
MySQL:
3. What did you see instead (Required)
TiDB:
4. What is your TiDB version? (Required)
73472c2f3f9625b02013c5e4e9be563bb6ca9ca4