Commit 2cd5df8c authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-23656 view: removal of parentheses results in wrong result

Item_ref should have the precedence of the item it's referencing
parent 15f03c20
#
# MDEV-23656 view: removal of parentheses results in wrong result
#
create table t1 (a int, b decimal(10,2));
insert into t1 values (1, 10.2);
create view v1 as select avg(b) / (2 + a) from t1;
show create view v1;
View v1
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`
character_set_client latin1
collation_connection latin1_swedish_ci
drop view v1;
drop table t1;
--echo #
--echo # MDEV-23656 view: removal of parentheses results in wrong result
--echo #
create table t1 (a int, b decimal(10,2));
insert into t1 values (1, 10.2);
create view v1 as select avg(b) / (2 + a) from t1;
query_vertical show create view v1;
drop view v1;
drop table t1;
...@@ -4541,7 +4541,11 @@ class Item_ref :public Item_ident ...@@ -4541,7 +4541,11 @@ class Item_ref :public Item_ident
{ {
(*ref)->restore_to_before_no_rows_in_result(); (*ref)->restore_to_before_no_rows_in_result();
} }
virtual void print(String *str, enum_query_type query_type); void print(String *str, enum_query_type query_type);
enum precedence precedence() const
{
return ref ? (*ref)->precedence() : DEFAULT_PRECEDENCE;
}
void cleanup(); void cleanup();
Item_field *field_for_view_update() Item_field *field_for_view_update()
{ return (*ref)->field_for_view_update(); } { return (*ref)->field_for_view_update(); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment