Bug #70930 count distinct get error result

Submitted: 16 Nov 2013 15:51 Modified: 20 Nov 2013 14:01
Reporter: xiaobin lin (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S2 (Serious)
Version:5.1+, 5.5+, 5.6.14, 5.7.2-m12 OS:Any
Assigned to: CPU Architecture:Any
Tags: count, distinct, tmp_table_size

[16 Nov 2013 15:51] xiaobin lin
Description:
If tmp_table_size do not verify the requirement when execute merge_walk (sql/uniques.cc), a count(distinct) query will return "0" , seems buggy.

How to repeat:
drop table if exists tb;
set tmp_table_size=1024;
create table tb(id int auto_increment primary key, v varchar(32)) charset=gbk;
insert into tb(v) values("aaa");
insert into tb(v) (select v from tb);
insert into tb(v) (select v from tb);
insert into tb(v) (select v from tb);
insert into tb(v) (select v from tb);
insert into tb(v) (select v from tb);
insert into tb(v) (select v from tb);
insert into tb(v) (select v from tb);
insert into tb(v) (select v from tb);
update tb set v=concat(v, id); 
select count(distinct v) from tb;

seems duplicated with http://bugs.mysql.com/bug.php?id=52582

Suggested fix:
As merge_walk is almost the last step of a count(distinct) query, we can malloc temp buffer for it?
See in the patch.
[16 Nov 2013 15:52] xiaobin lin
base on 5.6

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: merge_walk_5613.diff (application/octet-stream, text), 1.77 KiB.

[18 Nov 2013 5:53] xiaobin lin
5.1 is ok. only 5.5 and 5.6 can repeat
[18 Nov 2013 6:15] MySQL Verification Team
Hello Xiaobin,
 
Thank you for the bug report and contribution.
Verified as described.

Thanks,
Umesh
[18 Nov 2013 7:45] xiaobin lin
In 5.1, it use max_heap_table_size to limit the memory used. 
So the case should set max_heap_table_size=16384, and need more data (65536 rows can repeat it)
[20 Nov 2013 12:28] Erlend Dahl
This has been fixed in 5.7.3 (to be released).
[20 Nov 2013 13:45] Erlend Dahl
This is BUG#17500866 in the 5.7.3 changelog (http://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-3.html). It was fixed independently before the contribution was received.
[20 Nov 2013 14:01] xiaobin lin
hi,  Erlend, get it.
Thank you. I am downing the bzr and will learn how it fixed in trunk :)

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.060 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.