Skip to content

Commit fb2035a

Browse files
committed
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.
1 parent 16b1cb6 commit fb2035a

File tree

6 files changed

+15
-4
lines changed

6 files changed

+15
-4
lines changed

mysql-test/r/func_math.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);
838838
select CRC32(NULL), CRC32(''), CRC32('MySQL'), CRC32('mysql'), CRC32('01234567'), CRC32('012345678');
839839
CRC32(NULL) CRC32('') CRC32('MySQL') CRC32('mysql') CRC32('01234567') CRC32('012345678')
840840
NULL 0 3259397556 2501908538 763378421 939184570
841+
explain extended select (3-2)+1, (3/2)*1, 3-(2+1), 3/(2*1);
842+
id select_type table type possible_keys key key_len ref rows filtered Extra
843+
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
844+
Warnings:
845+
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)`

mysql-test/r/select.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4784,7 +4784,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
47844784
1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00
47854785
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using where
47864786
Warnings:
4787-
Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = <cache>(2 + 1 + 1)
4787+
Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = <cache>(2 + (1 + 1))
47884788
SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1;
47894789
b a
47904790
2 3

mysql-test/r/select_jcl6.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4795,7 +4795,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
47954795
1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00
47964796
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using where
47974797
Warnings:
4798-
Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = <cache>(2 + 1 + 1)
4798+
Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = <cache>(2 + (1 + 1))
47994799
SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1;
48004800
b a
48014801
2 3

mysql-test/r/select_pkeycache.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4784,7 +4784,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
47844784
1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00
47854785
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using where
47864786
Warnings:
4787-
Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = <cache>(2 + 1 + 1)
4787+
Note 1003 select `test`.`t1`.`a` AS `a`,2 AS `b` from `test`.`t1` where `test`.`t1`.`a` = <cache>(2 + (1 + 1))
47884788
SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1;
47894789
b a
47904790
2 3

mysql-test/t/func_math.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);
608608
--echo #
609609

610610
select CRC32(NULL), CRC32(''), CRC32('MySQL'), CRC32('mysql'), CRC32('01234567'), CRC32('012345678');
611+
612+
#
613+
# MDEV-13673 Bad result in view
614+
#
615+
explain extended select (3-2)+1, (3/2)*1, 3-(2+1), 3/(2*1);

sql/item_func.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ void Item_func::print_op(String *str, enum_query_type query_type)
479479
str->append(func_name());
480480
str->append(' ');
481481
}
482-
args[arg_count-1]->print_parenthesised(str, query_type, precedence());
482+
args[arg_count-1]->print_parenthesised(str, query_type,
483+
(enum precedence)(precedence() + 1));
483484
}
484485

485486

0 commit comments

Comments
 (0)