Skip to content

Commit 2cd5df8

Browse files
committed
MDEV-23656 view: removal of parentheses results in wrong result
Item_ref should have the precedence of the item it's referencing
1 parent 15f03c2 commit 2cd5df8

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# MDEV-23656 view: removal of parentheses results in wrong result
3+
#
4+
create table t1 (a int, b decimal(10,2));
5+
insert into t1 values (1, 10.2);
6+
create view v1 as select avg(b) / (2 + a) from t1;
7+
show create view v1;
8+
View v1
9+
Create View CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select avg(`t1`.`b`) / (2 + `t1`.`a`) AS `avg(b) / (2 + a)` from `t1`
10+
character_set_client latin1
11+
collation_connection latin1_swedish_ci
12+
drop view v1;
13+
drop table t1;

mysql-test/t/precedence_bugs.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
--echo #
3+
--echo # MDEV-23656 view: removal of parentheses results in wrong result
4+
--echo #
5+
create table t1 (a int, b decimal(10,2));
6+
insert into t1 values (1, 10.2);
7+
create view v1 as select avg(b) / (2 + a) from t1;
8+
query_vertical show create view v1;
9+
drop view v1;
10+
drop table t1;

sql/item.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4541,7 +4541,11 @@ class Item_ref :public Item_ident
45414541
{
45424542
(*ref)->restore_to_before_no_rows_in_result();
45434543
}
4544-
virtual void print(String *str, enum_query_type query_type);
4544+
void print(String *str, enum_query_type query_type);
4545+
enum precedence precedence() const
4546+
{
4547+
return ref ? (*ref)->precedence() : DEFAULT_PRECEDENCE;
4548+
}
45454549
void cleanup();
45464550
Item_field *field_for_view_update()
45474551
{ return (*ref)->field_for_view_update(); }

0 commit comments

Comments
 (0)