Skip to content
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

use <nil> to represent NULL is weird #6935

Closed
zz-jason opened this issue Jun 28, 2018 · 0 comments · Fixed by #7041
Closed

use <nil> to represent NULL is weird #6935

zz-jason opened this issue Jun 28, 2018 · 0 comments · Fixed by #7041
Assignees

Comments

@zz-jason
Copy link
Member

let's say we have the following table:

drop table if exists t;
create table t(a char(20), index idx_a(a));

The following two queries result in the same explain result but they represent different DML queries:

desc select * from t where a = "<nil>";
desc select * from t where a is null;
TiDB(localhost:4000) > desc select * from t where a = "<nil>";
+-------------------+------+---------------------------------------------------------+-------+
| id                | task | operator info                                           | count |
+-------------------+------+---------------------------------------------------------+-------+
| IndexReader_9     | root | index:IndexScan_8                                       | 10.00 |
| └─IndexScan_8     | cop  | table:t, index:a, range:[<nil>,<nil>], keep order:false | 10.00 |
+-------------------+------+---------------------------------------------------------+-------+
2 rows in set (0.00 sec)

TiDB(localhost:4000) > desc select * from t where a is null;
+-------------------+------+---------------------------------------------------------+-------+
| id                | task | operator info                                           | count |
+-------------------+------+---------------------------------------------------------+-------+
| IndexReader_9     | root | index:IndexScan_8                                       | 10.00 |
| └─IndexScan_8     | cop  | table:t, index:a, range:[<nil>,<nil>], keep order:false | 10.00 |
+-------------------+------+---------------------------------------------------------+-------+
2 rows in set (0.00 sec)

Actually no mater what string we use to represent NULL, there is a chance that a is null and a = xx can result in the same range representation once the string we use to represent is equal to xx.

A way to solve this problem is to wrap strings with ", we can use the string "NULL" to represent NULL, which means we can distinguish NULL from other strings:

TiDB(localhost:4000) > desc select * from t where a = "NULL";
+-------------------+------+---------------------------------------------------------+-------+
| id                | task | operator info                                           | count |
+-------------------+------+---------------------------------------------------------+-------+
| IndexReader_9     | root | index:IndexScan_8                                       | 10.00 |
| └─IndexScan_8     | cop  | table:t, index:a, range:["NULL","NULL"], keep order:false | 10.00 |
+-------------------+------+---------------------------------------------------------+-------+
2 rows in set (0.00 sec)

TiDB(localhost:4000) > desc select * from t where a is null;
+-------------------+------+---------------------------------------------------------+-------+
| id                | task | operator info                                           | count |
+-------------------+------+---------------------------------------------------------+-------+
| IndexReader_9     | root | index:IndexScan_8                                       | 10.00 |
| └─IndexScan_8     | cop  | table:t, index:a, range:[NULL,NULL], keep order:false | 10.00 |
+-------------------+------+---------------------------------------------------------+-------+
2 rows in set (0.00 sec)
@zz-jason zz-jason added type/enhancement help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. status/TODO sig/planner SIG: Planner labels Jun 28, 2018
@zz-jason zz-jason self-assigned this Jul 12, 2018
@zz-jason zz-jason added status/WIP and removed help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. status/TODO labels Jul 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant