diff --git a/mysql-test/r/opt_tvc.result b/mysql-test/r/opt_tvc.result index a3c71faff46..59f005ef510 100644 --- a/mysql-test/r/opt_tvc.result +++ b/mysql-test/r/opt_tvc.result @@ -116,13 +116,13 @@ from (values (1),(5)) as tvc_1 id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY ALL distinct_key NULL NULL NULL 2 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using join buffer (flat, BNL join) -1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 100.00 Using where 4 MATERIALIZED ALL NULL NULL NULL NULL 2 100.00 2 MATERIALIZED ALL NULL NULL NULL NULL 2 100.00 5 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) semi join ((values (1),(5)) `tvc_1`) where `test`.`t1`.`b` = `tvc_1`.`1` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) semi join ((values (1),(5)) `tvc_1`) where `tvc_0`.`1` = `test`.`t1`.`a` and `test`.`t1`.`b` = `tvc_1`.`1` # subquery with IN-predicate select * from t1 where a in @@ -463,10 +463,10 @@ group by b id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY ALL NULL NULL NULL NULL 12 100.00 2 DERIVED t1 ALL NULL NULL NULL NULL 6 100.00 Using temporary; Using filesort -2 DERIVED eq_ref distinct_key distinct_key 4 func 1 100.00 +2 DERIVED eq_ref distinct_key distinct_key 4 func 1 100.00 Using where 3 MATERIALIZED ALL NULL NULL NULL NULL 2 100.00 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `dr_table`.`max(a)` AS `max(a)`,`dr_table`.`b` AS `b` from (/* select#2 */ select max(`test`.`t1`.`a`) AS `max(a)`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(5)) `tvc_0`) where 1 group by `test`.`t1`.`b`) `dr_table` +Note 1003 /* select#1 */ select `dr_table`.`max(a)` AS `max(a)`,`dr_table`.`b` AS `b` from (/* select#2 */ select max(`test`.`t1`.`a`) AS `max(a)`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (3),(5)) `tvc_0`) where `tvc_0`.`3` = `test`.`t1`.`b` group by `test`.`t1`.`b`) `dr_table` drop table t1, t2; set @@in_subquery_conversion_threshold= default; diff --git a/mysql-test/r/table_value_constr.result b/mysql-test/r/table_value_constr.result index 411edc53168..f8161edf708 100644 --- a/mysql-test/r/table_value_constr.result +++ b/mysql-test/r/table_value_constr.result @@ -1,5 +1,6 @@ create table t1 (a int, b int); -insert into t1 values (1,2),(4,6),(9,7),(1,1),(2,5),(7,8); +insert into t1 values (1,2),(4,6),(9,7), +(1,1),(2,5),(7,8); # just VALUES values (1,2); 1 2 diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 09fbf3e239c..e57239bef4e 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -265,6 +265,13 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref) if (check_stack_overrun(thd, STACK_MIN_SIZE, (uchar*)&res)) return TRUE; + if (unit->first_select() && + unit->first_select()->tvc) + { + my_error(ER_NO_TVC_IN_SUBQUERY, MYF(0)); + res= 1; + goto end; + } if (!(res= engine->prepare(thd))) { diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 1a547e44820..c8cf51a5297 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7490,5 +7490,9 @@ ER_WRONG_INSERT_INTO_SEQUENCE eng "Wrong INSERT into a SEQUENCE. One can only do single table INSERT into a squence object (like with mysqldump). If you want to change the SEQUENCE, use ALTER SEQUENCE instead." ER_SP_STACK_TRACE eng "At line %u in %s" -ER_WRONG_NUMBER_OF_COLUMNS_IN_TABLE_VALUE_CONSTRUCTOR - eng "The used TABLE VALUE CONSTRUCTOR has a different number of columns" +ER_WRONG_NUMBER_OF_VALUES_IN_TVC + eng "The used table value constructor has a different number of values" +ER_UNKNOWN_VALUE_IN_TVC + eng "Unknown value '%d' in table values constructor definition" +ER_NO_TVC_IN_SUBQUERY + eng "The usage of table value constructor as specification of subselect isn't implemented yet" \ No newline at end of file diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index cd8540eb072..da96f5d425b 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -646,6 +646,9 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) SELECT_LEX *first_select= unit->first_select(); + if (first_select->tvc) + derived->is_for_tvc= true; + if (derived->is_recursive_with_table() && !derived->is_with_table_recursive_reference() && !derived->with->rec_result && derived->with->get_sq_rec_ref()) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index ab87bc00c8c..e0e2a778e90 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -347,8 +347,7 @@ bool handle_select(THD *thd, LEX *lex, select_result *result, MYSQL_SELECT_START(thd->query()); if (select_lex->master_unit()->is_unit_op() || - select_lex->master_unit()->fake_select_lex || - select_lex->tvc) + select_lex->master_unit()->fake_select_lex) res= mysql_union(thd, lex, result, &lex->unit, setup_tables_done_option); else { diff --git a/sql/sql_tvc.cc b/sql/sql_tvc.cc index e9476254f9e..28d748877fd 100644 --- a/sql/sql_tvc.cc +++ b/sql/sql_tvc.cc @@ -46,13 +46,20 @@ bool join_type_handlers_for_tvc(THD *thd_arg, List_iterator_fast &li, if (first_list_el_count != lst->elements) { - my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_TABLE_VALUE_CONSTRUCTOR, - ER_THD(thd_arg, ER_WRONG_NUMBER_OF_COLUMNS_IN_TABLE_VALUE_CONSTRUCTOR), + my_message(ER_WRONG_NUMBER_OF_VALUES_IN_TVC, + ER_THD(thd_arg, ER_WRONG_NUMBER_OF_VALUES_IN_TVC), MYF(0)); DBUG_RETURN(true); } for (uint pos= 0; (item=it++); pos++) { + if (item->type() == Item::FIELD_ITEM) + { + my_error(ER_UNKNOWN_VALUE_IN_TVC, MYF(0), + ((Item_field *)item)->full_name(), + MYF(0)); + DBUG_RETURN(true); + } const Type_handler *item_type_handler= item->real_type_handler(); if (first) holders[pos].set_handler(item_type_handler);