[MDEV-4363] Bad selectivity for col IS NULL OR col IS NOT NULL Created: 2013-04-03  Updated: 2013-04-07  Resolved: 2013-04-07

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Sergei Petrunia Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: mwl#253

Issue Links:
Relates
relates to MDEV-4145 Take into account the selectivity of ... Closed

 Description   

Take a dataset and settings from MDEV-4362.

Then lets add another column with another distribution:

alter table t5 add col2 int;
update t5 set col2=NULL where col2 < 33;
update t5 set col2=NULL where col1 < 33;
update t5 set col2=178 where col1 >= 33 and col1 < 66;
update t5 set col2=47 where col1 >= 66 and col1 < 77;
set @a=11;
update t5 set col2=(@a:=@a+1) where col1 >= 77;
analyze table t5 persistent for all;

Let's first check for NULLs:

MariaDB [j10]> explain extended select  * from t5 where col2 IS NULL;
+------+-------------+-------+------+---------------+------+---------+------+-------+----------+-------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows  | filtered | Extra       |
+------+-------------+-------+------+---------------+------+---------+------+-------+----------+-------------+
|    1 | SIMPLE      | t5    | ALL  | NULL          | NULL | NULL    | NULL | 10000 |    33.00 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+-------+----------+-------------+
1 row in set, 1 warning (0.00 sec)

Correct.

MariaDB [j10]> explain extended select  * from t5 where col2 IS not NULL;
+------+-------------+-------+------+---------------+------+---------+------+-------+----------+-------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows  | filtered | Extra       |
+------+-------------+-------+------+---------------+------+---------+------+-------+----------+-------------+
|    1 | SIMPLE      | t5    | ALL  | NULL          | NULL | NULL    | NULL | 10000 |    65.01 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+-------+----------+-------------+
1 row in set, 1 warning (0.00 sec)

Also correct, a precise estimate.

MariaDB [j10]> explain extended select  * from t5 where col2 IS not NULL or col2 is null;
+------+-------------+-------+------+---------------+------+---------+------+-------+----------+-------------+
| id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows  | filtered | Extra       |
+------+-------------+-------+------+---------------+------+---------+------+-------+----------+-------------+
|    1 | SIMPLE      | t5    | ALL  | NULL          | NULL | NULL    | NULL | 10000 |    65.01 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+-------+----------+-------------+
1 row in set, 1 warning (0.00 sec)

Ooops. Why is selectivity still 65% ?



 Comments   
Comment by Igor Babaev [ 2013-04-07 ]

A fix for the bug has been pushed into maria-10.0-mwl253.

Generated at Thu Feb 08 06:55:51 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.