Comment 6 for bug 611379

Revision history for this message
Igor Babaev (igorb-seattle) wrote :

The following simple test case displays the same behavior as the test case in the submitted report.

MariaDB [test]> create table t1 (a int not null);
Query OK, 0 rows affected (0.00 sec)

MariaDB [test]> insert into t1 values (1);
Query OK, 1 row affected (0.00 sec)

MariaDB [test]> create table t2 (a int not null primary key);
Query OK, 0 rows affected (0.00 sec)

MariaDB [test]> insert into t2 values (10);
Query OK, 1 row affected (0.01 sec)

MariaDB [test]> explain select sum(distinct t1.a) from t1,t2 where t1.a=t2.a;
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Impossible WHERE noticed after reading const tables |
+----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [test]> explain select * from (select sum(distinct t1.a) from t1,t2 where t1.a=t2.a) as t;
+----+-------------+------------+--------+---------------+------+---------+------+------+-----------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+--------+---------------+------+---------+------+------+-----------------------------------------------------+
| 1 | PRIMARY | <derived2> | system | NULL | NULL | NULL | NULL | 1 | |
| 2 | DERIVED | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Impossible WHERE noticed after reading const tables |
+----+-------------+------------+--------+---------------+------+---------+------+------+-----------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [test]> select sum(distinct t1.a) from t1,t2 where t1.a=t2.a;
+--------------------+
| sum(distinct t1.a) |
+--------------------+
| NULL |
+--------------------+
1 row in set (0.00 sec)

MariaDB [test]> select * from (select sum(distinct t1.a) from t1,t2 where t1.a=t2.a) as t;
+--------------------+
| sum(distinct t1.a) |
+--------------------+
| 0 |
+--------------------+
1 row in set (0.00 sec)

Both queries must return
+--------------------+
| sum(distinct t1.a) |
+--------------------+
| NULL |
+--------------------+

I've checked that absolutely the same problem we have with mysql-5.1.49 and with the current mysql-5.1 development tree.