Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions mysql-test/main/mdev_19039.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE TABLE t1 (i int);
INSERT INTO t1 VALUES (1), (1), (2), (2), (3), (3);
SELECT i, SUM(i) OVER () FROM t1 GROUP BY i ;
i SUM(i) OVER ()
1 6
2 6
3 6
SELECT i, SUM(i) OVER () FROM t1 GROUP BY i WITH ROLLUP;
i SUM(i) OVER ()
NULL 6
1 6
2 6
3 6
DROP TABLE t1;
7 changes: 7 additions & 0 deletions mysql-test/main/mdev_19039.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE t1 (i int);
INSERT INTO t1 VALUES (1), (1), (2), (2), (3), (3);

SELECT i, SUM(i) OVER () FROM t1 GROUP BY i ;
SELECT i, SUM(i) OVER () FROM t1 GROUP BY i WITH ROLLUP;

DROP TABLE t1;
42 changes: 24 additions & 18 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30577,9 +30577,10 @@ bool JOIN::rollup_init()
reinterpret_cast<Ref_ptr_array*>
(thd->alloc((sizeof(Ref_ptr_array) +
all_fields.elements * sizeof(Item*)) * send_group_parts));
rollup.fields= thd->alloc<List<Item> >(send_group_parts);

if (!null_items || !rollup.ref_pointer_arrays || !rollup.fields)
rollup.all_fields= thd->alloc<List<Item>>(send_group_parts);
rollup.fields_list= thd->alloc<List<Item>>(send_group_parts);
if (!null_items || !rollup.ref_pointer_arrays || !rollup.all_fields ||
!rollup.fields_list)
return true;

ref_array= (Item**) (rollup.ref_pointer_arrays+send_group_parts);
Expand All @@ -30593,15 +30594,22 @@ bool JOIN::rollup_init()
if (!(rollup.null_items[i]= new (thd->mem_root) Item_null_result(thd)))
return true;

List<Item> *rollup_fields= &rollup.fields[i];
List<Item> *rollup_fields= &rollup.all_fields[i];
rollup_fields->empty();
rollup.ref_pointer_arrays[i]= Ref_ptr_array(ref_array, all_fields.elements);
ref_array+= all_fields.elements;
}
uint hidden_fields= all_fields.elements - fields_list.elements;
for (i= 0 ; i < send_group_parts; i++)
{
for (j=0 ; j < fields_list.elements ; j++)
rollup.fields[i].push_back(rollup.null_items[i], thd->mem_root);
List_iterator_fast<Item> it(rollup.all_fields[i]);
for (j= 0; j < all_fields.elements; j++)
{
rollup.all_fields[i].push_back(rollup.null_items[i], thd->mem_root);
if (j < hidden_fields)
it++;
}
it.sublist(rollup.fields_list[i], fields_list.elements);
}
List_iterator<Item> it(all_fields);
Item *item;
Expand Down Expand Up @@ -30740,7 +30748,7 @@ bool JOIN::rollup_make_fields(List<Item> &fields_arg, List<Item> &sel_fields,
uint pos= send_group_parts - level -1;
bool real_fields= 0;
Item *item;
List_iterator<Item> new_it(rollup.fields[pos]);
List_iterator<Item> new_it(rollup.all_fields[pos]);
Ref_ptr_array ref_array_start= rollup.ref_pointer_arrays[pos];
ORDER *start_group;

Expand Down Expand Up @@ -30790,8 +30798,8 @@ bool JOIN::rollup_make_fields(List<Item> &fields_arg, List<Item> &sel_fields,
for (group_tmp= start_group, i= pos ;
group_tmp ; group_tmp= group_tmp->next, i++)
{
if (*group_tmp->item == item)
{
if (item->eq(*group_tmp->item, 0))
{
/*
This is an element that is used by the GROUP BY and should be
set to NULL in this level
Expand All @@ -30808,12 +30816,10 @@ bool JOIN::rollup_make_fields(List<Item> &fields_arg, List<Item> &sel_fields,
}
}
ref_array_start[ref_array_ix]= item;
(void) new_it++; // Point to next item
new_it.replace(item); // Replace previous
if (real_fields)
{
(void) new_it++; // Point to next item
new_it.replace(item); // Replace previous
ref_array_ix++;
}
ref_array_ix++;
else
ref_array_ix--;
}
Expand Down Expand Up @@ -30852,9 +30858,9 @@ int JOIN::rollup_send_data(uint idx)
if ((!having || having->val_bool()))
{
if (send_records < unit->lim.get_select_limit() && do_send_rows &&
(res= result->send_data_with_check(rollup.fields[i],
unit, send_records)) > 0)
return 1;
(res= result->send_data_with_check(rollup.fields_list[i], unit,
send_records)) > 0)
return 1;
if (!res)
send_records++;
}
Expand Down Expand Up @@ -30896,7 +30902,7 @@ int JOIN::rollup_write_data(uint idx, TMP_TABLE_PARAM *tmp_table_param_arg,
{
int write_error;
Item *item;
List_iterator_fast<Item> it(rollup.fields[i]);
List_iterator_fast<Item> it(rollup.all_fields[i]);
while ((item= it++))
{
if (item->type() == Item::NULL_ITEM && item->is_result_field())
Expand Down
3 changes: 2 additions & 1 deletion sql/sql_select.h
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,8 @@ typedef struct st_rollup
State state;
Item_null_array null_items;
Ref_ptr_array *ref_pointer_arrays;
List<Item> *fields;
List<Item> *all_fields;
List<Item> *fields_list;
} ROLLUP;


Expand Down
Loading