summaryrefslogtreecommitdiff
path: root/sql/item_sum.h
diff options
context:
space:
mode:
authorevgen@moonbone.local <>2006-03-29 23:30:34 +0400
committerevgen@moonbone.local <>2006-03-29 23:30:34 +0400
commit1c13e54890029509c9817e8aa15a5dcda944bb2f (patch)
tree0d5a34019f582b2773c068e7856108aeb993e64b /sql/item_sum.h
parent678e075ecf4b89de737f9bb5c8c2f9e9e28cfa1c (diff)
downloadmariadb-git-1c13e54890029509c9817e8aa15a5dcda944bb2f.tar.gz
Fixed bug#15560: GROUP_CONCAT wasn't ready for WITH ROLLUP queries
The GROUP_CONCAT uses its own temporary table. When ROLLUP is present it creates the second copy of Item_func_group_concat. This copy receives the same list of arguments that original group_concat does. When the copy is set up the result_fields of functions from the argument list are reset to the temporary table of this copy. As a result of this action data from functions flow directly to the ROLLUP copy and the original group_concat functions shows wrong result. Since queries with COUNT(DISTINCT ...) use temporary tables to store the results the COUNT function they are also affected by this bug. The idea of the fix is to copy content of the result_field for the function under GROUP_CONCAT/COUNT from the first temporary table to the second one, rather than setting result_field to point to the second temporary table. To achieve this goal force_copy_fields flag is added to Item_func_group_concat and Item_sum_count_distinct classes. This flag is initialized to 0 and set to 1 into the make_unique() member function of both classes. To the TMP_TABLE_PARAM structure is modified to include the similar flag as well. The create_tmp_table() function passes that flag to create_tmp_field(). When the flag is set the create_tmp_field() function will set result_field as a source field and will not reset that result field to newly created field for Item_func_result_field and its descendants. Due to this there will be created copy func to copy data from old result_field to newly created field.
Diffstat (limited to 'sql/item_sum.h')
-rw-r--r--sql/item_sum.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/sql/item_sum.h b/sql/item_sum.h
index d53d8d861ae..c972240fcba 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -185,6 +185,7 @@ class Item_sum_count_distinct :public Item_sum_int
TMP_TABLE_PARAM *tmp_table_param;
TREE tree_base;
TREE *tree;
+ bool force_copy_fields;
/*
Following is 0 normal object and pointer to original one for copy
(to correctly free resources)
@@ -226,15 +227,16 @@ class Item_sum_count_distinct :public Item_sum_int
public:
Item_sum_count_distinct(List<Item> &list)
:Item_sum_int(list), table(0), used_table_cache(~(table_map) 0),
- tmp_table_param(0), tree(&tree_base), original(0), use_tree(0),
- always_null(0)
+ tmp_table_param(0), tree(&tree_base), force_copy_fields(0), original(0),
+ use_tree(0), always_null(0)
{ quick_group= 0; }
Item_sum_count_distinct(THD *thd, Item_sum_count_distinct *item)
:Item_sum_int(thd, item), table(item->table),
used_table_cache(item->used_table_cache),
field_lengths(item->field_lengths),
tmp_table_param(item->tmp_table_param),
- tree(item->tree), original(item), key_length(item->key_length),
+ tree(item->tree), force_copy_fields(item->force_copy_fields),
+ original(item), key_length(item->key_length),
max_elements_in_tree(item->max_elements_in_tree),
rec_offset(item->rec_offset), use_tree(item->use_tree),
always_null(item->always_null)
@@ -685,6 +687,7 @@ class Item_func_group_concat : public Item_sum
bool distinct;
bool warning_for_row;
bool always_null;
+ bool force_copy_fields;
friend int group_concat_key_cmp_with_distinct(void* arg, byte* key1,
byte* key2);