summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <hf@deer.(none)>2003-07-15 20:06:27 +0500
committerunknown <hf@deer.(none)>2003-07-15 20:06:27 +0500
commitbf3af8eeac3dba6af359805e82ad5c1b26d4834e (patch)
tree59c537050deacb02468cf82a4d9ce13cd8a990d5 /sql
parentc458a78a83649d4d39ce95828a30563f4ba6b913 (diff)
parentcb8e29cb43e927f110b16ac959ee7afde82bf5df (diff)
downloadmariadb-git-bf3af8eeac3dba6af359805e82ad5c1b26d4834e.tar.gz
Merge abotchkov@bk-internal.mysql.com:/home/bk/mysql-4.1
into deer.(none):/home/hf/work/mysql-4.1.2way
Diffstat (limited to 'sql')
-rw-r--r--sql/item_func.cc55
-rw-r--r--sql/item_func.h21
-rw-r--r--sql/item_strfunc.cc44
-rw-r--r--sql/item_strfunc.h18
-rw-r--r--sql/item_timefunc.cc2
-rw-r--r--sql/sql_yacc.yy4
6 files changed, 25 insertions, 119 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 7264a3b5225..7e236225067 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1170,32 +1170,32 @@ longlong Item_func_field::val_int()
if (cmp_type == STRING_RESULT)
{
String *field;
- if (!(field=item->val_str(&value)))
+ if (!(field=args[0]->val_str(&value)))
return 0; // -1 if null ?
- for (uint i=0 ; i < arg_count ; i++)
+ for (uint i=1 ; i < arg_count ; i++)
{
String *tmp_value=args[i]->val_str(&tmp);
if (tmp_value && field->length() == tmp_value->length() &&
!sortcmp(field,tmp_value,cmp_collation.collation))
- return (longlong) (i+1);
+ return (longlong) (i);
}
}
else if (cmp_type == INT_RESULT)
{
- longlong val= item->val_int();
- for (uint i=0; i < arg_count ; i++)
+ longlong val= args[0]->val_int();
+ for (uint i=1; i < arg_count ; i++)
{
if (val == args[i]->val_int())
- return (longlong) (i+1);
+ return (longlong) (i);
}
}
else
{
- double val= item->val();
- for (uint i=0; i < arg_count ; i++)
+ double val= args[0]->val();
+ for (uint i=1; i < arg_count ; i++)
{
if (val == args[i]->val())
- return (longlong) (i+1);
+ return (longlong) (i);
}
}
return 0;
@@ -1204,42 +1204,11 @@ longlong Item_func_field::val_int()
void Item_func_field::fix_length_and_dec()
{
maybe_null=0; max_length=3;
- used_tables_cache|= item->used_tables();
- const_item_cache&= item->const_item();
- with_sum_func= with_sum_func || item->with_sum_func;
-
- cmp_type= item->result_type();
- for (uint i=0; i < arg_count ; i++)
+ cmp_type= args[0]->result_type();
+ for (uint i=1; i < arg_count ; i++)
cmp_type= item_cmp_type(cmp_type, args[i]->result_type());
-
if (cmp_type == STRING_RESULT)
- {
- cmp_collation.set(item->collation);
- for (uint i=0 ; i < arg_count ; i++)
- {
- if (cmp_collation.aggregate(args[i]->collation))
- {
- my_error(ER_CANT_AGGREGATE_NCOLLATIONS,MYF(0),func_name());
- return;
- }
- }
- }
-}
-
-
-void Item_func_field::split_sum_func(Item **ref_pointer_array,
- List<Item> &fields)
-{
- if (item->with_sum_func && item->type() != SUM_FUNC_ITEM)
- item->split_sum_func(ref_pointer_array, fields);
- else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
- {
- uint el= fields.elements;
- fields.push_front(item);
- ref_pointer_array[el]= item;
- item= new Item_ref(ref_pointer_array + el, 0, item->name);
- }
- Item_func::split_sum_func(ref_pointer_array, fields);
+ agg_arg_collations_for_comparison(cmp_collation, args, arg_count);
}
diff --git a/sql/item_func.h b/sql/item_func.h
index a5575a35851..a0969fc6b9a 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -625,33 +625,14 @@ public:
class Item_func_field :public Item_int_func
{
- Item *item;
String value,tmp;
Item_result cmp_type;
DTCollation cmp_collation;
public:
- Item_func_field(Item *a,List<Item> &list) :Item_int_func(list),item(a) {}
- ~Item_func_field() { delete item; }
+ Item_func_field(List<Item> &list) :Item_int_func(list) {}
longlong val_int();
- bool fix_fields(THD *thd,struct st_table_list *tlist, Item **ref)
- {
- return (item->fix_fields(thd, tlist, &item) || item->check_cols(1) ||
- Item_func::fix_fields(thd, tlist, ref));
- }
- void split_sum_func(Item **ref_pointer_array, List<Item> &fields);
- void update_used_tables()
- {
- item->update_used_tables() ; Item_func::update_used_tables();
- used_tables_cache|= item->used_tables();
- const_item_cache&= item->const_item();
- }
const char *func_name() const { return "field"; }
void fix_length_and_dec();
- void set_outer_resolving()
- {
- item->set_outer_resolving();
- Item_int_func::set_outer_resolving();
- }
};
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index b25619d0bb1..4e35e90b429 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1660,81 +1660,53 @@ void Item_func_elt::fix_length_and_dec()
max_length=0;
decimals=0;
- if (agg_arg_collations(collation, args, arg_count))
+ if (agg_arg_collations(collation, args+1, arg_count-1))
return;
- for (uint i=0 ; i < arg_count ; i++)
+ for (uint i=1 ; i < arg_count ; i++)
{
set_if_bigger(max_length,args[i]->max_length);
set_if_bigger(decimals,args[i]->decimals);
}
maybe_null=1; // NULL if wrong first arg
- with_sum_func= with_sum_func || item->with_sum_func;
- used_tables_cache|=item->used_tables();
- const_item_cache&=item->const_item();
-}
-
-
-void Item_func_elt::split_sum_func(Item **ref_pointer_array,
- List<Item> &fields)
-{
- if (item->with_sum_func && item->type() != SUM_FUNC_ITEM)
- item->split_sum_func(ref_pointer_array, fields);
- else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
- {
- uint el= fields.elements;
- fields.push_front(item);
- ref_pointer_array[el]= item;
- item= new Item_ref(ref_pointer_array + el, 0, item->name);
- }
- Item_str_func::split_sum_func(ref_pointer_array, fields);
-}
-
-
-void Item_func_elt::update_used_tables()
-{
- Item_func::update_used_tables();
- item->update_used_tables();
- used_tables_cache|=item->used_tables();
- const_item_cache&=item->const_item();
}
double Item_func_elt::val()
{
uint tmp;
- if ((tmp=(uint) item->val_int()) == 0 || tmp > arg_count)
+ if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
{
null_value=1;
return 0.0;
}
null_value=0;
- return args[tmp-1]->val();
+ return args[tmp]->val();
}
longlong Item_func_elt::val_int()
{
uint tmp;
- if ((tmp=(uint) item->val_int()) == 0 || tmp > arg_count)
+ if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
{
null_value=1;
return 0;
}
null_value=0;
- return args[tmp-1]->val_int();
+ return args[tmp]->val_int();
}
String *Item_func_elt::val_str(String *str)
{
uint tmp;
String *res;
- if ((tmp=(uint) item->val_int()) == 0 || tmp > arg_count)
+ if ((tmp=(uint) args[0]->val_int()) == 0 || tmp >= arg_count)
{
null_value=1;
return NULL;
}
null_value=0;
- res= args[tmp-1]->val_str(str);
+ res= args[tmp]->val_str(str);
res->set_charset(charset());
return res;
}
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 6cc6d730627..7f8d7ade67b 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -372,29 +372,13 @@ public:
class Item_func_elt :public Item_str_func
{
- Item *item;
-
public:
- Item_func_elt(Item *a,List<Item> &list) :Item_str_func(list),item(a) {}
- ~Item_func_elt() { delete item; }
+ Item_func_elt(List<Item> &list) :Item_str_func(list) {}
double val();
longlong val_int();
String *val_str(String *str);
- bool fix_fields(THD *thd, TABLE_LIST *tlist, Item **ref)
- {
- return (item->fix_fields(thd, tlist, &item) ||
- item->check_cols(1) ||
- Item_func::fix_fields(thd, tlist, ref));
- }
- void split_sum_func(Item **ref_pointer_array, List<Item> &fields);
void fix_length_and_dec();
- void update_used_tables();
const char *func_name() const { return "elt"; }
- void set_outer_resolving()
- {
- item->set_outer_resolving();
- Item_str_func::set_outer_resolving();
- }
};
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 4fdb1b13d24..c2d1504e94a 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -380,7 +380,7 @@ longlong Item_func_time_to_sec::val_int()
static bool get_interval_value(Item *args,interval_type int_type,
String *str_value, INTERVAL *t)
{
- long array[4],value;
+ long array[5],value;
const char *str;
uint32 length;
LINT_INIT(value); LINT_INIT(str); LINT_INIT(length);
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index c836cb414e0..45a647cd8ab 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -2389,7 +2389,7 @@ simple_expr:
| DAY_SYM '(' expr ')'
{ $$= new Item_func_dayofmonth($3); }
| ELT_FUNC '(' expr ',' expr_list ')'
- { $$= new Item_func_elt($3, *$5); }
+ { $5->push_front($3); $$= new Item_func_elt(*$5); }
| MAKE_SET_SYM '(' expr ',' expr_list ')'
{ $$= new Item_func_make_set($3, *$5); }
| ENCRYPT '(' expr ')'
@@ -2427,7 +2427,7 @@ simple_expr:
$$= new Item_func_date_format (new Item_func_from_unixtime($3),$5,0);
}
| FIELD_FUNC '(' expr ',' expr_list ')'
- { $$= new Item_func_field($3, *$5); }
+ { $5->push_front($3); $$= new Item_func_field(*$5); }
| GEOMFROMTEXT '(' expr ')'
{ $$= new Item_func_geometry_from_text($3); }
| GEOMFROMTEXT '(' expr ',' expr ')'