Closed wjhuang2016 closed 1 month ago
tidb:4000 [test]> SELECT WEIGHT_STRING(`t2592d2ba`.`col_2`) is null as col_12051 FROM `t2592d2ba` where col_1 = 2448007782;
+-----------+
| col_12051 |
+-----------+
| 1 |
+-----------+
1 row in set, 1 warning (0.00 sec)
tidb:4000 [test]> desc SELECT WEIGHT_STRING(`t2592d2ba`.`col_2`) is null as col_12051 FROM `t2592d2ba` where col_1 = 2448007782;
+-------------------+---------+------+-------------------------------+-----------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------+---------+------+-------------------------------+-----------------------------------------------------------------------------+
| Projection_6 | 1.00 | root | | isnull(weight_string(cast(test.t2592d2ba.col_2, var_string(20))))->Column#3 |
| └─Point_Get_7 | 1.00 | root | table:t2592d2ba, partition:p0 | handle:2448007782 |
+-------------------+---------+------+-------------------------------+-----------------------------------------------------------------------------+
2 rows in set, 1 warning (0.00 sec)
tidb:4000 [test]> SELECT WEIGHT_STRING(cast(`t2592d2ba`.`col_2` as char(20))) is null as col_12051 FROM `t2592d2ba` where col_1 = 2448007782;
+-----------+
| col_12051 |
+-----------+
| 0 |
+-----------+
1 row in set, 1 warning (0.00 sec)
tidb:4000 [test]> desc SELECT WEIGHT_STRING(cast(`t2592d2ba`.`col_2` as char(20))) is null as col_12051 FROM `t2592d2ba` where col_1 = 2448007782;
+-------------------+---------+------+-------------------------------+-----------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------+---------+------+-------------------------------+-----------------------------------------------------------------------------+
| Projection_6 | 1.00 | root | | isnull(weight_string(cast(test.t2592d2ba.col_2, var_string(20))))->Column#3 |
| └─Point_Get_7 | 1.00 | root | table:t2592d2ba, partition:p0 | handle:2448007782 |
+-------------------+---------+------+-------------------------------+-----------------------------------------------------------------------------+
2 rows in set, 1 warning (0.00 sec)
tidb:4000 [test]> SELECT WEIGHT_STRING(`t2592d2ba`.`col_2`) FROM `t2592d2ba` where col_1 = 2448007782;
+------------------------------------------------------------------------+
| WEIGHT_STRING(`t2592d2ba`.`col_2`) |
+------------------------------------------------------------------------+
| NULL |
+------------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
tidb:4000 [test]> SELECT WEIGHT_STRING(cast(`t2592d2ba`.`col_2` as char(20))) FROM `t2592d2ba` where col_1 = 2448007782;
+------------------------------------------------------------------------------------------------------------+
| WEIGHT_STRING(cast(`t2592d2ba`.`col_2` as char(20))) |
+------------------------------------------------------------------------------------------------------------+
| 0x1C3E |
+------------------------------------------------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
WEIGHT_STRING() is a debugging function intended for internal use. Its behavior can change without notice between MySQL versions. It can be used for testing and debugging of collations, especially if you are adding a new collation.
The severity of this issue can be marked as major or moderate
*expression.builtinWeightStringNullSig
is built when executing "SELECT WEIGHT_STRING(t2592d2ba
.col_2
)"
*expression.builtinWeightStringSig
is built when executing "SELECT WEIGHT_STRING(cast(t2592d2ba
.col_2
as char(20))) "
Seeing the same issue on v5.4.0 as well.
According to the implementation https://github.com/pingcap/tidb/blob/568cc224f7083925686d2212faf7043775542ce0/expression/builtin_string.go#L3688-L3690, weightString always returns null for numberic type. It is a designed behavior rather than a bug.
According to MySQL manual, If the input str
is numeric, the result of WEIGHT_STRING()
in MySQL is undefined.
cc @XuHuaiyu @bb7133
MySQL 5.7
mysql> SELECT WEIGHT_STRING(`t2592d2ba`.`col_2`) is null as col_12051 FROM `t2592d2ba` WHERE `t2592d2ba`.`col_2` = 0;
+-----------+
| col_12051 |
+-----------+
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
| 1 |
+-----------+
23 rows in set (0.00 sec)
mysql> select weight_string(0);
+------------------+
| weight_string(0) |
+------------------+
| NULL |
+------------------+
1 row in set (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.23 |
+-----------+
1 row in set (0.00 sec)
We do not plan to fix this issue, as the MySQL documentation does not clearly specify the return value when the parameter type is numeric. TiDB's current implementation is consistent with MySQL 5.7. Additionally, this is a debug function, not a user function that would be used in a production environment, so we will not be making any changes.
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
56c619f1f5ea8e3f9970fe664729074b5123683a