--- Percona-Server-5.1.59/sql/item_cmpfunc.cc 2011-08-11 21:52:53.000000000 +0800 +++ Percona-Server-5.1.59-debug/sql/item_cmpfunc.cc 2011-11-30 21:12:23.000000000 +0800 @@ -506,14 +506,20 @@ !(field_item->is_datetime() && args[1]->result_type() == STRING_RESULT)) { - if (convert_constant_item(thd, field_item, &args[1])) - { - cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, - INT_RESULT); // Works for all types. - args[0]->cmp_context= args[1]->cmp_context= INT_RESULT; - return; - } - } + if ( (!(field_item->field->type() == MYSQL_TYPE_LONGLONG && args[1]->real_item()->type() == DECIMAL_ITEM)) + && convert_constant_item(thd, field_item, &args[1])) + { + cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, + INT_RESULT); // Works for all types. + args[0]->cmp_context= args[1]->cmp_context= INT_RESULT; + return; + } else { + cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, + DECIMAL_RESULT); // Works for all types. + args[0]->cmp_context= args[1]->cmp_context= DECIMAL_RESULT; + return; + } + } } if (args[1]->real_item()->type() == FIELD_ITEM) { @@ -522,14 +528,20 @@ !(field_item->is_datetime() && args[0]->result_type() == STRING_RESULT)) { - if (convert_constant_item(thd, field_item, &args[0])) - { - cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, - INT_RESULT); // Works for all types. - args[0]->cmp_context= args[1]->cmp_context= INT_RESULT; - return; - } - } + if ( (!(field_item->field->type() == MYSQL_TYPE_LONGLONG && args[0]->real_item()->type() == DECIMAL_ITEM)) + && convert_constant_item(thd, field_item, &args[0])) + { + cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, + INT_RESULT); // Works for all types. + args[0]->cmp_context= args[1]->cmp_context= INT_RESULT; + return; + } else { + cmp.set_cmp_func(this, tmp_arg, tmp_arg+1, + DECIMAL_RESULT); // Works for all types. + args[0]->cmp_context= args[1]->cmp_context= DECIMAL_RESULT; + return; + } + } } } set_cmp_func();