Description:
If you have two count(distinct x) expressions in a query then you will get back different (incorrect) results if you have an index on both of the the distinct columns.
How to repeat:
mysql> create table test(a int, b int);
Query OK, 0 rows affected (0.14 sec)
mysql> insert into test(a,b) values(1, 1);
Query OK, 1 row affected (0.00 sec)
mysql> insert into test(a,b) values(1, 2);
Query OK, 1 row affected (0.00 sec)
mysql> insert into test(a,b) values(1, 3);
Query OK, 1 row affected (0.01 sec)
mysql> insert into test(a,b) values(1, 4);
Query OK, 1 row affected (0.00 sec)
mysql> insert into test(a,b) values(1, 5);
Query OK, 1 row affected (0.00 sec)
mysql> select SQL_NO_CACHE count(distinct a), count(distinct b) from test;
+-------------------+-------------------+
| count(distinct a) | count(distinct b) |
+-------------------+-------------------+
| 1 | 5 |
+-------------------+-------------------+
1 row in set (0.00 sec)
mysql> alter table test add index (a,b);
Query OK, 0 rows affected (0.12 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> select SQL_NO_CACHE count(distinct a), count(distinct b) from test;
+-------------------+-------------------+
| count(distinct a) | count(distinct b) |
+-------------------+-------------------+
| 5 | 5 |
+-------------------+-------------------+
1 row in set (0.01 sec)