summaryrefslogtreecommitdiff
path: root/sql/item_sum.cc
diff options
context:
space:
mode:
authorunknown <sergefp@mysql.com>2007-09-14 14:53:13 +0400
committerunknown <sergefp@mysql.com>2007-09-14 14:53:13 +0400
commit466747d57081b4bdfe166ff16da8ac9da99900e4 (patch)
tree366498aa227f237ef0ac7c133a28cc69a402fdb3 /sql/item_sum.cc
parentee0b7d895d42b0e3c93bdbffa7c4d3f51c1f60c2 (diff)
downloadmariadb-git-466747d57081b4bdfe166ff16da8ac9da99900e4.tar.gz
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 contiguous 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: BUG#30324: Grouping queries with COUNT(DISTINCT bit column) return wrong results - Testcase mysql-test/t/type_bit.test: BUG#30324: Grouping queries with COUNT(DISTINCT bit column) return wrong results - Testcase sql/item_sum.cc: 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.
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r--sql/item_sum.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index fe9f58d84e1..c20d3fba705 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -2464,6 +2464,23 @@ bool Item_sum_count_distinct::setup(THD *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<Item> 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),