Bug #56881 | NULL left operand to NOT IN in WHERE clause behaves differently than real NULL | ||
---|---|---|---|
Submitted: | 20 Sep 2010 21:17 | Modified: | 23 May 2011 17:49 |
Reporter: | Roland Bouman | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
Version: | 5.1 | OS: | Any (ubuntu linux, ms windows xp) |
Assigned to: | CPU Architecture: | Any |
[20 Sep 2010 21:17]
Roland Bouman
[20 Sep 2010 21:27]
Roland Bouman
(added version info, os-es, and severity. Severity is serious as the query results are affected)
[21 Sep 2010 3:20]
Valeriy Kravchuk
Verified with current mysql-5.1 from bzr: macbook-pro:5.1 openxs$ bin/mysql -uroot test Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 5.1.51-debug Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE TABLE parent (id int); Query OK, 0 rows affected (0.39 sec) mysql> INSERT INTO parent VALUES (1), (2); Query OK, 2 rows affected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> mysql> CREATE TABLE child (parent_id int, other int); Query OK, 0 rows affected (0.20 sec) mysql> INSERT INTO child VALUES (1,NULL); Query OK, 1 row affected (0.00 sec) mysql> SELECT p.id, c.parent_id, -> c.parent_id NOT IN ( -> SELECT parent_id -> FROM child -> WHERE parent_id = 3 -> ) notin -> FROM parent p -> LEFT JOIN child c -> ON p.id = c.parent_id -> ; +------+-----------+-------+ | id | parent_id | notin | +------+-----------+-------+ | 1 | 1 | 1 | | 2 | NULL | 1 | +------+-----------+-------+ 2 rows in set (0.02 sec) mysql> SELECT p.id, c.parent_id -> FROM parent p -> LEFT JOIN child c -> ON p.id = c.parent_id -> WHERE c.parent_id NOT IN ( -> SELECT parent_id -> FROM child -> WHERE parent_id = 3 -> ) -> ; +------+-----------+ | id | parent_id | +------+-----------+ | 1 | 1 | +------+-----------+ 1 row in set (0.01 sec) mysql> SELECT p.id, c.parent_id, c.other -> FROM parent p -> LEFT JOIN child c -> ON p.id = c.parent_id -> WHERE c.other NOT IN ( -> SELECT parent_id -> FROM child -> WHERE parent_id = 3 -> ) -> ; +------+-----------+-------+ | id | parent_id | other | +------+-----------+-------+ | 1 | 1 | NULL | +------+-----------+-------+ 1 row in set (0.01 sec)
[23 May 2011 17:50]
Paul DuBois
Noted in 5.6.3 changelog. For an outer join with a NOT IN subquery in the WHERE clause, a null left operand to the NOT IN returned was treated differently than a literal NULL operand. CHANGESET - http://lists.mysql.com/commits/136714