From: Date: September 8 2007 6:23pm Subject: bk commit into 5.0 tree (sergefp:1.2513) BUG#30324 List-Archive: http://lists.mysql.com/commits/33963 X-Bug: 30324 Message-Id: <20070908162356.EC1E8FBC15@pylon.mylan> Below is the list of changes that have just been committed into a local 5.0 repository of psergey. When psergey does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2007-09-08 20:23:52+04:00, sergefp@stripped +3 -0 BUG#30324: Grouping queries with COUNT(DISTINCT bit column) return wrong results - The bug was caused by COUNT(DISTINCT ...) code using Unique object in a way that assumed that BIT(N) column occupies a continous space in temp_table->record[0] buffer. - The fix is to make COUNT(DISTINCT ...) code instruct create_tmp_table to create temporary table with column of type BIGINT, not BIT(N). mysql-test/r/type_bit.result@stripped, 2007-09-08 20:23:49+04:00, sergefp@stripped +15 -0 BUG#30324: Grouping queries with COUNT(DISTINCT bit column) return wrong results - Testcase mysql-test/t/type_bit.test@stripped, 2007-09-08 20:23:49+04:00, sergefp@stripped +14 -0 BUG#30324: Grouping queries with COUNT(DISTINCT bit column) return wrong results - Testcase sql/item_sum.cc@stripped, 2007-09-08 20:23:49+04:00, sergefp@stripped +17 -0 BUG#30324: Grouping queries with COUNT(DISTINCT bit column) return wrong results - Make COUNT(DISTINCT ...) code instruct create_tmp_table to create temporary table with BIGINT, not BIT(N) column. diff -Nrup a/mysql-test/r/type_bit.result b/mysql-test/r/type_bit.result --- a/mysql-test/r/type_bit.result 2007-08-17 18:29:10 +04:00 +++ b/mysql-test/r/type_bit.result 2007-09-08 20:23:49 +04:00 @@ -657,4 +657,19 @@ b # # DROP TABLE t1; +CREATE TABLE t1 (a int, b bit(2)); +INSERT INTO t1 VALUES (3, 2), (2, 3), (2, 0), (3, 2), (3, 1); +SELECT COUNT(DISTINCT b) FROM t1 GROUP BY a; +COUNT(DISTINCT b) +2 +2 +DROP TABLE t1; +create table t2 (a int, b bit(2), c char(10)); +INSERT INTO t2 VALUES (3, 2, 'two'), (2, 3, 'three'), (2, 0, 'zero'), +(3, 2, 'two'), (3, 1, 'one'); +SELECT COUNT(DISTINCT b,c) FROM t2 GROUP BY a; +COUNT(DISTINCT b,c) +2 +2 +DROP TABLE t2; End of 5.0 tests diff -Nrup a/mysql-test/t/type_bit.test b/mysql-test/t/type_bit.test --- a/mysql-test/t/type_bit.test 2007-08-17 18:28:48 +04:00 +++ b/mysql-test/t/type_bit.test 2007-09-08 20:23:49 +04:00 @@ -304,4 +304,18 @@ SELECT b FROM t1 GROUP BY b; --disable_metadata DROP TABLE t1; +# +# BUG#30324 Wrong query result for COUNT(DISTINCT(bit_column)) +# +CREATE TABLE t1 (a int, b bit(2)); +INSERT INTO t1 VALUES (3, 2), (2, 3), (2, 0), (3, 2), (3, 1); +SELECT COUNT(DISTINCT b) FROM t1 GROUP BY a; +DROP TABLE t1; + +create table t2 (a int, b bit(2), c char(10)); +INSERT INTO t2 VALUES (3, 2, 'two'), (2, 3, 'three'), (2, 0, 'zero'), + (3, 2, 'two'), (3, 1, 'one'); +SELECT COUNT(DISTINCT b,c) FROM t2 GROUP BY a; +DROP TABLE t2; + --echo End of 5.0 tests diff -Nrup a/sql/item_sum.cc b/sql/item_sum.cc --- a/sql/item_sum.cc 2007-07-19 20:20:54 +04:00 +++ b/sql/item_sum.cc 2007-09-08 20:23:49 +04:00 @@ -2464,6 +2464,23 @@ bool Item_sum_count_distinct::setup(THD count_field_types(select_lex, tmp_table_param, list, 0); tmp_table_param->force_copy_fields= force_copy_fields; DBUG_ASSERT(table == 0); + /* + Make create_tmp_table() convert BIT columns to BIGINT. + This is needed because BIT fields store parts of their data in table's + null bits, and we don't have methods to compare two table records, which + is needed by Unique which is used when HEAP table is used. + */ + { + List_iterator_fast li(list); + Item *item; + while ((item= li++)) + { + if (item->type() == Item::FIELD_ITEM && + ((Item_field*)item)->field->type() == FIELD_TYPE_BIT) + item->marker=4; + } + } + if (!(table= create_tmp_table(thd, tmp_table_param, list, (ORDER*) 0, 1, 0, (select_lex->options | thd->options),