Commit 72e091f0 authored by unknown's avatar unknown

fixed row items with group functions

fixed layout


BitKeeper/etc/ignore:
  Added stamp-h2 stamp-h3 stamp-h4 to the ignore list
mysql-test/r/row.result:
  test of row with group function
mysql-test/t/row.test:
  test of row with group function
sql/item_cmpfunc.cc:
  added braces according review
sql/item_func.cc:
  fixed layout
sql/item_row.cc:
  fixed row item
sql/item_row.h:
  fixed row items with group functions
parent b627e2db
......@@ -591,3 +591,6 @@ help.c
vi.h
include/readline/readline.h
cmd-line-utils/libedit/common.h
stamp-h2
stamp-h3
stamp-h4
......@@ -144,3 +144,18 @@ Cardinality error (more/less than 1 columns)
select count(*) from t1 having (1,1) order by i;
Cardinality error (more/less than 1 columns)
drop table t1;
create table t1 (a int, b int);
insert into t1 values (1, 4);
insert into t1 values (10, 40);
insert into t1 values (1, 4);
insert into t1 values (10, 43);
insert into t1 values (1, 4);
insert into t1 values (10, 41);
insert into t1 values (1, 4);
insert into t1 values (10, 43);
insert into t1 values (1, 4);
select a, MAX(b), (1, MAX(b)) = (1, 4) from t1 group by a;
a MAX(b) (1, MAX(b)) = (1, 4)
1 4 1
10 43 0
drop table t1;
......@@ -67,3 +67,15 @@ select count(*) from t1 order by ROW(1,1);
select count(*) from t1 having (1,1) order by i;
drop table t1;
create table t1 (a int, b int);
insert into t1 values (1, 4);
insert into t1 values (10, 40);
insert into t1 values (1, 4);
insert into t1 values (10, 43);
insert into t1 values (1, 4);
insert into t1 values (10, 41);
insert into t1 values (1, 4);
insert into t1 values (10, 43);
insert into t1 values (1, 4);
select a, MAX(b), (1, MAX(b)) = (1, 4) from t1 group by a;
drop table t1;
......@@ -1079,8 +1079,10 @@ in_string::in_string(uint elements,qsort_cmp cmp_func)
in_string::~in_string()
{
if (base)
{
for (uint i=0 ; i < count ; i++)
((String*) base)[i].free();
}
}
void in_string::set(uint pos,Item *item)
......
......@@ -157,8 +157,8 @@ void Item_func::set_outer_resolving()
void Item_func::split_sum_func(Item **ref_pointer_array, List<Item> &fields)
{
Item **arg,**arg_end;
for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++)
Item **arg, **arg_end;
for (arg= args, arg_end= args+arg_count; arg != arg_end ; arg++)
{
if ((*arg)->with_sum_func && (*arg)->type() != SUM_FUNC_ITEM)
(*arg)->split_sum_func(ref_pointer_array, fields);
......@@ -167,7 +167,7 @@ void Item_func::split_sum_func(Item **ref_pointer_array, List<Item> &fields)
uint el= fields.elements;
fields.push_front(*arg);
ref_pointer_array[el]= *arg;
*arg=new Item_ref(ref_pointer_array + el, 0, (*arg)->name);
*arg= new Item_ref(ref_pointer_array + el, 0, (*arg)->name);
}
}
}
......
......@@ -48,26 +48,45 @@ bool Item_row::fix_fields(THD *thd, TABLE_LIST *tabl, Item **ref)
{
null_value= 0;
maybe_null= 0;
for (uint i= 0; i < arg_count; i++)
Item **arg, **arg_end;
for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
{
if (items[i]->fix_fields(thd, tabl, items+i))
if ((*arg)->fix_fields(thd, tabl, arg))
return 1;
used_tables_cache |= items[i]->used_tables();
if (const_item_cache&= items[i]->const_item() && !with_null)
used_tables_cache |= (*arg)->used_tables();
if (const_item_cache&= (*arg)->const_item() && !with_null)
{
if (items[i]->cols() > 1)
with_null|= items[i]->null_inside();
if ((*arg)->cols() > 1)
with_null|= (*arg)->null_inside();
else
{
items[i]->val_int();
with_null|= items[i]->null_value;
(*arg)->val_int();
with_null|= (*arg)->null_value;
}
}
maybe_null|= items[i]->maybe_null;
maybe_null|= (*arg)->maybe_null;
with_sum_func= with_sum_func || (*arg)->with_sum_func;
}
return 0;
}
void Item_row::split_sum_func(Item **ref_pointer_array, List<Item> &fields)
{
Item **arg, **arg_end;
for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
{
if ((*arg)->with_sum_func && (*arg)->type() != SUM_FUNC_ITEM)
(*arg)->split_sum_func(ref_pointer_array, fields);
else if ((*arg)->used_tables() || (*arg)->type() == SUM_FUNC_ITEM)
{
uint el= fields.elements;
fields.push_front(*arg);
ref_pointer_array[el]= *arg;
*arg= new Item_ref(ref_pointer_array + el, 0, (*arg)->name);
}
}
}
void Item_row::update_used_tables()
{
used_tables_cache= 0;
......
......@@ -63,6 +63,7 @@ public:
return 0;
};
bool fix_fields(THD *thd, TABLE_LIST *tables, Item **ref);
void split_sum_func(Item **ref_pointer_array, List<Item> &fields);
table_map used_tables() const { return used_tables_cache; };
bool const_item() const { return const_item_cache; };
enum Item_result result_type() const { return ROW_RESULT; }
......
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