mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
A bug fix and test case for a bug that appears in quereis where there
is a GROUP BY a column that is not NOT NULL and ORDER BY is done by another column. Even better fix would be to make a separate function for this.
This commit is contained in:
@ -393,3 +393,26 @@ One Two sum(Four)
|
|||||||
1 2 16
|
1 2 16
|
||||||
1 3 16
|
1 3 16
|
||||||
drop table if exists t1;
|
drop table if exists t1;
|
||||||
|
drop table if exists t1,t2;
|
||||||
|
create table t1 (id integer primary key not null auto_increment, gender char(1));
|
||||||
|
insert into t1 values(NULL, 'M');
|
||||||
|
insert into t1 values(NULL, 'F');
|
||||||
|
insert into t1 values(NULL, 'F');
|
||||||
|
insert into t1 values(NULL, 'F');
|
||||||
|
insert into t1 values(NULL, 'M');
|
||||||
|
create table t2 (user_id integer not null, timestamp datetime);
|
||||||
|
insert into t2 values (1, sysdate());
|
||||||
|
insert into t2 values (2, sysdate());
|
||||||
|
insert into t2 values (1, sysdate());
|
||||||
|
insert into t2 values (3, sysdate());
|
||||||
|
insert into t2 values (4, sysdate());
|
||||||
|
insert into t2 values (4, sysdate());
|
||||||
|
select u.gender as gender, count(distinct u.id) as dist_count, (count(distinct u.id)/5*100) as percentage from t1 u, t2 l where l.user_id = u.id group by u.gender;
|
||||||
|
gender dist_count percentage
|
||||||
|
F 3 60.00
|
||||||
|
M 1 20.00
|
||||||
|
select u.gender as gender, count(distinct u.id) as dist_count, (count(distinct u.id)/5*100) as percentage from t1 u, t2 l where l.user_id = u.id group by u.gender order by percentage;
|
||||||
|
gender dist_count percentage
|
||||||
|
M 1 20.00
|
||||||
|
F 3 60.00
|
||||||
|
drop table t1,t2;
|
||||||
|
@ -299,3 +299,20 @@ insert into t1 values (1,3,3,4);
|
|||||||
insert into t1 values (1,3,4,4);
|
insert into t1 values (1,3,4,4);
|
||||||
select One, Two, sum(Four) from t1 group by One,Two;
|
select One, Two, sum(Four) from t1 group by One,Two;
|
||||||
drop table if exists t1;
|
drop table if exists t1;
|
||||||
|
drop table if exists t1,t2;
|
||||||
|
create table t1 (id integer primary key not null auto_increment, gender char(1));
|
||||||
|
insert into t1 values(NULL, 'M');
|
||||||
|
insert into t1 values(NULL, 'F');
|
||||||
|
insert into t1 values(NULL, 'F');
|
||||||
|
insert into t1 values(NULL, 'F');
|
||||||
|
insert into t1 values(NULL, 'M');
|
||||||
|
create table t2 (user_id integer not null, timestamp datetime);
|
||||||
|
insert into t2 values (1, sysdate());
|
||||||
|
insert into t2 values (2, sysdate());
|
||||||
|
insert into t2 values (1, sysdate());
|
||||||
|
insert into t2 values (3, sysdate());
|
||||||
|
insert into t2 values (4, sysdate());
|
||||||
|
insert into t2 values (4, sysdate());
|
||||||
|
select u.gender as gender, count(distinct u.id) as dist_count, (count(distinct u.id)/5*100) as percentage from t1 u, t2 l where l.user_id = u.id group by u.gender;
|
||||||
|
select u.gender as gender, count(distinct u.id) as dist_count, (count(distinct u.id)/5*100) as percentage from t1 u, t2 l where l.user_id = u.id group by u.gender order by percentage;
|
||||||
|
drop table t1,t2;
|
||||||
|
@ -135,7 +135,7 @@ static TABLE *get_sort_by_table(ORDER *a,ORDER *b,TABLE_LIST *tables);
|
|||||||
static void calc_group_buffer(JOIN *join,ORDER *group);
|
static void calc_group_buffer(JOIN *join,ORDER *group);
|
||||||
static bool alloc_group_fields(JOIN *join,ORDER *group);
|
static bool alloc_group_fields(JOIN *join,ORDER *group);
|
||||||
static bool make_sum_func_list(JOIN *join,List<Item> &fields);
|
static bool make_sum_func_list(JOIN *join,List<Item> &fields);
|
||||||
static bool change_to_use_tmp_fields(List<Item> &func);
|
static bool change_to_use_tmp_fields(List<Item> &func, bool change=false);
|
||||||
static bool change_refs_to_tmp_fields(THD *thd, List<Item> &func);
|
static bool change_refs_to_tmp_fields(THD *thd, List<Item> &func);
|
||||||
static void init_tmptable_sum_functions(Item_sum **func);
|
static void init_tmptable_sum_functions(Item_sum **func);
|
||||||
static void update_tmptable_sum_func(Item_sum **func,TABLE *tmp_table);
|
static void update_tmptable_sum_func(Item_sum **func,TABLE *tmp_table);
|
||||||
@ -788,7 +788,7 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
|
|||||||
tmp_table=tmp_table2;
|
tmp_table=tmp_table2;
|
||||||
join.join_tab[0].table=0; // Table is freed
|
join.join_tab[0].table=0; // Table is freed
|
||||||
|
|
||||||
if (change_to_use_tmp_fields(all_fields)) // No sum funcs anymore
|
if (change_to_use_tmp_fields(all_fields,true)) // No sum funcs anymore
|
||||||
goto err;
|
goto err;
|
||||||
join.tmp_table_param.field_count+=join.tmp_table_param.sum_func_count;
|
join.tmp_table_param.field_count+=join.tmp_table_param.sum_func_count;
|
||||||
join.tmp_table_param.sum_func_count=0;
|
join.tmp_table_param.sum_func_count=0;
|
||||||
@ -6764,7 +6764,7 @@ make_sum_func_list(JOIN *join,List<Item> &fields)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
change_to_use_tmp_fields(List<Item> &items)
|
change_to_use_tmp_fields(List<Item> &items, bool change)
|
||||||
{
|
{
|
||||||
List_iterator<Item> it(items);
|
List_iterator<Item> it(items);
|
||||||
Item *item_field,*item;
|
Item *item_field,*item;
|
||||||
@ -6776,6 +6776,11 @@ change_to_use_tmp_fields(List<Item> &items)
|
|||||||
continue;
|
continue;
|
||||||
if (item->type() == Item::FIELD_ITEM)
|
if (item->type() == Item::FIELD_ITEM)
|
||||||
{
|
{
|
||||||
|
if (change)
|
||||||
|
{
|
||||||
|
((Item_field*) item)->result_field->null_ptr=0;
|
||||||
|
item->maybe_null=0;
|
||||||
|
}
|
||||||
((Item_field*) item)->field=
|
((Item_field*) item)->field=
|
||||||
((Item_field*) item)->result_field;
|
((Item_field*) item)->result_field;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user