Bug #116566 List partition prune get a wrong result
Submitted: 6 Nov 2024 6:23 Modified: 6 Nov 2024 6:51
Reporter: hangjie Mo Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Partitions Severity:S3 (Non-critical)
Version:8.0.32, 8.0.40, 8.4.3, 9.1.0 OS:Any
Assigned to: CPU Architecture:Any

[6 Nov 2024 6:23] hangjie Mo
Description:
CREATE TABLE `tlist` (
  `a` int DEFAULT NULL,
  `b` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
/*!50100 PARTITION BY LIST (`a`)
(PARTITION p0 VALUES IN (0,1,2) ENGINE = InnoDB,
 PARTITION p1 VALUES IN (3,4,5) ENGINE = InnoDB,
 PARTITION p2 VALUES IN (6,7,8) ENGINE = InnoDB,
 PARTITION p3 VALUES IN (9,10,11) ENGINE = InnoDB,
 PARTITION p4 VALUES IN (NULL,-1) ENGINE = InnoDB);

mysql> explain select * from tlist where a not in (0, 1, 2, 3, 4, 5, 6, 7, 8, NULL);
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | tlist | p3,p4      | ALL  | NULL          | NULL | NULL    | NULL |    2 |    50.00 | Using where |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 1 warning (0.00 sec)

Because not in expression contains `NULL` value, so I think the partitions should be NULL here.

If I insert some values into table and use sql above, the results are always NULL.

insert into tlist values (9, 1),(-1, 2);

mysql> select * from tlist where a not in (0, 1, 2, 3, 4, 5, 6, 7, 8, NULL);
Empty set (0.00 sec)

How to repeat:
Follow description
[6 Nov 2024 6:51] MySQL Verification Team
Hello hangjie Mo,

Thank you for the report and feedback.

regards,
Umesh