From fb2035a1a37bb3dfe8311e0bb2b9d474837c035c Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 15 Sep 2017 00:29:56 +0200 Subject: MDEV-13673 Bad result in view When printing an expression, like a/(b*c), we need to print parentheses, even though / and * have the same precedence. Basically, we should always treat the second argument as having one level higher precedence than it normally is. --- mysql-test/r/func_math.result | 5 +++++ mysql-test/r/select.result | 2 +- mysql-test/r/select_jcl6.result | 2 +- mysql-test/r/select_pkeycache.result | 2 +- mysql-test/t/func_math.test | 5 +++++ sql/item_func.cc | 3 ++- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index 8ca10203add..ff2e929cffc 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -838,3 +838,8 @@ select 0=0, 0=-0, 0.0= -0.0, 0.0 = -(0.0), 0.0E1=-0.0E1, 0.0E1=-(0.0E1); select CRC32(NULL), CRC32(''), CRC32('MySQL'), CRC32('mysql'), CRC32('01234567'), CRC32('012345678'); CRC32(NULL) CRC32('') CRC32('MySQL') CRC32('mysql') CRC32('01234567') CRC32('012345678') NULL 0 3259397556 2501908538 763378421 939184570 +explain extended select (3-2)+1, (3/2)*1, 3-(2+1), 3/(2*1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select 3 - 2 + 1 AS `(3-2)+1`,3 / 2 * 1 AS `(3/2)*1`,3 - (2 + 1) AS `3-(2+1)`,3 / (2 * 1) AS `3/(2*1)` diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 90216c6cedc..010f37757e0 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -4784,7 +4784,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = (2 + 1 + 1) +Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = (2 + (1 + 1)) SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1; b a 2 3 diff --git a/mysql-test/r/select_jcl6.result b/mysql-test/r/select_jcl6.result index 054aa94763a..6eb0520b0ff 100644 --- a/mysql-test/r/select_jcl6.result +++ b/mysql-test/r/select_jcl6.result @@ -4795,7 +4795,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = (2 + 1 + 1) +Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = (2 + (1 + 1)) SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1; b a 2 3 diff --git a/mysql-test/r/select_pkeycache.result b/mysql-test/r/select_pkeycache.result index 90216c6cedc..010f37757e0 100644 --- a/mysql-test/r/select_pkeycache.result +++ b/mysql-test/r/select_pkeycache.result @@ -4784,7 +4784,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = (2 + 1 + 1) +Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = (2 + (1 + 1)) SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1; b a 2 3 diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index f1db36d605f..0b819278a44 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -608,3 +608,8 @@ select 0=0, 0=-0, 0.0= -0.0, 0.0 = -(0.0), 0.0E1=-0.0E1, 0.0E1=-(0.0E1); --echo # select CRC32(NULL), CRC32(''), CRC32('MySQL'), CRC32('mysql'), CRC32('01234567'), CRC32('012345678'); + +# +# MDEV-13673 Bad result in view +# +explain extended select (3-2)+1, (3/2)*1, 3-(2+1), 3/(2*1); diff --git a/sql/item_func.cc b/sql/item_func.cc index 4a9fa3342e6..f452b820090 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -479,7 +479,8 @@ void Item_func::print_op(String *str, enum_query_type query_type) str->append(func_name()); str->append(' '); } - args[arg_count-1]->print_parenthesised(str, query_type, precedence()); + args[arg_count-1]->print_parenthesised(str, query_type, + (enum precedence)(precedence() + 1)); } -- cgit v1.2.1