Bug #82044 | COUNT(DISTINCT) query with WHERE clause returns an Incorrect number of rows | ||
---|---|---|---|
Submitted: | 29 Jun 2016 7:59 | Modified: | 12 Jul 2016 15:19 |
Reporter: | 광복 이 | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 5.7.9 | OS: | Ubuntu (12.04.4 LTS) |
Assigned to: | CPU Architecture: | Any | |
Tags: | 5.7.13, COUNT(DISTINCT) query, MySQL, ncorrect number of rows |
[29 Jun 2016 7:59]
광복 이
[4 Jul 2016 15:13]
MySQL Verification Team
Thank you for your bug report. Can you let us know whether you have tested 5.7.13 and whether this problems is solved now ????
[5 Jul 2016 0:30]
광복 이
This test was done in 5.7.9. I want to update to 5.7.13 soon. But I'm hesitatingfor the this bug. This count(distinct) pattern queries are one of main service queries of my business. In fact, I don't know whether the bug is solved or not in Mysql5.7.13. I'm waiting for your REPLY. Please let me know the bug is resolved in 5.7.13 ~
[5 Jul 2016 13:49]
MySQL Verification Team
I have checked ChangeLog from 5.7.9 to 5.7.14 and I did not find any reference similar to the behavior that you describe. Hence, what we need is to repeat this bug. So, please can you upload your table to this bug report using the "Files" tab. We need your data in order to repeat the problem. Only if we repeat the problem would we be able to verify this report as an unfixed bug.
[12 Jul 2016 15:19]
MySQL Verification Team
I have just tested this with 5.7.13 and there are no problems. Please, do note that it was tested with and without an index on the aggregated column ... Here is copy / paste from my session: ./client/mysql sinbas -e " show create table t1" +-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | t1 | CREATE TABLE `t1` ( `id1` bigint(20) NOT NULL, `id2` bigint(20) NOT NULL, `id3` bigint(20) NOT NULL, `c1` bigint(20) DEFAULT NULL, `c2` bigint(20) NOT NULL, `seqid` bigint(20) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id1`,`id2`), UNIQUE KEY `ix_seq` (`seqid`), KEY `sinisa` (`id1`) ) ENGINE=InnoDB AUTO_INCREMENT=1782 DEFAULT CHARSET=utf8 | +-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ [smilivoj@local mysql-5.7.13]$ ./client/mysql sinbas -e " select count(distinct id1) from t1" +---------------------+ | count(distinct id1) | +---------------------+ | 876 | +---------------------+ [smilivoj@local mysql-5.7.13]$ ./client/mysql sinbas -e " select count(*) total from (select 1 from t1 group by t1.id1) a" +-------+ | total | +-------+ | 876 | +-------+ [smilivoj@local mysql-5.7.13]$ ./client/mysql sinbas -e "drop index sinisa on t1" [smilivoj@local mysql-5.7.13]$ ./client/mysql sinbas -e " show create table t1"+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | t1 | CREATE TABLE `t1` ( `id1` bigint(20) NOT NULL, `id2` bigint(20) NOT NULL, `id3` bigint(20) NOT NULL, `c1` bigint(20) DEFAULT NULL, `c2` bigint(20) NOT NULL, `seqid` bigint(20) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id1`,`id2`), UNIQUE KEY `ix_seq` (`seqid`) ) ENGINE=InnoDB AUTO_INCREMENT=1782 DEFAULT CHARSET=utf8 | +-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ [smilivoj@local mysql-5.7.13]$ ./client/mysql sinbas -e " select count(distinct id1) from t1"+---------------------+ | count(distinct id1) | +---------------------+ | 876 | +---------------------+ [smilivoj@local mysql-5.7.13]$ ./client/mysql sinbas -e " select count(*) total from (select 1 from t1 group by t1.id1) a" +-------+ | total | +-------+ | 876 | +-------+ This effort definitely closes this bug.