-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect query reuslt caused by NULLIF keyword #51842
Comments
[17:53:53]TiDB root:test> SELECT NULLIF(v0.c0, 1371581446) <=> 1292367147 FROM v0, t0;
+------------------------------------------+
| NULLIF(v0.c0, 1371581446) <=> 1292367147 |
+------------------------------------------+
| 0 |
+------------------------------------------+
1 row in set
Time: 0.005s
[17:54:06]TiDB root:test> explain SELECT f1 FROM (SELECT NULLIF(v0.c0, 1371581446) AS f1 FROM v0, t0) AS t WHERE f1 <=> 1292367147;
+---------------------------+---------+-----------+---------------+----------------------------------------------------+
| id | estRows | task | access object | operator info |
+---------------------------+---------+-----------+---------------+----------------------------------------------------+
| Projection_13 | 1.00 | root | | if(eq(Column#3, <nil>), <nil>, Column#3)->Column#6 |
| └─HashJoin_15 | 1.00 | root | | CARTESIAN inner join |
| ├─Projection_19(Build) | 1.00 | root | | <nil>->Column#3 |
| │ └─TableReader_21 | 1.00 | root | | data:TableFullScan_20 |
| │ └─TableFullScan_20 | 1.00 | cop[tikv] | table:t0 | keep order:false |
| └─TableReader_18(Probe) | 1.00 | root | | data:TableFullScan_17 |
| └─TableFullScan_17 | 1.00 | cop[tikv] | table:t0 | keep order:false |
+---------------------------+---------+-----------+---------------+----------------------------------------------------+
7 rows in set
Time: 0.009s
[17:54:06]TiDB root:test> |
The root cause is there is a special rule when compare between duration and other types(I think is for some mysql compatibility): tidb/pkg/expression/builtin_compare.go Lines 1320 to 1326 in 968f4f2
when compare duration column and other constant, the constant will be converted to duration type For query
|
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
Consider the following statements.
In theory, query1 and query2 should return the same result. However, query1 return nothing
NULL
while query2 return nothing.2. What is your TiDB version? (Required)
v7.6.0, v6.4.0
The text was updated successfully, but these errors were encountered: