From a5a01dbb088a100cd6d72838815f33e1e6bd409a Mon Sep 17 00:00:00 2001 From: Galina Shalygina Date: Tue, 29 Aug 2017 21:03:15 +0200 Subject: [PATCH] Mistakes corrected. Now all tests in opt_tvc.test file work correctly --- mysql-test/r/opt_tvc.result | 16 ++++++++-------- sql/sql_derived.cc | 3 --- sql/sql_select.cc | 13 ++++--------- sql/sql_tvc.cc | 1 - sql/table.h | 1 - 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/mysql-test/r/opt_tvc.result b/mysql-test/r/opt_tvc.result index 59f005ef510..feaafabcbf2 100644 --- a/mysql-test/r/opt_tvc.result +++ b/mysql-test/r/opt_tvc.result @@ -95,13 +95,13 @@ b in (1,5); 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 Using where +1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 100.00 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 `tvc_0`.`1` = `test`.`t1`.`a` and `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 `test`.`t1`.`b` = `tvc_1`.`1` explain extended select * from t1 where a in ( @@ -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 Using where +1 PRIMARY eq_ref distinct_key distinct_key 4 func 1 100.00 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 `tvc_0`.`1` = `test`.`t1`.`a` and `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 `test`.`t1`.`b` = `tvc_1`.`1` # subquery with IN-predicate select * from t1 where a in @@ -443,11 +443,11 @@ 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 Using where +2 DERIVED eq_ref distinct_key distinct_key 4 func 1 100.00 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 `tvc_0`.`3` = `test`.`t1`.`b` 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 1 group by `test`.`t1`.`b`) `dr_table` explain extended select * from ( select max(a),b @@ -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 Using where +2 DERIVED eq_ref distinct_key distinct_key 4 func 1 100.00 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 `tvc_0`.`3` = `test`.`t1`.`b` 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 1 group by `test`.`t1`.`b`) `dr_table` drop table t1, t2; set @@in_subquery_conversion_threshold= default; diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index da96f5d425b..cd8540eb072 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -646,9 +646,6 @@ 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 e0e2a778e90..2acc3ea39b4 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -13633,9 +13633,8 @@ static int compare_fields_by_table_order(Item *field1, static TABLE_LIST* embedding_sjm(Item *item) { Item_field *item_field= (Item_field *) (item->real_item()); - TABLE_LIST *tbl= item_field->field->table->pos_in_table_list; - TABLE_LIST *nest= tbl->embedding; - if (nest && nest->sj_mat_info && nest->sj_mat_info->is_used && !tbl->is_for_tvc) + TABLE_LIST *nest= item_field->field->table->pos_in_table_list->embedding; + if (nest && nest->sj_mat_info && nest->sj_mat_info->is_used) return nest; else return NULL; @@ -13712,7 +13711,6 @@ Item *eliminate_item_equal(THD *thd, COND *cond, COND_EQUAL *upper_levels, Item *head; TABLE_LIST *current_sjm= NULL; Item *current_sjm_head= NULL; - bool force_producing_equality= false; DBUG_ASSERT(!cond || cond->type() == Item::INT_ITEM || @@ -13734,8 +13732,6 @@ Item *eliminate_item_equal(THD *thd, COND *cond, COND_EQUAL *upper_levels, TABLE_LIST *emb_nest; head= item_equal->get_first(NO_PARTICULAR_TAB, NULL); it++; - if (((Item_field *)(head->real_item()))->field->table->pos_in_table_list->is_for_tvc) - force_producing_equality= true; if ((emb_nest= embedding_sjm(head))) { current_sjm= emb_nest; @@ -13803,7 +13799,7 @@ Item *eliminate_item_equal(THD *thd, COND *cond, COND_EQUAL *upper_levels, produce_equality= FALSE; } - if (produce_equality || force_producing_equality) + if (produce_equality) { if (eq_item && eq_list.push_back(eq_item, thd->mem_root)) return 0; @@ -13818,8 +13814,7 @@ Item *eliminate_item_equal(THD *thd, COND *cond, COND_EQUAL *upper_levels, equals on top level, or the constant. */ Item *head_item= (!item_const && current_sjm && - current_sjm_head != field_item && - !force_producing_equality) ? current_sjm_head: head; + current_sjm_head != field_item) ? current_sjm_head: head; Item *head_real_item= head_item->real_item(); if (head_real_item->type() == Item::FIELD_ITEM) head_item= head_real_item; diff --git a/sql/sql_tvc.cc b/sql/sql_tvc.cc index 28d748877fd..263dc24a9b0 100644 --- a/sql/sql_tvc.cc +++ b/sql/sql_tvc.cc @@ -466,7 +466,6 @@ st_select_lex *make_new_subselect_for_tvc(THD *thd_arg, TL_READ, MDL_SHARED_READ))) goto err; - new_tab->is_for_tvc= true; //shows that this derived table is defined by TVC sel->add_joined_table(new_tab); new_tab->select_lex->add_where_field(new_tab->derived->first_select()); diff --git a/sql/table.h b/sql/table.h index b9606145e2a..478b65efec5 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1930,7 +1930,6 @@ struct TABLE_LIST */ st_select_lex_unit *derived; /* SELECT_LEX_UNIT of derived table */ With_element *with; /* With element defining this table (if any) */ - bool is_for_tvc; /* If specification of this table contains tvc*/ /* Bitmap of the defining with element */ table_map with_internal_reference_map; bool block_handle_derived;