Skip to content

Commit eda2ebe

Browse files
committed
MDEV-11784 View is created with invalid definition which causes ERROR 1241 (21000): Operand should contain 1 column(s)
set the correct print precedence for IN subqueries
1 parent cf00393 commit eda2ebe

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

mysql-test/r/view.result

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
drop table if exists t1,t2,t3,t4,t5,t6,t9,`t1a``b`,v1,v2,v3,v4,v5,v6;
2-
drop view if exists t1,t2,t3,t4,t5,t6,t9,`t1a``b`,v1,v2,v3,v4,v5,v6;
3-
drop database if exists mysqltest;
4-
use test;
51
SET @save_optimizer_switch=@@optimizer_switch;
62
SET optimizer_switch='outer_join_with_cache=off';
73
create view v1 (c,d) as select a,b from t1;
@@ -6325,6 +6321,17 @@ INSERT INTO v (f1, f3) VALUES (1,1), (2,2);
63256321
ERROR HY000: Can not modify more than one base table through a join view 'test.v'
63266322
drop view v;
63276323
drop tables t1,t2,t3;
6324+
create table t1 (i int, j int);
6325+
insert t1 values (1,1),(2,2);
6326+
create view v1 as select (2, 3) not in (select i, j from t1);
6327+
select * from v1;
6328+
(2, 3) not in (select i, j from t1)
6329+
1
6330+
show create view v1;
6331+
View Create View character_set_client collation_connection
6332+
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select !((2,3) in (select `t1`.`i`,`t1`.`j` from `t1`)) AS `(2, 3) not in (select i, j from t1)` latin1 latin1_swedish_ci
6333+
drop view v1;
6334+
drop table t1;
63286335
#
63296336
# End of 10.2 tests
63306337
#

mysql-test/t/view.test

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
2-
--disable_warnings
3-
drop table if exists t1,t2,t3,t4,t5,t6,t9,`t1a``b`,v1,v2,v3,v4,v5,v6;
4-
drop view if exists t1,t2,t3,t4,t5,t6,t9,`t1a``b`,v1,v2,v3,v4,v5,v6;
5-
drop database if exists mysqltest;
6-
--enable_warnings
7-
use test;
8-
91
# Save the initial number of concurrent sessions.
102
--source include/count_sessions.inc
113

@@ -6066,6 +6058,17 @@ INSERT INTO v (f1, f3) VALUES (1,1), (2,2);
60666058
drop view v;
60676059
drop tables t1,t2,t3;
60686060

6061+
#
6062+
# MDEV-11784 View is created with invalid definition which causes ERROR 1241 (21000): Operand should contain 1 column(s)
6063+
#
6064+
create table t1 (i int, j int);
6065+
insert t1 values (1,1),(2,2);
6066+
create view v1 as select (2, 3) not in (select i, j from t1);
6067+
select * from v1;
6068+
show create view v1;
6069+
drop view v1;
6070+
drop table t1;
6071+
60696072
--echo #
60706073
--echo # End of 10.2 tests
60716074
--echo #

sql/item_subselect.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class Item_exists_subselect :public Item_subselect
399399
bool val_bool();
400400
bool fix_fields(THD *thd, Item **ref);
401401
void fix_length_and_dec();
402-
virtual void print(String *str, enum_query_type query_type);
402+
void print(String *str, enum_query_type query_type);
403403
bool select_transformer(JOIN *join);
404404
void top_level_item() { abort_on_null=1; }
405405
inline bool is_top_level_item() { return abort_on_null; }
@@ -616,7 +616,8 @@ class Item_in_subselect :public Item_exists_subselect
616616
void update_null_value () { (void) val_bool(); }
617617
bool val_bool();
618618
bool test_limit(st_select_lex_unit *unit);
619-
virtual void print(String *str, enum_query_type query_type);
619+
void print(String *str, enum_query_type query_type);
620+
enum precedence precedence() const { return CMP_PRECEDENCE; }
620621
bool fix_fields(THD *thd, Item **ref);
621622
void fix_length_and_dec();
622623
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
@@ -740,7 +741,7 @@ class Item_allany_subselect :public Item_in_subselect
740741
subs_type substype() { return all?ALL_SUBS:ANY_SUBS; }
741742
bool select_transformer(JOIN *join);
742743
void create_comp_func(bool invert) { func= func_creator(invert); }
743-
virtual void print(String *str, enum_query_type query_type);
744+
void print(String *str, enum_query_type query_type);
744745
bool is_maxmin_applicable(JOIN *join);
745746
bool transform_into_max_min(JOIN *join);
746747
void no_rows_in_result();
@@ -849,7 +850,7 @@ class subselect_single_select_engine: public subselect_engine
849850
uint8 uncacheable();
850851
void exclude();
851852
table_map upper_select_const_tables();
852-
virtual void print (String *str, enum_query_type query_type);
853+
void print (String *str, enum_query_type query_type);
853854
bool change_result(Item_subselect *si,
854855
select_result_interceptor *result,
855856
bool temp);
@@ -883,7 +884,7 @@ class subselect_union_engine: public subselect_engine
883884
uint8 uncacheable();
884885
void exclude();
885886
table_map upper_select_const_tables();
886-
virtual void print (String *str, enum_query_type query_type);
887+
void print (String *str, enum_query_type query_type);
887888
bool change_result(Item_subselect *si,
888889
select_result_interceptor *result,
889890
bool temp= FALSE);
@@ -940,7 +941,7 @@ class subselect_uniquesubquery_engine: public subselect_engine
940941
uint8 uncacheable() { return UNCACHEABLE_DEPENDENT_INJECTED; }
941942
void exclude();
942943
table_map upper_select_const_tables() { return 0; }
943-
virtual void print (String *str, enum_query_type query_type);
944+
void print (String *str, enum_query_type query_type);
944945
bool change_result(Item_subselect *si,
945946
select_result_interceptor *result,
946947
bool temp= FALSE);
@@ -998,7 +999,7 @@ class subselect_indexsubquery_engine: public subselect_uniquesubquery_engine
998999
having(having_arg)
9991000
{}
10001001
int exec();
1001-
virtual void print (String *str, enum_query_type query_type);
1002+
void print (String *str, enum_query_type query_type);
10021003
virtual enum_engine_type engine_type() { return INDEXSUBQUERY_ENGINE; }
10031004
};
10041005

@@ -1073,11 +1074,8 @@ class subselect_hash_sj_engine : public subselect_engine
10731074
void cleanup();
10741075
int prepare(THD *);
10751076
int exec();
1076-
virtual void print(String *str, enum_query_type query_type);
1077-
uint cols()
1078-
{
1079-
return materialize_engine->cols();
1080-
}
1077+
void print(String *str, enum_query_type query_type);
1078+
uint cols() { return materialize_engine->cols(); }
10811079
uint8 uncacheable() { return materialize_engine->uncacheable(); }
10821080
table_map upper_select_const_tables() { return 0; }
10831081
bool no_rows() { return !tmp_table->file->stats.records; }

0 commit comments

Comments
 (0)