tidb icon indicating copy to clipboard operation
tidb copied to clipboard

ranger returns wrong empty range for `null` filter

Open eurekaka opened this issue 8 years ago • 1 comments

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a recipe for reproducing the error.
MySQL [test]> create table t(a int, b int, index a_idx(a));
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> insert into t values(1,1),(2,2),(null,3);
Query OK, 3 rows affected (0.00 sec)

MySQL [test]> select * from t;
+------+------+
| a    | b    |
+------+------+
|    1 |    1 |
|    2 |    2 |
| NULL |    3 |
+------+------+
3 rows in set (0.00 sec)

MySQL [test]> explain select * from t where a = null;
+-------------------+-------+------+--------------------------------------------------+
| id                | count | task | operator info                                    |
+-------------------+-------+------+--------------------------------------------------+
| IndexLookUp_10    | 0.00  | root |                                                  |
| ├─IndexScan_8     | 0.00  | cop  | table:t, index:a, keep order:false, stats:pseudo |
| └─TableScan_9     | 0.00  | cop  | table:t, keep order:false, stats:pseudo          |
+-------------------+-------+------+--------------------------------------------------+
3 rows in set (0.00 sec)

MySQL [test]> select * from t where a = null;
Empty set (0.00 sec)
  1. What did you expect to see?

third row of the table should be returned, i.e, | NULL | 3 |

  1. What did you see instead?

empty set returned.

  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
MySQL [test]> select tidb_version();
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                                    |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v2.1.0-rc.1-18-geec6899
Git Commit Hash: eec68995689d5811f4d52846586e969652ed8ffc
Git Branch: master
UTC Build Time: 2018-09-01 06:53:29
GoVersion: go version go1.11rc1 linux/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

eurekaka avatar Sep 02 '18 04:09 eurekaka

Hmm, I just figured out NULL = NULL is false, so the result is right. Close this issue.

MySQL [test]> select * from t where a is null;
+------+------+
| a    | b    |
+------+------+
| NULL |    3 |
+------+------+
1 row in set (0.00 sec)

MySQL [test]> explain select * from t where a is null;
+-------------------+-------+------+---------------------------------------------------------------------+
| id                | count | task | operator info                                                       |
+-------------------+-------+------+---------------------------------------------------------------------+
| IndexLookUp_10    | 0.00  | root |                                                                     |
| ├─IndexScan_8     | 0.00  | cop  | table:t, index:a, range:[NULL,NULL], keep order:false, stats:pseudo |
| └─TableScan_9     | 0.00  | cop  | table:t, keep order:false, stats:pseudo                             |
+-------------------+-------+------+---------------------------------------------------------------------+
3 rows in set (0.00 sec)

eurekaka avatar Sep 02 '18 04:09 eurekaka