Commit 3a395a99 authored by unknown's avatar unknown

Bug fix for complicated GROUP BY ... ORDER BY query.

Fixed problem in access rights testing (from last patch)


mysql-test/r/group_by.result:
  Condenced GROUP test case
mysql-test/t/group_by.test:
  Condenced GROUP test case
sql/sql_parse.cc:
  Fixed problem in access rights testing (from last patch)
sql/sql_select.cc:
  Rollback Sinisa's GROUP BY patch and make a better one.
parent a9a49dc3
......@@ -375,38 +375,17 @@ hijklm 2
DROP TABLE t1;
drop table if exists t1;
create table t1 (One int unsigned, Two int unsigned, Three int unsigned, Four int unsigned);
insert into t1 values (1,2,1,4);
insert into t1 values (1,2,2,4);
insert into t1 values (1,2,3,4);
insert into t1 values (1,2,4,4);
insert into t1 values (1,1,1,4);
insert into t1 values (1,1,2,4);
insert into t1 values (1,1,3,4);
insert into t1 values (1,1,4,4);
insert into t1 values (1,3,1,4);
insert into t1 values (1,3,2,4);
insert into t1 values (1,3,3,4);
insert into t1 values (1,3,4,4);
insert into t1 values (1,2,1,4),(1,2,2,4),(1,2,3,4),(1,2,4,4),(1,1,1,4),(1,1,2,4),(1,1,3,4),(1,1,4,4),(1,3,1,4),(1,3,2,4),(1,3,3,4),(1,3,4,4);
select One, Two, sum(Four) from t1 group by One,Two;
One Two sum(Four)
1 1 16
1 2 16
1 3 16
drop table if exists t1;
drop table if exists t1,t2;
drop table t1;
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());
insert into t1 values (NULL, 'M'), (NULL, 'F'),(NULL, 'F'),(NULL, 'F'),(NULL, 'M');
create table t2 (user_id integer not null, date date);
insert into t2 values (1, '2002-06-09'),(2, '2002-06-09'),(1, '2002-06-09'),(3, '2002-06-09'),(4, '2002-06-09'),(4, '2002-06-09');
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
......
......@@ -284,35 +284,20 @@ INSERT INTO t1 values ('hij','klm');
SELECT CONCAT(a, b),count(*) FROM t1 GROUP BY 1;
DROP TABLE t1;
drop table if exists t1;
#
# Test problem with ORDER BY on a SUM() column
#
create table t1 (One int unsigned, Two int unsigned, Three int unsigned, Four int unsigned);
insert into t1 values (1,2,1,4);
insert into t1 values (1,2,2,4);
insert into t1 values (1,2,3,4);
insert into t1 values (1,2,4,4);
insert into t1 values (1,1,1,4);
insert into t1 values (1,1,2,4);
insert into t1 values (1,1,3,4);
insert into t1 values (1,1,4,4);
insert into t1 values (1,3,1,4);
insert into t1 values (1,3,2,4);
insert into t1 values (1,3,3,4);
insert into t1 values (1,3,4,4);
insert into t1 values (1,2,1,4),(1,2,2,4),(1,2,3,4),(1,2,4,4),(1,1,1,4),(1,1,2,4),(1,1,3,4),(1,1,4,4),(1,3,1,4),(1,3,2,4),(1,3,3,4),(1,3,4,4);
select One, Two, sum(Four) from t1 group by One,Two;
drop table if exists t1;
drop table if exists t1,t2;
drop table t1;
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());
insert into t1 values (NULL, 'M'), (NULL, 'F'),(NULL, 'F'),(NULL, 'F'),(NULL, 'M');
create table t2 (user_id integer not null, date date);
insert into t2 values (1, '2002-06-09'),(2, '2002-06-09'),(1, '2002-06-09'),(3, '2002-06-09'),(4, '2002-06-09'),(4, '2002-06-09');
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;
......@@ -2565,7 +2565,7 @@ check_table_access(THD *thd,uint want_access,TABLE_LIST *tables,
}
}
else if (check_access(thd,want_access,tables->db,&tables->grant.privilege,
0, no_errors | grant_option))
0, no_errors))
return TRUE;
}
if (grant_option)
......
......@@ -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 bool alloc_group_fields(JOIN *join,ORDER *group);
static bool make_sum_func_list(JOIN *join,List<Item> &fields);
static bool change_to_use_tmp_fields(List<Item> &func, bool change=false);
static bool change_to_use_tmp_fields(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 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;
join.join_tab[0].table=0; // Table is freed
if (change_to_use_tmp_fields(all_fields,true)) // No sum funcs anymore
if (change_to_use_tmp_fields(all_fields)) // No sum funcs anymore
goto err;
join.tmp_table_param.field_count+=join.tmp_table_param.sum_func_count;
join.tmp_table_param.sum_func_count=0;
......@@ -3676,7 +3676,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
if (blob_count == 0)
{
/* We need to ensure that first byte is not 0 for the delete link */
if (hidden_null_count)
if (param->hidden_field_count)
hidden_null_count++;
else
null_count++;
......@@ -6764,7 +6764,7 @@ make_sum_func_list(JOIN *join,List<Item> &fields)
*/
static bool
change_to_use_tmp_fields(List<Item> &items, bool change)
change_to_use_tmp_fields(List<Item> &items)
{
List_iterator<Item> it(items);
Item *item_field,*item;
......@@ -6776,11 +6776,6 @@ change_to_use_tmp_fields(List<Item> &items, bool change)
continue;
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)->result_field;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment