Skip to content

Commit 401ae95

Browse files
committed
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.
1 parent 37bfe32 commit 401ae95

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

mysql-test/main/precedence_bugs.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,21 @@ Create View CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY D
5858
character_set_client latin1
5959
collation_connection latin1_swedish_ci
6060
drop view v1;
61+
#
62+
# MDEV-30082 View definition losing brackets changes semantics of the query and causes wrong result
63+
#
64+
create table t1 (a varchar(1), b bool) engine=myisam;
65+
insert into t1 values ('u',1),('s',1);
66+
select * from t1 where t1.b in (t1.a <= all (select 'a'));
67+
a b
68+
create view v as select * from t1 where t1.b in (t1.a <= all (select 'a'));
69+
select * from v;
70+
a b
71+
show create view v;
72+
View Create View character_set_client collation_connection
73+
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
74+
drop view v;
75+
drop table t1;
76+
#
77+
# End of 10.3 results
78+
#

mysql-test/main/precedence_bugs.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,19 @@ drop table t1;
3939
create view v1 as select 1 like (now() between '2000-01-01' and '2012-12-12' );
4040
query_vertical show create view v1;
4141
drop view v1;
42+
43+
--echo #
44+
--echo # MDEV-30082 View definition losing brackets changes semantics of the query and causes wrong result
45+
--echo #
46+
create table t1 (a varchar(1), b bool) engine=myisam;
47+
insert into t1 values ('u',1),('s',1);
48+
select * from t1 where t1.b in (t1.a <= all (select 'a'));
49+
create view v as select * from t1 where t1.b in (t1.a <= all (select 'a'));
50+
select * from v;
51+
show create view v;
52+
drop view v;
53+
drop table t1;
54+
55+
--echo #
56+
--echo # End of 10.3 results
57+
--echo #

sql/item_cmpfunc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,8 @@ class Item_func_not_all :public Item_func_not
668668
longlong val_int();
669669
enum Functype functype() const { return NOT_ALL_FUNC; }
670670
const char *func_name() const { return "<not>"; }
671+
enum precedence precedence() const
672+
{ return show ? Item_func::precedence() : args[0]->precedence(); }
671673
bool fix_fields(THD *thd, Item **ref)
672674
{return Item_func::fix_fields(thd, ref);}
673675
virtual void print(String *str, enum_query_type query_type);

sql/item_subselect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ class Item_allany_subselect :public Item_in_subselect
783783
bool select_transformer(JOIN *join);
784784
void create_comp_func(bool invert) { func= func_creator(invert); }
785785
void print(String *str, enum_query_type query_type);
786+
enum precedence precedence() const { return CMP_PRECEDENCE; }
786787
bool is_maxmin_applicable(JOIN *join);
787788
bool transform_into_max_min(JOIN *join);
788789
void no_rows_in_result();

0 commit comments

Comments
 (0)