diff options
author | unknown <igor@rurik.mysql.com> | 2005-12-02 20:42:36 -0800 |
---|---|---|
committer | unknown <igor@rurik.mysql.com> | 2005-12-02 20:42:36 -0800 |
commit | e324da302f39998d654b5b112a0342cad0427e35 (patch) | |
tree | a7f18b069781ad44463394d0a6a6a4d7f37b560a /sql/item_cmpfunc.cc | |
parent | 448327afb42e7b4d98ebd231ff7482ba59f0e921 (diff) | |
parent | 2883e932ef55268d90c57f926d08df7b9a068f1a (diff) | |
download | mariadb-git-e324da302f39998d654b5b112a0342cad0427e35.tar.gz |
Merge rurik.mysql.com:/home/igor/mysql-5.0
into rurik.mysql.com:/home/igor/dev/mysql-5.0-2
sql/item.cc:
Auto merged
sql/item.h:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_func.cc:
Auto merged
sql/item_strfunc.cc:
Auto merged
sql/item_sum.cc:
Auto merged
sql/item_sum.h:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/sql_class.cc:
Auto merged
sql/sql_class.h:
Auto merged
sql/sql_lex.h:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_select.cc:
Auto merged
sql/sql_update.cc:
Auto merged
sql/sql_yacc.yy:
Auto merged
Diffstat (limited to 'sql/item_cmpfunc.cc')
-rw-r--r-- | sql/item_cmpfunc.cc | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index ca070131122..15614a32c39 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -25,6 +25,8 @@ #include <m_ctype.h> #include "sql_select.h" +static bool convert_constant_item(THD *thd, Field *field, Item **item); + static Item_result item_store_type(Item_result a,Item_result b) { if (a == STRING_RESULT || b == STRING_RESULT) @@ -45,14 +47,37 @@ static void agg_result_type(Item_result *type, Item **items, uint nitems) type[0]= item_store_type(type[0], items[i]->result_type()); } -static void agg_cmp_type(Item_result *type, Item **items, uint nitems) + +static void agg_cmp_type(THD *thd, Item_result *type, Item **items, uint nitems) { uint i; + Field *field= NULL; + bool all_constant= TRUE; + + /* If the first argument is a FIELD_ITEM, pull out the field. */ + if (items[0]->type() == Item::FIELD_ITEM) + field=((Item_field *)items[0])->field; + /* But if it can't be compared as a longlong, we don't really care. */ + if (field && !field->can_be_compared_as_longlong()) + field= NULL; + type[0]= items[0]->result_type(); - for (i=1 ; i < nitems ; i++) + for (i= 1; i < nitems; i++) + { type[0]= item_cmp_type(type[0], items[i]->result_type()); + if (field && !convert_constant_item(thd, field, &items[i])) + all_constant= FALSE; + } + + /* + If we had a field that can be compared as a longlong, and all constant + items, then the aggregate result will be an INT_RESULT. + */ + if (field && all_constant) + type[0]= INT_RESULT; } + static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname) { @@ -1051,32 +1076,11 @@ void Item_func_between::fix_length_and_dec() */ if (!args[0] || !args[1] || !args[2]) return; - agg_cmp_type(&cmp_type, args, 3); + agg_cmp_type(thd, &cmp_type, args, 3); + if (cmp_type == STRING_RESULT && agg_arg_charsets(cmp_collation, args, 3, MY_COLL_CMP_CONV)) return; - - /* - Make a special ease of compare with date/time and longlong fields. - They are compared as integers, so for const item this time-consuming - conversion can be done only once, not for every single comparison - */ - if (args[0]->type() == FIELD_ITEM) - { - Field *field=((Item_field*) args[0])->field; - if (!thd->is_context_analysis_only() && - field->can_be_compared_as_longlong()) - { - /* - The following can't be recoded with || as convert_constant_item - changes the argument - */ - if (convert_constant_item(thd, field,&args[1])) - cmp_type=INT_RESULT; // Works for all types. - if (convert_constant_item(thd, field,&args[2])) - cmp_type=INT_RESULT; // Works for all types. - } - } } @@ -1722,6 +1726,7 @@ void Item_func_case::fix_length_and_dec() { Item **agg; uint nagg; + THD *thd= current_thd; if (!(agg= (Item**) sql_alloc(sizeof(Item*)*(ncases+1)))) return; @@ -1753,7 +1758,7 @@ void Item_func_case::fix_length_and_dec() for (nagg= 0; nagg < ncases/2 ; nagg++) agg[nagg+1]= args[nagg*2]; nagg++; - agg_cmp_type(&cmp_type, agg, nagg); + agg_cmp_type(thd, &cmp_type, agg, nagg); if ((cmp_type == STRING_RESULT) && agg_arg_charsets(cmp_collation, agg, nagg, MY_COLL_CMP_CONV)) return; @@ -2346,7 +2351,7 @@ void Item_func_in::fix_length_and_dec() uint const_itm= 1; THD *thd= current_thd; - agg_cmp_type(&cmp_type, args, arg_count); + agg_cmp_type(thd, &cmp_type, args, arg_count); if (cmp_type == STRING_RESULT && agg_arg_charsets(cmp_collation, args, arg_count, MY_COLL_CMP_CONV)) @@ -3662,7 +3667,7 @@ void Item_equal::merge(Item_equal *item) the multiple equality already contains a constant and its value is not equal to the value of c. */ - add(const_item); + add(c); } cond_false|= item->cond_false; } |