summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/t/table_value_const.test8
-rw-r--r--sql/sql_lex.cc1
-rw-r--r--sql/sql_tvc.h4
-rw-r--r--sql/sql_union.cc17
-rw-r--r--sql/sql_yacc.yy4
5 files changed, 26 insertions, 8 deletions
diff --git a/mysql-test/t/table_value_const.test b/mysql-test/t/table_value_const.test
index 6d338ab0353..00cd1baad95 100644
--- a/mysql-test/t/table_value_const.test
+++ b/mysql-test/t/table_value_const.test
@@ -1,9 +1,15 @@
+create table t1 (a int, b int);
+
+insert into t1 values (1,2),(4,6),(9,7),(1,1),(2,5),(7,8);
+
values (1,2);
select 1,2 union values (1,2);
values (1,2) union select (1,2);
+values (1,2), (3,4) union select 1,2;
+
select * from t1 where (t1.a,t1.b) in (select 5,7 union values (1,2),(2,3));
select * from t1 where (t1.a,t1.b) in (values (1,2),(2,3) union select 5,7);
@@ -26,5 +32,5 @@ create view v1 as select 1,2 union values (3,4),(5,6);
eval $drop_view;
-
+drop table t1;
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 4c763f50eaf..baab673011f 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -2262,6 +2262,7 @@ void st_select_lex::init_select()
with_dep= 0;
join= 0;
lock_type= TL_READ_DEFAULT;
+ tvc= 0;
}
/*
diff --git a/sql/sql_tvc.h b/sql/sql_tvc.h
index e5c3477351c..007b50d81df 100644
--- a/sql/sql_tvc.h
+++ b/sql/sql_tvc.h
@@ -19,6 +19,10 @@ public:
List<List_item> lists_of_values;
select_result *result;
+ table_value_constr(List<List_item> tvc_values) :
+ lists_of_values(tvc_values), result(0)
+ { }
+
bool prepare(THD *thd_arg, SELECT_LEX *sl,
select_result *tmp_result);
bool exec();
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index c5cedf795a3..52880cd4442 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -1357,17 +1357,21 @@ bool st_select_lex_unit::exec()
we don't calculate found_rows() per union part.
Otherwise, SQL_CALC_FOUND_ROWS should be done on all sub parts.
*/
- sl->join->select_options=
- (select_limit_cnt == HA_POS_ERROR || sl->braces) ?
- sl->options & ~OPTION_FOUND_ROWS : sl->options | found_rows_for_union;
- saved_error= sl->join->optimize();
+ if (!sl->tvc)
+ {
+ sl->join->select_options=
+ (select_limit_cnt == HA_POS_ERROR || sl->braces) ?
+ sl->options & ~OPTION_FOUND_ROWS : sl->options | found_rows_for_union;
+ saved_error= sl->join->optimize();
+ }
}
if (!saved_error)
{
records_at_start= table->file->stats.records;
if (sl->tvc)
sl->tvc->exec();
- sl->join->exec();
+ else
+ sl->join->exec();
if (sl == union_distinct && !(with_element && with_element->is_recursive))
{
// This is UNION DISTINCT, so there should be a fake_select_lex
@@ -1376,7 +1380,8 @@ bool st_select_lex_unit::exec()
DBUG_RETURN(TRUE);
table->no_keyread=1;
}
- saved_error= sl->join->error;
+ if (!sl->tvc)
+ saved_error= sl->join->error;
offset_limit_cnt= (ha_rows)(sl->offset_limit ?
sl->offset_limit->val_uint() :
0);
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index d6aceeaa8a6..b4a0e52f693 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -67,6 +67,7 @@
#include "lex_token.h"
#include "sql_lex.h"
#include "sql_sequence.h"
+#include "sql_tvc.h"
/* this is to get the bison compilation windows warnings out */
#ifdef _MSC_VER
@@ -16277,7 +16278,8 @@ table_value_constructor:
LEX *lex=Lex;
$$= Lex->current_select;
mysql_init_select(Lex);
- $$->tvc->lists_of_values= lex->many_values;
+ table_value_constr tvc(lex->many_values);
+ $$->tvc= &tvc;
}
;