diff options
author | unknown <hf@deer.(none)> | 2005-06-08 20:35:37 +0500 |
---|---|---|
committer | unknown <hf@deer.(none)> | 2005-06-08 20:35:37 +0500 |
commit | 2fded7d5c4b371f100368c833faba425a845a8fc (patch) | |
tree | 519742a623eae1df25ea536bcb3e84d39e69e9d7 /sql/item_cmpfunc.cc | |
parent | e595b7ee9db2e1aecadc68a11d821b65c42de1a1 (diff) | |
download | mariadb-git-2fded7d5c4b371f100368c833faba425a845a8fc.tar.gz |
Fix for bug #9764 (DISTINCT IFNULL truncates data)
mysql-test/r/create.result:
test result fixed
mysql-test/r/distinct.result:
test result fixed
mysql-test/t/distinct.test:
test case added
sql/item_cmpfunc.cc:
max_length should be calculated differently for DECIMAL_RESULT and others
Diffstat (limited to 'sql/item_cmpfunc.cc')
-rw-r--r-- | sql/item_cmpfunc.cc | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 28ab38c5aed..b5b37efaf07 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1109,12 +1109,14 @@ void Item_func_between::print(String *str) void Item_func_ifnull::fix_length_and_dec() { + agg_result_type(&hybrid_type, args, 2); maybe_null=args[1]->maybe_null; decimals= max(args[0]->decimals, args[1]->decimals); - max_length= (max(args[0]->max_length - args[0]->decimals, - args[1]->max_length - args[1]->decimals) + - decimals); - agg_result_type(&hybrid_type, args, 2); + max_length= (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT) ? + (max(args[0]->max_length - args[0]->decimals, + args[1]->max_length - args[1]->decimals) + decimals) : + max(args[0]->max_length, args[1]->max_length); + switch (hybrid_type) { case STRING_RESULT: agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV); @@ -1225,16 +1227,7 @@ Item_func_if::fix_length_and_dec() { maybe_null=args[1]->maybe_null || args[2]->maybe_null; decimals= max(args[1]->decimals, args[2]->decimals); - if (decimals == NOT_FIXED_DEC) - { - max_length= max(args[1]->max_length, args[2]->max_length); - } - else - { - max_length= (max(args[1]->max_length - args[1]->decimals, - args[2]->max_length - args[2]->decimals) + - decimals); - } + enum Item_result arg1_type=args[1]->result_type(); enum Item_result arg2_type=args[2]->result_type(); bool null1=args[1]->const_item() && args[1]->null_value; @@ -1263,6 +1256,11 @@ Item_func_if::fix_length_and_dec() collation.set(&my_charset_bin); // Number } } + max_length= + (cached_result_type == DECIMAL_RESULT || cached_result_type == INT_RESULT) ? + (max(args[1]->max_length - args[1]->decimals, + args[2]->max_length - args[2]->decimals) + decimals) : + max(args[1]->max_length, args[2]->max_length); } |