Commit 401ae95a authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-30082 View definition losing brackets changes semantics of the query and causes wrong result

Item_func_not_all::print() either uses Item_func::print() or
directly invokes args[0]->print(). Thus the precedence should be
either the one of Item_func or of args[0].

Item_allany_subselect::print() prints args[0], then a comparison op,
then a subquery. That is, the precedence should be the one of
a comparison.
parent 37bfe32c
......@@ -58,3 +58,21 @@ Create View CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY D
character_set_client latin1
collation_connection latin1_swedish_ci
drop view v1;
#
# MDEV-30082 View definition losing brackets changes semantics of the query and causes wrong result
#
create table t1 (a varchar(1), b bool) engine=myisam;
insert into t1 values ('u',1),('s',1);
select * from t1 where t1.b in (t1.a <= all (select 'a'));
a b
create view v as select * from t1 where t1.b in (t1.a <= all (select 'a'));
select * from v;
a b
show create view v;
View Create View character_set_client collation_connection
v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` where `t1`.`b` = (`t1`.`a` <= all (select 'a')) latin1 latin1_swedish_ci
drop view v;
drop table t1;
#
# End of 10.3 results
#
......@@ -39,3 +39,19 @@ drop table t1;
create view v1 as select 1 like (now() between '2000-01-01' and '2012-12-12' );
query_vertical show create view v1;
drop view v1;
--echo #
--echo # MDEV-30082 View definition losing brackets changes semantics of the query and causes wrong result
--echo #
create table t1 (a varchar(1), b bool) engine=myisam;
insert into t1 values ('u',1),('s',1);
select * from t1 where t1.b in (t1.a <= all (select 'a'));
create view v as select * from t1 where t1.b in (t1.a <= all (select 'a'));
select * from v;
show create view v;
drop view v;
drop table t1;
--echo #
--echo # End of 10.3 results
--echo #
......@@ -668,6 +668,8 @@ class Item_func_not_all :public Item_func_not
longlong val_int();
enum Functype functype() const { return NOT_ALL_FUNC; }
const char *func_name() const { return "<not>"; }
enum precedence precedence() const
{ return show ? Item_func::precedence() : args[0]->precedence(); }
bool fix_fields(THD *thd, Item **ref)
{return Item_func::fix_fields(thd, ref);}
virtual void print(String *str, enum_query_type query_type);
......
......@@ -783,6 +783,7 @@ class Item_allany_subselect :public Item_in_subselect
bool select_transformer(JOIN *join);
void create_comp_func(bool invert) { func= func_creator(invert); }
void print(String *str, enum_query_type query_type);
enum precedence precedence() const { return CMP_PRECEDENCE; }
bool is_maxmin_applicable(JOIN *join);
bool transform_into_max_min(JOIN *join);
void no_rows_in_result();
......
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