diff options
-rw-r--r-- | mysql-test/r/subselect.result | 16 | ||||
-rw-r--r-- | mysql-test/r/subselect2.result | 10 | ||||
-rw-r--r-- | sql/item_subselect.cc | 18 | ||||
-rw-r--r-- | sql/item_subselect.h | 22 | ||||
-rw-r--r-- | sql/sql_select.cc | 38 | ||||
-rw-r--r-- | sql/sql_select.h | 2 |
6 files changed, 54 insertions, 52 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index e846f557c7c..6cac5a9bc6c 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -840,7 +840,7 @@ a t1.a in (select t2.a from t2) explain SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 Using index -2 DEPENDENT SUBQUERY t2 index_in a a 5 func 2 Using index +2 DEPENDENT SUBQUERY t2 index_subquery a a 5 func 2 Using index CREATE TABLE t3 (a int(11) default '0'); INSERT INTO t3 VALUES (1),(2),(3); SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; @@ -1253,7 +1253,7 @@ a explain select * from t2 where t2.a in (select a from t1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 Using where; Using index -2 DEPENDENT SUBQUERY t1 simple_in PRIMARY PRIMARY 4 func 1 Using index +2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 Using index select * from t2 where t2.a in (select a from t1 where t1.b <> 30); a 2 @@ -1261,7 +1261,7 @@ a explain select * from t2 where t2.a in (select a from t1 where t1.b <> 30); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 Using where; Using index -2 DEPENDENT SUBQUERY t1 simple_in PRIMARY PRIMARY 4 func 1 Using index; Using where +2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 Using index; Using where select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); a 2 @@ -1286,7 +1286,7 @@ a explain select * from t2 where t2.a in (select a from t1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 index NULL a 5 NULL 4 Using where; Using index -2 DEPENDENT SUBQUERY t1 index_in a a 5 func 1001 Using index +2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 Using index select * from t2 where t2.a in (select a from t1 where t1.b <> 30); a 2 @@ -1294,7 +1294,7 @@ a explain select * from t2 where t2.a in (select a from t1 where t1.b <> 30); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 index NULL a 5 NULL 4 Using where; Using index -2 DEPENDENT SUBQUERY t1 index_in a a 5 func 1001 Using index; Using where +2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 Using index; Using where select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); a 2 @@ -1317,7 +1317,7 @@ a explain select * from t2 where t2.a in (select a from t1 where t1.b <> 30); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 index NULL a 5 NULL 4 Using where; Using index -2 DEPENDENT SUBQUERY t1 index_in a a 5 func 1001 Using index; Using where +2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 Using index; Using where drop table t1, t2, t3; create table t1 (a int, b int); create table t2 (a int, b int); @@ -1405,9 +1405,9 @@ a3 1 explain select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 Using index -2 DEPENDENT SUBQUERY t2 index_in s1 s1 6 func 2 Using index +2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 Using index explain select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 Using index -2 DEPENDENT SUBQUERY t2 index_in s1 s1 6 func 1 Using index; Using where +2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 1 Using index; Using where drop table t1,t2; diff --git a/mysql-test/r/subselect2.result b/mysql-test/r/subselect2.result index c387d8b2d76..98df44553d2 100644 --- a/mysql-test/r/subselect2.result +++ b/mysql-test/r/subselect2.result @@ -123,9 +123,9 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 0 const row not found 1 PRIMARY t2 ALL DDOCTYPEID_IDX NULL NULL NULL 9 Using where 1 PRIMARY t4 eq_ref PRIMARY PRIMARY 32 test.t2.DOCTYPEID 1 -2 DEPENDENT SUBQUERY t3 simple_in PRIMARY,FFOLDERID_IDX PRIMARY 32 func 1 Using index; Using where -3 DEPENDENT SUBQUERY t3 simple_in PRIMARY,FFOLDERID_IDX PRIMARY 32 func 1 Using index; Using where -4 DEPENDENT SUBQUERY t3 simple_in PRIMARY,FFOLDERID_IDX PRIMARY 32 func 1 Using index; Using where -5 DEPENDENT SUBQUERY t3 simple_in PRIMARY,FFOLDERID_IDX PRIMARY 32 func 1 Using index; Using where -6 DEPENDENT SUBQUERY t3 simple_in PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 32 func 1 Using index; Using where +2 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,FFOLDERID_IDX PRIMARY 32 func 1 Using index; Using where +3 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,FFOLDERID_IDX PRIMARY 32 func 1 Using index; Using where +4 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,FFOLDERID_IDX PRIMARY 32 func 1 Using index; Using where +5 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,FFOLDERID_IDX PRIMARY 32 func 1 Using index; Using where +6 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 32 func 1 Using index; Using where drop table t1, t2, t3, t4; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 773c7ddd9de..7c4fe8621a7 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -773,7 +773,7 @@ int subselect_union_engine::prepare() return unit->prepare(thd, result, 0); } -int subselect_simplein_engine::prepare() +int subselect_uniquesubquery_engine::prepare() { //this never should be called DBUG_ASSERT(0); @@ -860,7 +860,7 @@ void subselect_union_engine::fix_length_and_dec(Item_cache **row) } } -void subselect_simplein_engine::fix_length_and_dec(Item_cache **row) +void subselect_uniquesubquery_engine::fix_length_and_dec(Item_cache **row) { //this never should be called DBUG_ASSERT(0); @@ -919,9 +919,9 @@ int subselect_union_engine::exec() return res; } -int subselect_simplein_engine::exec() +int subselect_uniquesubquery_engine::exec() { - DBUG_ENTER("subselect_simplein_engine::exec"); + DBUG_ENTER("subselect_uniquesubquery_engine::exec"); int error; TABLE *table= tab->table; if ((tab->ref.key_err= (*tab->ref.key_copy)->copy())) @@ -949,9 +949,9 @@ int subselect_simplein_engine::exec() DBUG_RETURN(end_exec(table) || (error != 0)); } -int subselect_simplein_engine::end_exec(TABLE *table) +int subselect_uniquesubquery_engine::end_exec(TABLE *table) { - DBUG_ENTER("subselect_simplein_engine::end_exec"); + DBUG_ENTER("subselect_uniquesubquery_engine::end_exec"); int error=0, tmp; if ((tmp= table->file->extra(HA_EXTRA_NO_CACHE))) { @@ -968,9 +968,9 @@ int subselect_simplein_engine::end_exec(TABLE *table) DBUG_RETURN(error != 0); } -int subselect_indexin_engine::exec() +int subselect_indexsubquery_engine::exec() { - DBUG_ENTER("subselect_indexin_engine::exec"); + DBUG_ENTER("subselect_indexsubselect_engine::exec"); int error; bool null_finding= 0; TABLE *table= tab->table; @@ -1075,7 +1075,7 @@ void subselect_union_engine::exclude() unit->exclude_level(); } -void subselect_simplein_engine::exclude() +void subselect_uniquesubquery_engine::exclude() { //this never should be called DBUG_ASSERT(0); diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 174e8809688..a17715c57c1 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -183,8 +183,8 @@ public: void fix_length_and_dec(); friend class select_exists_subselect; - friend class subselect_simplein_engine; - friend class subselect_indexin_engine; + friend class subselect_uniquesubquery_engine; + friend class subselect_indexsubquery_engine; }; /* IN subselect */ @@ -227,7 +227,7 @@ public: friend class Item_ref_null_helper; friend class Item_is_not_null_test; - friend class subselect_indexin_engine; + friend class subselect_indexsubquery_engine; }; /* ALL/ANY/SOME subselect */ @@ -313,15 +313,15 @@ public: }; struct st_join_table; -class subselect_simplein_engine: public subselect_engine +class subselect_uniquesubquery_engine: public subselect_engine { protected: st_join_table *tab; Item *cond; public: - subselect_simplein_engine(THD *thd, st_join_table *tab_arg, - Item_subselect *subs, Item *where) + subselect_uniquesubquery_engine(THD *thd, st_join_table *tab_arg, + Item_subselect *subs, Item *where) :subselect_engine(thd, subs, 0), tab(tab_arg), cond(where) {} @@ -335,14 +335,14 @@ public: static int end_exec(TABLE *table); }; -class subselect_indexin_engine: public subselect_simplein_engine +class subselect_indexsubquery_engine: public subselect_uniquesubquery_engine { bool check_null; public: - subselect_indexin_engine(THD *thd, st_join_table *tab_arg, - Item_subselect *subs, Item *where, - bool chk_null) - :subselect_simplein_engine(thd, tab_arg, subs, where), + subselect_indexsubquery_engine(THD *thd, st_join_table *tab_arg, + Item_subselect *subs, Item *where, + bool chk_null) + :subselect_uniquesubquery_engine(thd, tab_arg, subs, where), check_null(chk_null) {} int exec(); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5319434a8f6..ab985ffbc6d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -32,7 +32,7 @@ const char *join_type_str[]={ "UNKNOWN","system","const","eq_ref","ref", "MAYBE_REF","ALL","range","index","fulltext", - "ref_or_null","simple_in","index_in" + "ref_or_null","unique_subquery","index_subquery" }; static void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array); @@ -773,13 +773,14 @@ JOIN::optimize() { if (test_in_subselect(&where)) { - join_tab[0].type= JT_SIMPLE_IN; + join_tab[0].type= JT_UNIQUE_SUBQUERY; error= 0; DBUG_RETURN(unit->item-> - change_engine(new subselect_simplein_engine(thd, - join_tab, - unit->item, - where))); + change_engine(new + subselect_uniquesubquery_engine(thd, + join_tab, + unit->item, + where))); } } else if (join_tab[0].type == JT_REF && @@ -787,14 +788,15 @@ JOIN::optimize() { if (test_in_subselect(&where)) { - join_tab[0].type= JT_INDEX_IN; + join_tab[0].type= JT_INDEX_SUBQUERY; error= 0; DBUG_RETURN(unit->item-> - change_engine(new subselect_indexin_engine(thd, - join_tab, - unit->item, - where, - 0))); + change_engine(new + subselect_indexsubquery_engine(thd, + join_tab, + unit->item, + where, + 0))); } } } else if (join_tab[0].type == JT_REF_OR_NULL && @@ -803,7 +805,7 @@ JOIN::optimize() ((Item_func *) having)->functype() == Item_func::ISNOTNULLTEST_FUNC) { - join_tab[0].type= JT_INDEX_IN; + join_tab[0].type= JT_INDEX_SUBQUERY; error= 0; if ((conds= remove_additional_cond(conds))) @@ -812,11 +814,11 @@ JOIN::optimize() join_tab->info= "Using index"; DBUG_RETURN(unit->item-> - change_engine(new subselect_indexin_engine(thd, - join_tab, - unit->item, - conds, - 1))); + change_engine(new subselect_indexsubquery_engine(thd, + join_tab, + unit->item, + conds, + 1))); } } diff --git a/sql/sql_select.h b/sql/sql_select.h index 9ca46a505aa..6c17a646ee6 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -76,7 +76,7 @@ typedef struct st_join_cache { enum join_type { JT_UNKNOWN,JT_SYSTEM,JT_CONST,JT_EQ_REF,JT_REF,JT_MAYBE_REF, JT_ALL, JT_RANGE, JT_NEXT, JT_FT, JT_REF_OR_NULL, - JT_SIMPLE_IN, JT_INDEX_IN}; + JT_UNIQUE_SUBQUERY, JT_INDEX_SUBQUERY}; class JOIN; |