From 3fbcafea9c5e85dc6315f0b89872ac5e273195c8 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Sep 2002 09:50:36 +0300 Subject: [PATCH 1/6] subselect with union new error handling Item_ref bug fixed include/mysql_com.h: new error handling query cache pointer description mysql-test/r/distinct.result: new result's after Monty's bug fixing mysql-test/r/subselect.result: subselect with union test mysql-test/t/subselect.test: subselect with union test sql/item.cc: subselect with union Item_ref bug fixed sql/item_cmpfunc.cc: Monty's bug fixing sql/item_subselect.cc: TODO changing subselect with union sql/item_subselect.h: subselect with union sql/mysql_priv.h: Item_ref bug fixed sql/mysqld.cc: new error handling sql/net_pkg.cc: new error handling sql/net_serv.cc: new error handling sql/sql_base.cc: Item_ref bug fixed sql/sql_class.cc: new error handling sql/sql_class.h: new error handling sql/sql_derived.cc: subselect with union sql/sql_insert.cc: new error handling (only with mysql_select now) sql/sql_lex.cc: subselect with union sql/sql_lex.h: subselect with union sql/sql_parse.cc: new error handling sql/sql_select.cc: new error handling subselect with union removed thd->where=0 hack sql/sql_select.h: subselect with union sql/sql_union.cc: subselect with union sql/sql_update.cc: new error handling (only with mysql_select now) sql/sql_yacc.yy: subselect with union --- include/mysql_com.h | 7 +- mysql-test/r/distinct.result | 3 +- mysql-test/r/subselect.result | 21 +- mysql-test/t/subselect.test | 12 +- sql/item.cc | 25 ++- sql/item_cmpfunc.cc | 2 + sql/item_subselect.cc | 214 +++++++++++++------- sql/item_subselect.h | 125 ++++++++---- sql/mysql_priv.h | 7 +- sql/mysqld.cc | 3 +- sql/net_pkg.cc | 5 +- sql/net_serv.cc | 37 ++-- sql/sql_base.cc | 36 ++-- sql/sql_class.cc | 48 +++-- sql/sql_class.h | 4 +- sql/sql_derived.cc | 2 +- sql/sql_insert.cc | 2 + sql/sql_lex.cc | 9 +- sql/sql_lex.h | 32 ++- sql/sql_parse.cc | 20 +- sql/sql_select.cc | 69 +++---- sql/sql_select.h | 4 +- sql/sql_union.cc | 368 ++++++++++++++++++++-------------- sql/sql_update.cc | 3 + sql/sql_yacc.yy | 10 +- 25 files changed, 686 insertions(+), 382 deletions(-) diff --git a/include/mysql_com.h b/include/mysql_com.h index c259259c9e2..ca6a9527461 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -132,8 +132,13 @@ typedef struct st_net { unsigned int *return_status; unsigned char reading_or_writing; char save_char; + my_bool report_error; /* We should report error (we have unreported error) */ my_bool no_send_ok; - gptr query_cache_query; + /* + Pointer to query object in query cache, do not equal NULL (0) for + queries in cache that have not stored its results yet + */ + gptr query_cache_query; } NET; #define packet_error (~(unsigned long) 0) diff --git a/mysql-test/r/distinct.result b/mysql-test/r/distinct.result index e347a95b037..89f4a8ae7f2 100644 --- a/mysql-test/r/distinct.result +++ b/mysql-test/r/distinct.result @@ -92,7 +92,8 @@ NULL NULL NULL 0 0 select id >= 0 and id <= 5 as grp,count(*) from t1 group by grp; grp count(*) -0 7 +NULL 1 +0 6 1 6 SELECT DISTINCT FACILITY FROM t1; FACILITY diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index bd92c496f29..e7cfa50d7f7 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -1,7 +1,7 @@ select (select 2); (select 2) 2 -drop table if exists t1,t2,t3,t4; +drop table if exists t1,t2,t3,t4,t5; create table t1 (a int); create table t2 (a int, b int); create table t3 (a int); @@ -82,4 +82,21 @@ select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 where t2.b=t4.b); b ma 7 12 -drop table t1,t2,t3,t4; +create table t5 (a int); +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +NULL 1 +2 2 +insert into t5 values (5); +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +NULL 1 +2 2 +insert into t5 values (2); +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +NULL 1 +2 2 +select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; +Subselect return more than 1 record +drop table t1,t2,t3,t4,t5; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 7b1ebdcbc27..224149900d2 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -1,6 +1,6 @@ select (select 2); -drop table if exists t1,t2,t3,t4; +drop table if exists t1,t2,t3,t4,t5; create table t1 (a int); create table t2 (a int, b int); create table t3 (a int); @@ -33,4 +33,12 @@ select b,max(a) as ma from t4 group by b having b < (select max(t2.a) from t2 where t2.b=t4.b); select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 where t2.b=t4.b); -drop table t1,t2,t3,t4; +create table t5 (a int); +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +insert into t5 values (5); +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +insert into t5 values (2); +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +-- error 1230 +select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; +drop table t1,t2,t3,t4,t5; diff --git a/sql/item.cc b/sql/item.cc index 81c5168b72d..47171206e3d 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -457,7 +457,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) if (!field) // If field is not checked { Field *tmp; - if (!(tmp=find_field_in_tables(thd,this,tables))) + if (!(tmp=find_field_in_tables(thd, this, tables, 0))) { /* We can't find table field in table list of current select, @@ -473,9 +473,14 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) sl && !tmp; sl= sl->outer_select()) tmp=find_field_in_tables(thd, this, - (TABLE_LIST*)(last= sl)->table_list.first); + (TABLE_LIST*)(last= sl)->table_list.first, + 0); if (!tmp) - return 1; + { + // Call to produce appropriate error message + find_field_in_tables(thd, this, tables, 1); + return -1; + } else { depended_from= last; @@ -488,7 +493,8 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) s= s->outer_select()) if( !s->depended ) { - s->depended= 1; //Select is depended of outer select + // Select is depended of outer select + s->depended= s->master_unit()->depended= 1; //Tables will be reopened many times for (TABLE_LIST *tbl= (TABLE_LIST*)s->table_list.first; @@ -803,7 +809,7 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) { if (!ref) { - if (!(ref= find_item_in_list(this,thd->lex.select->item_list))) + if (!(ref= find_item_in_list(this, thd->lex.select->item_list, 0))) { /* We can't find table field in table list of current select, @@ -818,9 +824,13 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) for (SELECT_LEX *sl= thd->lex.select->outer_select(); sl && !ref; sl= sl->outer_select()) - ref= find_item_in_list(this, (last= sl)->item_list); + ref= find_item_in_list(this, (last= sl)->item_list, 0); if (!ref) + { + // Call to report error + find_item_in_list(this, thd->lex.select->item_list, 1); return 1; + } else { depended_from= last; @@ -833,7 +843,8 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) s= s->outer_select()) if( !s->depended ) { - s->depended= 1; //Select is depended of outer select + // Select is depended of outer select + s->depended= s->master_unit()->depended= 1; //Tables will be reopened many times for (TABLE_LIST *tbl= (TABLE_LIST*)s->table_list.first; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 0fc9a1f0e4c..d1a130aa12b 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1101,6 +1101,8 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) used_tables_cache|=item->used_tables(); with_sum_func= with_sum_func || item->with_sum_func; const_item_cache&=item->const_item(); + if (item->maybe_null) + maybe_null=1; } if (thd) thd->cond_count+=list.elements; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 2bff2af45e4..18e9f51925a 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -23,9 +23,6 @@ SUBSELECT TODO: - remove double 'having' & 'having_list' from JOIN (sql_select.h/sql_select.cc) - - subselect in HAVING clause - - add subselect union select (sql_union.cc) - */ #ifdef __GNUC__ @@ -37,21 +34,17 @@ SUBSELECT TODO: Item_subselect::Item_subselect(THD *thd, st_select_lex *select_lex, select_subselect *result): - assigned(0), executed(0), optimized(0), error(0) + engine_owner(1), value_assigned(0) { DBUG_ENTER("Item_subselect::Item_subselect"); DBUG_PRINT("subs", ("select_lex 0x%xl", (long) select_lex)); - this->result= result; - SELECT_LEX_UNIT *unit= select_lex->master_unit(); - unit->offset_limit_cnt= unit->global_parameters->offset_limit; - unit->select_limit_cnt= unit->global_parameters->select_limit+ - unit->global_parameters ->offset_limit; - if (unit->select_limit_cnt < unit->global_parameters->select_limit) - unit->select_limit_cnt= HA_POS_ERROR; // no limit - if (unit->select_limit_cnt == HA_POS_ERROR) - select_lex->options&= ~OPTION_FOUND_ROWS; - join= new JOIN(thd, select_lex->item_list, select_lex->options, result); - this->select_lex= select_lex; + + if (select_lex->next_select()) + engine= new subselect_union_engine(thd, select_lex->master_unit(), result, + this); + else + engine= new subselect_single_select_engine(thd, select_lex, result, + this); assign_null(); /* item value is NULL if select_subselect not changed this value @@ -61,6 +54,12 @@ Item_subselect::Item_subselect(THD *thd, st_select_lex *select_lex, DBUG_VOID_RETURN; } +Item_subselect::~Item_subselect() +{ + if (engine_owner) + delete engine; +} + void Item_subselect::make_field (Send_field *tmp_field) { if (null_value) @@ -78,62 +77,17 @@ void Item_subselect::make_field (Send_field *tmp_field) bool Item_subselect::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) { // Is it one field subselect? - if (select_lex->item_list.elements > max_columns) + if (engine->cols() > max_columns) { - my_printf_error(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL), MYF(0)); + my_message(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL), MYF(0)); return 1; } - SELECT_LEX *save_select= thd->lex.select; - thd->lex.select= select_lex; - if(join->prepare((TABLE_LIST*) select_lex->table_list.first, - select_lex->where, - (ORDER*) select_lex->order_list.first, - (ORDER*) select_lex->group_list.first, - select_lex->having, - (ORDER*) 0, select_lex, - select_lex->master_unit())) - return 1; - thd->lex.select= save_select; - return 0; -} - -int Item_subselect::exec() -{ - DBUG_ENTER("Item_subselect::exec"); - if (!optimized) - { - optimized=1; - if (join->optimize()) - { - executed= 1; - DBUG_RETURN(join->error?join->error:1); - } - } - if (join->select_lex->depended && executed) - { - if (join->reinit()) - { - error= 1; - DBUG_RETURN(1); - } - assign_null(); - executed= assigned= 0; - } - if (!executed) - { - SELECT_LEX *save_select= join->thd->lex.select; - join->thd->lex.select= select_lex; - join->exec(); - join->thd->lex.select= save_select; - executed= 1; - DBUG_RETURN(join->error); - } - DBUG_RETURN(0); + return engine->prepare(); } inline table_map Item_subselect::used_tables() const { - return (table_map) select_lex->depended ? 1L : 0L; + return (table_map) engine->depended() ? 1L : 0L; } Item_singleval_subselect::Item_singleval_subselect(THD *thd, @@ -151,21 +105,21 @@ Item::Type Item_subselect::type() const double Item_singleval_subselect::val () { - if (exec()) + if (engine->exec()) return 0; return real_value; } longlong Item_singleval_subselect::val_int () { - if (exec()) + if (engine->exec()) return 0; return int_value; } String *Item_singleval_subselect::val_str (String *str) { - if (exec() || null_value) + if (engine->exec() || null_value) return 0; return &str_value; } @@ -183,23 +137,143 @@ Item_exists_subselect::Item_exists_subselect(THD *thd, double Item_exists_subselect::val () { - if (exec()) + if (engine->exec()) return 0; return (double) value; } longlong Item_exists_subselect::val_int () { - if (exec()) + if (engine->exec()) return 0; return value; } String *Item_exists_subselect::val_str(String *str) { - if (exec()) + if (engine->exec()) return 0; str->set(value); return str; } + +subselect_single_select_engine::subselect_single_select_engine(THD *thd, + st_select_lex *select, + select_subselect *result, + Item_subselect *item): + subselect_engine(thd, item, result), + executed(0), optimized(0) +{ + select_lex= select; + SELECT_LEX_UNIT *unit= select_lex->master_unit(); + unit->offset_limit_cnt= unit->global_parameters->offset_limit; + unit->select_limit_cnt= unit->global_parameters->select_limit+ + unit->global_parameters ->offset_limit; + if (unit->select_limit_cnt < unit->global_parameters->select_limit) + unit->select_limit_cnt= HA_POS_ERROR; // no limit + if (unit->select_limit_cnt == HA_POS_ERROR) + select_lex->options&= ~OPTION_FOUND_ROWS; + join= new JOIN(thd, select_lex->item_list, select_lex->options, result); + if (!join || !result) + { + //out of memory + thd->fatal_error= 1; + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); + } + this->select_lex= select_lex; +} + +subselect_union_engine::subselect_union_engine(THD *thd, + st_select_lex_unit *u, + select_subselect *result, + Item_subselect *item): + subselect_engine(thd, item, result) +{ + unit= u; + if( !result) + { + //out of memory + thd->fatal_error= 1; + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); + } + unit->item= item; +} + +int subselect_single_select_engine::prepare() +{ + SELECT_LEX *save_select= thd->lex.select; + thd->lex.select= select_lex; + if(join->prepare((TABLE_LIST*) select_lex->table_list.first, + select_lex->where, + (ORDER*) select_lex->order_list.first, + (ORDER*) select_lex->group_list.first, + select_lex->having, + (ORDER*) 0, select_lex, + select_lex->master_unit(), 0)) + return 1; + thd->lex.select= save_select; + return 0; +} + +int subselect_union_engine::prepare() +{ + return unit->prepare(thd, result); +} + + +int subselect_single_select_engine::exec() +{ + DBUG_ENTER("subselect_single_select_engine::exec"); + if (!optimized) + { + optimized=1; + if (join->optimize()) + { + executed= 1; + DBUG_RETURN(join->error?join->error:1); + } + } + if (select_lex->depended && executed) + { + if (join->reinit()) + DBUG_RETURN(1); + item->assign_null(); + item->assigned((executed= 0)); + } + if (!executed) + { + SELECT_LEX *save_select= join->thd->lex.select; + join->thd->lex.select= select_lex; + join->exec(); + join->thd->lex.select= save_select; + executed= 1; + DBUG_RETURN(join->error||thd->fatal_error); + } + DBUG_RETURN(0); +} + +int subselect_union_engine::exec() +{ + return unit->exec(); +} + +uint subselect_single_select_engine::cols() +{ + return select_lex->item_list.elements; +} + +uint subselect_union_engine::cols() +{ + return unit->first_select()->item_list.elements; +} + +bool subselect_single_select_engine::depended() +{ + return select_lex->depended; +} + +bool subselect_union_engine::depended() +{ + return unit->depended; +} diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 3f363df33df..0d8495d3ae8 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -20,31 +20,25 @@ #pragma interface /* gcc class implementation */ #endif -struct st_select_lex; +class st_select_lex; +class st_select_lex_unit; class JOIN; class select_subselect; +class subselect_engine; /* base class for subselects */ class Item_subselect :public Item { + my_bool engine_owner; /* Is this item owner of engine */ + my_bool value_assigned; /* value already assigned to subselect */ protected: + /* engine that perform execution of subselect (single select or union) */ + subselect_engine *engine; + /* allowed number of columns (1 for single value subqueries) */ uint max_columns; - my_bool assigned; /* value already assigned to subselect */ - my_bool executed; /* simple subselect is executed */ - my_bool optimized; /* simple subselect is optimized */ - my_bool error; /* error in query */ - int exec(); - virtual void assign_null() - { - null_value= 1; - } public: - st_select_lex *select_lex; - JOIN *join; - select_subselect *result; - Item_subselect(THD *thd, st_select_lex *select_lex, select_subselect* result); Item_subselect(Item_subselect *item) @@ -52,14 +46,17 @@ public: null_value= item->null_value; decimals= item->decimals; max_columns= item->max_columns; - assigned= item->assigned; - executed= item->executed; - select_lex= item->select_lex; - join= item->join; - result= item->result; + engine= item->engine; + engine_owner= 0; name= item->name; - error= item->error; } + ~Item_subselect(); + virtual void assign_null() + { + null_value= 1; + } + bool assigned() { return value_assigned; } + void assigned(bool a) { value_assigned= a; } enum Type type() const; bool is_null() { return null_value; } void make_field (Send_field *); @@ -75,18 +72,10 @@ public: class Item_singleval_subselect :public Item_subselect { protected: - longlong int_value; - double real_value; - enum Item_result res_type; + longlong int_value; /* here stored integer value of this item */ + double real_value; /* here stored real value of this item */ + enum Item_result res_type; /* type of results */ - virtual void assign_null() - { - null_value= 1; - int_value= 0; - real_value= 0; - max_length= 4; - res_type= STRING_RESULT; - } public: Item_singleval_subselect(THD *thd, st_select_lex *select_lex); Item_singleval_subselect(Item_singleval_subselect *item): @@ -98,6 +87,14 @@ public: decimals= item->decimals; res_type= item->res_type; } + virtual void assign_null() + { + null_value= 1; + int_value= 0; + real_value= 0; + max_length= 4; + res_type= STRING_RESULT; + } double val (); longlong val_int (); String *val_str (String *); @@ -112,12 +109,8 @@ public: class Item_exists_subselect :public Item_subselect { protected: - longlong value; + longlong value; /* value of this item (boolean: exists/not-exists) */ - virtual void assign_null() - { - value= 0; - } public: Item_exists_subselect(THD *thd, st_select_lex *select_lex); Item_exists_subselect(Item_exists_subselect *item): @@ -125,6 +118,11 @@ public: { value= item->value; } + virtual void assign_null() + { + value= 0; + } + Item *new_item() { return new Item_exists_subselect(this); } enum Item_result result_type() const { return INT_RESULT;} longlong val_int(); @@ -133,3 +131,58 @@ public: friend class select_exists_subselect; }; + +class subselect_engine +{ +protected: + select_subselect *result; /* results storage class */ + THD *thd; /* pointer to current THD */ + Item_subselect *item; /* item, that use this engine */ +public: + static void *operator new(size_t size) + { + return (void*) sql_alloc((uint) size); + } + static void operator delete(void *ptr, size_t size) {} + + subselect_engine(THD *thd, Item_subselect *si, select_subselect *res) + { + result= res; + item= si; + this->thd= thd; + } + virtual int prepare()= 0; + virtual int exec()= 0; + virtual uint cols()= 0; /* return number of columnss in select */ + virtual bool depended()= 0; /* depended from outer select */ +}; + +class subselect_single_select_engine: public subselect_engine +{ + my_bool executed; /* simple subselect is executed */ + my_bool optimized; /* simple subselect is optimized */ + st_select_lex *select_lex; /* corresponding select_lex */ + JOIN * join; /* corresponding JOIN structure */ +public: + subselect_single_select_engine(THD *thd, st_select_lex *select, + select_subselect *result, + Item_subselect *item); + virtual int prepare(); + virtual int exec(); + virtual uint cols(); + virtual bool depended(); +}; + +class subselect_union_engine: public subselect_engine +{ + st_select_lex_unit *unit; /* corresponding unit structure */ +public: + subselect_union_engine(THD *thd, + st_select_lex_unit *u, + select_subselect *result, + Item_subselect *item); + virtual int prepare(); + virtual int exec(); + virtual uint cols(); + virtual bool depended(); +}; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index c0371d1e90c..155d056db42 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -373,7 +373,7 @@ int handle_select(THD *thd, LEX *lex, select_result *result); int mysql_select(THD *thd,TABLE_LIST *tables,List &list,COND *conds, ORDER *order, ORDER *group,Item *having,ORDER *proc_param, ulong select_type,select_result *result, - SELECT_LEX_UNIT *unit); + SELECT_LEX_UNIT *unit, bool fake_select_lex); int mysql_union(THD *thd, LEX *lex,select_result *result); int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *s, TABLE_LIST *t); Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, @@ -438,7 +438,8 @@ bool wait_for_tables(THD *thd); bool table_is_used(TABLE *table, bool wait_for_name_lock); bool drop_locked_tables(THD *thd,const char *db, const char *table_name); void abort_locked_tables(THD *thd,const char *db, const char *table_name); -Field *find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables); +Field *find_field_in_tables(THD *thd, Item_field *item, TABLE_LIST *tables, + bool report_error); Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length, bool check_grant,bool allow_rowid); #ifdef HAVE_OPENSSL @@ -526,7 +527,7 @@ TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find); SQL_SELECT *make_select(TABLE *head, table_map const_tables, table_map read_tables, COND *conds, int *error); -Item ** find_item_in_list(Item *item,List &items); +Item ** find_item_in_list(Item *item, List &items, bool report_error); bool insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name, const char *table_name, List_iterator *it); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 98bfa162242..830c7324771 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1608,8 +1608,9 @@ static int my_message_sql(uint error, const char *str, NET *net; DBUG_ENTER("my_message_sql"); DBUG_PRINT("error",("Message: '%s'",str)); - if ((net=my_pthread_getspecific_ptr(NET*,THR_NET))) + if ((net= my_pthread_getspecific_ptr(NET*,THR_NET))) { + net->report_error= 1; if (!net->last_error[0]) // Return only first message { strmake(net->last_error,str,sizeof(net->last_error)-1); diff --git a/sql/net_pkg.cc b/sql/net_pkg.cc index fa3abc68bfa..5551e2b19bc 100644 --- a/sql/net_pkg.cc +++ b/sql/net_pkg.cc @@ -72,7 +72,10 @@ void send_error(NET *net, uint sql_errno, const char *err) } VOID(net_write_command(net,(uchar) 255,(char*) err,length)); if (thd) - thd->fatal_error=0; // Error message is given + { + thd->fatal_error= 0; // Error message is given + thd->net.report_error= 0; + } DBUG_VOID_RETURN; } diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 0d6e548a873..abda5a3c275 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -113,6 +113,7 @@ int my_net_init(NET *net, Vio* vio) net->where_b = net->remain_in_buf=0; net->last_errno=0; net->query_cache_query=0; + net->report_error= 0; if (vio != 0) /* If real connection */ { @@ -141,8 +142,9 @@ static my_bool net_realloc(NET *net, ulong length) if (length >= max_allowed_packet) { DBUG_PRINT("error",("Packet too large (%lu)", length)); - net->error=1; - net->last_errno=ER_NET_PACKET_TOO_LARGE; + net->error= 1; + net->report_error= 1; + net->last_errno= ER_NET_PACKET_TOO_LARGE; return 1; } pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); @@ -152,9 +154,10 @@ static my_bool net_realloc(NET *net, ulong length) NET_HEADER_SIZE + COMP_HEADER_SIZE, MYF(MY_WME)))) { - net->error=1; + net->error= 1; + net->report_error= 1; #ifdef MYSQL_SERVER - net->last_errno=ER_OUT_OF_RESOURCES; + net->last_errno= ER_OUT_OF_RESOURCES; #endif return 1; } @@ -348,10 +351,12 @@ net_real_write(NET *net,const char *packet,ulong len) COMP_HEADER_SIZE, MYF(MY_WME)))) { #ifdef MYSQL_SERVER - net->last_errno=ER_OUT_OF_RESOURCES; - net->error=2; + net->last_errno= ER_OUT_OF_RESOURCES; + net->error= 2; + //TODO is it needed to set this variable if we have no socket + net->report_error= 1; #endif - net->reading_or_writing=0; + net->reading_or_writing= 0; DBUG_RETURN(1); } memcpy(b+header_length,packet,len); @@ -401,7 +406,8 @@ net_real_write(NET *net,const char *packet,ulong len) "%s: my_net_write: fcntl returned error %d, aborting thread\n", my_progname,vio_errno(net->vio)); #endif /* EXTRA_DEBUG */ - net->error=2; /* Close socket */ + net->error= 2; /* Close socket */ + net->report_error= 1; goto end; } } @@ -428,7 +434,8 @@ net_real_write(NET *net,const char *packet,ulong len) continue; } #endif /* defined(THREAD_SAFE_CLIENT) && !defined(MYSQL_SERVER) */ - net->error=2; /* Close socket */ + net->error= 2; /* Close socket */ + net->report_error= 1; #ifdef MYSQL_SERVER net->last_errno= (interrupted ? ER_NET_WRITE_INTERRUPTED : ER_NET_ERROR_ON_WRITE); @@ -562,9 +569,10 @@ my_real_read(NET *net, ulong *complen) my_progname,vio_errno(net->vio)); #endif /* EXTRA_DEBUG */ len= packet_error; - net->error=2; /* Close socket */ + net->error= 2; /* Close socket */ + net->report_error= 1; #ifdef MYSQL_SERVER - net->last_errno=ER_NET_FCNTL_ERROR; + net->last_errno= ER_NET_FCNTL_ERROR; #endif goto end; } @@ -593,7 +601,8 @@ my_real_read(NET *net, ulong *complen) #endif DBUG_PRINT("error",("Couldn't read packet: remain: %lu errno: %d length: %ld alarmed: %d", remain,vio_errno(net->vio),length,alarmed)); len= packet_error; - net->error=2; /* Close socket */ + net->error= 2; /* Close socket */ + net->report_error= 1; #ifdef MYSQL_SERVER net->last_errno= (interrupted ? ER_NET_READ_INTERRUPTED : ER_NET_READ_ERROR); @@ -622,6 +631,7 @@ my_real_read(NET *net, ulong *complen) #endif } len= packet_error; + net->report_error= 1; #ifdef MYSQL_SERVER net->last_errno=ER_NET_PACKETS_OUT_OF_ORDER; #endif @@ -794,7 +804,8 @@ my_net_read(NET *net) if (my_uncompress((byte*) net->buff + net->where_b, &packet_len, &complen)) { - net->error=2; /* caller will close socket */ + net->error= 2; /* caller will close socket */ + net->report_error= 1; #ifdef MYSQL_SERVER net->last_errno=ER_NET_UNCOMPRESS_ERROR; #endif diff --git a/sql/sql_base.cc b/sql/sql_base.cc index b3ef043f582..95f9e15331f 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1711,7 +1711,8 @@ Field *find_field_in_table(THD *thd,TABLE *table,const char *name,uint length, Field * -find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) +find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables, + bool report_error) { Field *found=0; const char *db=item->db_name; @@ -1748,7 +1749,7 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) } if (found) return found; - if (!found_table) + if (!found_table && report_error) { char buff[NAME_LEN*2+1]; if (db) @@ -1760,8 +1761,9 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) thd->where); } else - my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),MYF(0), - item->full_name(),thd->where); + if (report_error) + my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),MYF(0), + item->full_name(),thd->where); return (Field*) 0; } bool allow_rowid= tables && !tables->next; // Only one table @@ -1778,8 +1780,9 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) { if (!thd->where) // Returns first found break; - my_printf_error(ER_NON_UNIQ_ERROR,ER(ER_NON_UNIQ_ERROR),MYF(0), - name,thd->where); + if (report_error) + my_printf_error(ER_NON_UNIQ_ERROR,ER(ER_NON_UNIQ_ERROR),MYF(0), + name,thd->where); return (Field*) 0; } found=field; @@ -1787,13 +1790,14 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables) } if (found) return found; - my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR), - MYF(0),item->full_name(),thd->where); + if (report_error) + my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), + MYF(0), item->full_name(), thd->where); return (Field*) 0; } Item ** -find_item_in_list(Item *find,List &items) +find_item_in_list(Item *find,List &items, bool report_error) { List_iterator li(items); Item **found=0,*item; @@ -1841,9 +1845,9 @@ find_item_in_list(Item *find,List &items) break; } } - if (!found && current_thd->where) - my_printf_error(ER_BAD_FIELD_ERROR,ER(ER_BAD_FIELD_ERROR),MYF(0), - find->full_name(),current_thd->where); + if (!found && report_error) + my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), + find->full_name(), current_thd->where); return found; } @@ -2303,8 +2307,8 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, int setup_ftfuncs(THD *thd) { - List_iterator li(thd->lex.select->ftfunc_list), - lj(thd->lex.select->ftfunc_list); + List_iterator li(*(thd->lex.select->ftfunc_list)), + lj(*(thd->lex.select->ftfunc_list)); Item_func_match *ftf, *ftf2; while ((ftf=li++)) @@ -2324,9 +2328,9 @@ int setup_ftfuncs(THD *thd) int init_ftfuncs(THD *thd, bool no_order) { - if (thd->lex.select->ftfunc_list.elements) + if (thd->lex.select->ftfunc_list->elements) { - List_iterator li(thd->lex.select->ftfunc_list); + List_iterator li(*(thd->lex.select->ftfunc_list)); Item_func_match *ifm; DBUG_PRINT("info",("Performing FULLTEXT search")); thd->proc_info="FULLTEXT initialization"; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 9922eacdec1..b84bcf1df72 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -407,13 +407,19 @@ bool select_send::send_data(List &items) if (item->send(thd, packet)) { packet->free(); // Free used - my_error(ER_OUT_OF_RESOURCES,MYF(0)); + my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); DBUG_RETURN(1); } } thd->sent_row_count++; - bool error=my_net_write(&thd->net,(char*) packet->ptr(),packet->length()); - DBUG_RETURN(error); + if (!thd->net.report_error) + { + DBUG_RETURN(my_net_write(&thd->net, + (char*) packet->ptr(), + packet->length())); + } + else + DBUG_RETURN(1); } bool select_send::send_eof() @@ -423,8 +429,13 @@ bool select_send::send_eof() { mysql_unlock_tables(thd, thd->lock); thd->lock=0; } - ::send_eof(&thd->net); - return 0; + if (!thd->net.report_error) + { + ::send_eof(&thd->net); + return 0; + } + else + return 1; } @@ -460,7 +471,7 @@ select_export::prepare(List &list, SELECT_LEX_UNIT *u) option); if (!access(path,F_OK)) { - my_error(ER_FILE_EXISTS_ERROR,MYF(0),exchange->file_name); + my_error(ER_FILE_EXISTS_ERROR, MYF(0), exchange->file_name); return 1; } /* Create the file world readable */ @@ -646,9 +657,9 @@ err: } -void select_export::send_error(uint errcode,const char *err) +void select_export::send_error(uint errcode, const char *err) { - ::send_error(&thd->net,errcode,err); + my_message(errcode, err, MYF(0));; (void) end_io_cache(&cache); (void) my_close(file,MYF(0)); file= -1; @@ -660,9 +671,7 @@ bool select_export::send_eof() int error=test(end_io_cache(&cache)); if (my_close(file,MYF(MY_WME))) error=1; - if (error) - ::send_error(&thd->net); - else + if (!error) ::send_ok(&thd->net,row_count); file= -1; return error; @@ -735,7 +744,7 @@ bool select_dump::send_data(List &items) } if (row_count++ > 1) { - my_error(ER_TOO_MANY_ROWS,MYF(0)); + my_error(ER_TOO_MANY_ROWS, MYF(0)); goto err; } while ((item=li++)) @@ -760,7 +769,7 @@ err: void select_dump::send_error(uint errcode,const char *err) { - ::send_error(&thd->net,errcode,err); + my_message(errcode, err, MYF(0)); (void) end_io_cache(&cache); (void) my_close(file,MYF(0)); (void) my_delete(path,MYF(0)); // Delete file on error @@ -772,9 +781,7 @@ bool select_dump::send_eof() int error=test(end_io_cache(&cache)); if (my_close(file,MYF(MY_WME))) error=1; - if (error) - ::send_error(&thd->net); - else + if (!error) ::send_ok(&thd->net,row_count); file= -1; return error; @@ -789,8 +796,9 @@ bool select_singleval_subselect::send_data(List &items) { DBUG_ENTER("select_singleval_subselect::send_data"); Item_singleval_subselect *it= (Item_singleval_subselect *)item; - if (it->assigned){ - my_printf_error(ER_SUBSELECT_NO_1_ROW, ER(ER_SUBSELECT_NO_1_ROW), MYF(0)); + if (it->assigned()){ + thd->fatal_error= 1; + my_message(ER_SUBSELECT_NO_1_ROW, ER(ER_SUBSELECT_NO_1_ROW), MYF(0)); DBUG_RETURN(1); } if (unit->offset_limit_cnt) @@ -816,7 +824,7 @@ bool select_singleval_subselect::send_data(List &items) it->int_value= val_item->val_int(); it->res_type= val_item->result_type(); } - it->assigned= 1; + it->assigned(1); DBUG_RETURN(0); } @@ -830,7 +838,7 @@ bool select_exists_subselect::send_data(List &items) DBUG_RETURN(0); } it->value= 1; - it->assigned= 1; + it->assigned(1); DBUG_RETURN(0); } diff --git a/sql/sql_class.h b/sql/sql_class.h index a6b7e45ab03..82241f0ff1f 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -453,7 +453,7 @@ public: bool query_error, bootstrap, cleanup_done; bool safe_to_cache_query; bool volatile killed; - bool prepare_command; + bool prepare_command; ulong param_count,current_param_number; Error err_list; Error warn_list; @@ -621,7 +621,7 @@ public: virtual void initialize_tables (JOIN *join=0) {} virtual void send_error(uint errcode,const char *err) { - ::send_error(&thd->net,errcode,err); + my_message(errcode, err, MYF(0)); } virtual bool send_eof()=0; virtual void abort() {} diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index fb40a85fd91..cde120f3774 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -99,7 +99,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t) (ORDER*) sl->group_list.first, sl->having, (ORDER*) NULL, sl->options | thd->options | SELECT_NO_UNLOCK, - derived_result, unit); + derived_result, unit, 0); if (!res) { // Here we entirely fix both TABLE_LIST and list of SELECT's as there were no derived tables diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index c3aeca1fff8..ea949e9eb99 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1331,6 +1331,7 @@ bool select_insert::send_data(List &values) void select_insert::send_error(uint errcode,const char *err) { + //TODO error should be sent at the query processing end ::send_error(&thd->net,errcode,err); table->file->extra(HA_EXTRA_NO_CACHE); table->file->activate_all_index(thd); @@ -1357,6 +1358,7 @@ bool select_insert::send_eof() if (error) { table->file->print_error(error,MYF(0)); + //TODO error should be sent at the query processing end ::send_error(&thd->net); return 1; } diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 9ae5cdeeb15..7e6e2524400 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -146,7 +146,8 @@ LEX *lex_start(THD *thd, uchar *buf,uint length) lex->length=0; lex->select->in_sum_expr=0; lex->select->expr_list.empty(); - lex->select->ftfunc_list.empty(); + lex->select->ftfunc_list_alloc.empty(); + lex->select->ftfunc_list= &lex->select->ftfunc_list_alloc; lex->convert_set=(lex->thd=thd)->convert_set; lex->yacc_yyss=lex->yacc_yyvs=0; lex->ignore_space=test(thd->sql_mode & MODE_IGNORE_SPACE); @@ -918,6 +919,8 @@ void st_select_lex_unit::init_query() global_parameters= this; select_limit_cnt= HA_POS_ERROR; offset_limit_cnt= 0; + optimized= 0; + item= 0; } void st_select_lex::init_query() @@ -941,9 +944,11 @@ void st_select_lex::init_select() expr_list.empty(); interval_list.empty(); use_index.empty(); - ftfunc_list.empty(); + ftfunc_list_alloc.empty(); + ftfunc_list= &ftfunc_list_alloc; linkage= UNSPECIFIED_TYPE; depended= having_fix_field= 0; + } /* diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 470230c0999..26b59207f5d 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -216,7 +216,22 @@ private: */ class st_lex; class st_select_lex; +class THD; +class select_result; +class JOIN; +class select_union; class st_select_lex_unit: public st_select_lex_node { +protected: + List item_list; + List joins; /* list of *JOINs, to delete it in cleanup() */ + TABLE_LIST result_table_list; + select_union *union_result; + TABLE *table; /* temporary table using for appending UNION results */ + THD *thd; + select_result *result; + int res; + bool describe, found_rows_for_union, + optimized; // optimize phase already performed for UNION (unit) public: /* Pointer to 'last' select or pointer to unit where stored @@ -225,12 +240,21 @@ public: st_select_lex_node *global_parameters; /* LIMIT clause runtime counters */ ha_rows select_limit_cnt, offset_limit_cnt; + bool depended; /* depended from outer select subselect */ + /* not NULL if union used in subselect, point to subselect item */ + Item_subselect *item; + void init_query(); bool create_total_list(THD *thd, st_lex *lex, TABLE_LIST **result); st_select_lex* outer_select() { return (st_select_lex*) master; } st_select_lex* first_select() { return (st_select_lex*) slave; } st_select_lex_unit* next_unit() { return (st_select_lex_unit*) next; } + /* UNION methods */ + int prepare(THD *thd, select_result *result); + int exec(); + int cleanup(); + friend void mysql_init_query(THD *thd); private: bool create_total_list_n_last_return(THD *thd, st_lex *lex, @@ -241,7 +265,6 @@ typedef struct st_select_lex_unit SELECT_LEX_UNIT; /* SELECT_LEX - store information of parsed SELECT_LEX statment */ -class JOIN; class st_select_lex: public st_select_lex_node { public: char *db, *db1, *table1, *db2, *table2; /* For outer join using .. */ @@ -252,7 +275,12 @@ public: List item_list; /* list of fields & expressions */ List interval_list, use_index, *use_index_ptr, ignore_index, *ignore_index_ptr; - List ftfunc_list; + /* + Usualy it is pointer to ftfunc_list_alloc, but in union used to create fake + select_lex for calling mysql_select under results of union + */ + List *ftfunc_list; + List ftfunc_list_alloc; JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */ uint in_sum_expr; bool create_refs, diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index e006855105c..49a961c1a78 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -665,7 +665,7 @@ pthread_handler_decl(handle_one_connection,arg) if (thd->user_connect) decrease_user_connections(thd->user_connect); free_root(&thd->mem_root,MYF(0)); - if (net->error && net->vio != 0) + if (net->error && net->vio != 0 && net->report_error) { if (!thd->killed && opt_warnings) sql_print_error(ER(ER_NEW_ABORTING_CONNECTION), @@ -1169,6 +1169,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, break; } case COM_PING: + DBUG_PRINT("info", ("query: PING")); thread_safe_increment(com_other,&LOCK_thread_count); send_ok(net); // Tell client we are alive break; @@ -1257,6 +1258,7 @@ mysql_execute_command(void) SELECT_LEX_UNIT *unit= &lex->unit; DBUG_ENTER("mysql_execute_command"); + thd->net.report_error= 0; if (thd->slave_thread) { /* @@ -1864,7 +1866,7 @@ mysql_execute_command(void) (ORDER *)NULL, select_lex->options | thd->options | SELECT_NO_JOIN_CACHE, - result, unit); + result, unit, 0); delete result; } else @@ -2029,13 +2031,13 @@ mysql_execute_command(void) lex->lock_option, table_count))) { - res=mysql_select(thd,tables,select_lex->item_list, - select_lex->where, - (ORDER *)NULL,(ORDER *)NULL,(Item *)NULL, - (ORDER *)NULL, - select_lex->options | thd->options | - SELECT_NO_JOIN_CACHE, - result, unit); + res= mysql_select(thd,tables,select_lex->item_list, + select_lex->where, + (ORDER *)NULL,(ORDER *)NULL,(Item *)NULL, + (ORDER *)NULL, + select_lex->options | thd->options | + SELECT_NO_JOIN_CACHE, + result, unit, 0); delete result; } else diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 76f78009e84..690270d6407 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -178,9 +178,14 @@ int handle_select(THD *thd, LEX *lex, select_result *result) select_lex->having, (ORDER*) lex->proc_list.first, select_lex->options | thd->options, - result, &(lex->unit)); + result, &(lex->unit), 0); if (res && result) result->abort(); + if (res || thd->net.report_error) + { + send_error(&thd->net, 0, MYF(0)); + res= 1; + } delete result; return res; } @@ -198,9 +203,10 @@ int handle_select(THD *thd, LEX *lex, select_result *result) */ int JOIN::prepare(TABLE_LIST *tables_init, - COND *conds_init, ORDER *order_init, ORDER *group_init, - Item *having_init, - ORDER *proc_param_init, SELECT_LEX *select, SELECT_LEX_UNIT *unit) + COND *conds_init, ORDER *order_init, ORDER *group_init, + Item *having_init, + ORDER *proc_param_init, SELECT_LEX *select, + SELECT_LEX_UNIT *unit, bool fake_select_lex) { DBUG_ENTER("JOIN::prepare"); @@ -211,7 +217,8 @@ JOIN::prepare(TABLE_LIST *tables_init, proc_param= proc_param_init; tables_list= tables_init; select_lex= select; - select->join= this; + if (!fake_select_lex) + select->join= this; union_part= (unit->first_select()->next_select() != 0); /* Check that all tables, fields, conds and order are ok */ @@ -231,7 +238,7 @@ JOIN::prepare(TABLE_LIST *tables_init, select_lex->having_fix_field= 1; bool having_fix_rc= having->fix_fields(thd, tables_list, &having); select_lex->having_fix_field= 0; - if (having_fix_rc || thd->fatal_error) + if (having_fix_rc || thd->net.report_error) DBUG_RETURN(-1); /* purecov: inspected */ if (having->with_sum_func) having->split_sum_func(all_fields); @@ -538,7 +545,7 @@ JOIN::optimize() make_join_readinfo(this, (select_options & (SELECT_DESCRIBE | SELECT_NO_JOIN_CACHE)) | - (thd->lex.select->ftfunc_list.elements ? + (thd->lex.select->ftfunc_list->elements ? SELECT_NO_JOIN_CACHE : 0)); /* Need to tell Innobase that to play it safe, it should fetch all @@ -650,16 +657,16 @@ JOIN::exec() result->send_fields(fields_list,1); if (!having || having->val_int()) { - if (do_send_rows && result->send_data(fields_list)) - { - result->send_error(0,NullS); /* purecov: inspected */ - error=1; - } + if (do_send_rows && result->send_data(fields_list)) + { + result->send_error(0,NullS); /* purecov: inspected */ + error= 1; + } else error=(int) result->send_eof(); } else - error=(int) result->send_eof(); + error=(int) result->send_eof(); } delete procedure; DBUG_VOID_RETURN; @@ -995,8 +1002,9 @@ JOIN::cleanup(THD *thd) int mysql_select(THD *thd, TABLE_LIST *tables, List &fields, COND *conds, - ORDER *order, ORDER *group,Item *having, ORDER *proc_param, - ulong select_options, select_result *result, SELECT_LEX_UNIT *unit) + ORDER *order, ORDER *group,Item *having, ORDER *proc_param, + ulong select_options, select_result *result, + SELECT_LEX_UNIT *unit, bool fake_select_lex) { JOIN *join = new JOIN(thd, fields, select_options, result); @@ -1005,7 +1013,7 @@ mysql_select(THD *thd, TABLE_LIST *tables, List &fields, COND *conds, thd->used_tables=0; // Updated by setup_fields if (join->prepare(tables, conds, order, group, having, proc_param, - &(thd->lex.select_lex), unit)) + &(thd->lex.select_lex), unit, fake_select_lex)) { DBUG_RETURN(-1); } @@ -1026,7 +1034,7 @@ err: thd->limit_found_rows = join->send_records; thd->examined_row_count = join->examined_rows; thd->proc_info="end"; - int error= join->cleanup(thd); + int error= (fake_select_lex?0:join->cleanup(thd)) || thd->net.report_error; delete join; DBUG_RETURN(error); } @@ -1760,7 +1768,7 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, add_key_part(keyuse,field); } - if (thd->lex.select->ftfunc_list.elements) + if (thd->lex.select->ftfunc_list->elements) { add_ft_keys(keyuse,join_tab,cond,normal_tables); } @@ -4329,7 +4337,7 @@ do_select(JOIN *join,List *fields,TABLE *table,Procedure *procedure) VOID(table->file->extra(HA_EXTRA_WRITE_CACHE)); empty_record(table); } - join->tmp_table=table; /* Save for easy recursion */ + join->tmp_table= table; /* Save for easy recursion */ join->fields= fields; /* Set up select_end */ @@ -4379,20 +4387,14 @@ do_select(JOIN *join,List *fields,TABLE *table,Procedure *procedure) } else { - error=sub_select(join,join_tab,0); + error= sub_select(join,join_tab,0); if (error >= 0) - error=sub_select(join,join_tab,1); + error= sub_select(join,join_tab,1); if (error == -3) - error=0; /* select_limit used */ + error= 0; /* select_limit used */ } - /* Return 1 if error is sent; -1 if error should be sent */ - if (error < 0) - { - join->result->send_error(0,NullS); /* purecov: inspected */ - error=1; // Error sent - } - else + if (error >= 0) { error=0; if (!table) // If sending data to client @@ -6445,10 +6447,7 @@ find_order_in_list(THD *thd,TABLE_LIST *tables,ORDER *order,List &fields, order->in_field_list=1; return 0; } - const char *save_where=thd->where; - thd->where=0; // No error if not found - Item **item=find_item_in_list(*order->item,fields); - thd->where=save_where; + Item **item=find_item_in_list(*order->item, fields, 0); if (item) { order->item=item; // use it @@ -6546,17 +6545,15 @@ setup_new_fields(THD *thd,TABLE_LIST *tables,List &fields, DBUG_ENTER("setup_new_fields"); thd->set_query_id=1; // Not really needed, but... - thd->where=0; // Don't give error for ( ; new_field ; new_field=new_field->next) { - if ((item=find_item_in_list(*new_field->item,fields))) + if ((item=find_item_in_list(*new_field->item, fields, 0))) new_field->item=item; /* Change to shared Item */ else { thd->where="procedure list"; if ((*new_field->item)->fix_fields(thd, tables, new_field->item)) DBUG_RETURN(1); /* purecov: inspected */ - thd->where=0; all_fields.push_front(*new_field->item); new_field->item=all_fields.head_ref(); } diff --git a/sql/sql_select.h b/sql/sql_select.h index 3062747a08f..0f7e08d268e 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -209,6 +209,7 @@ class JOIN :public Sql_alloc{ send_records(0), found_records(0), examined_rows(0), thd(thd), sum_funcs(0), + procedure(0), having(0), select_options(select_options), result(result), @@ -235,7 +236,8 @@ class JOIN :public Sql_alloc{ int prepare(TABLE_LIST *tables, COND *conds, ORDER *order, ORDER *group, Item *having, - ORDER *proc_param, SELECT_LEX *select, SELECT_LEX_UNIT *unit); + ORDER *proc_param, SELECT_LEX *select, SELECT_LEX_UNIT *unit, + bool fake_select_lex); int optimize(); int global_optimize(); int reinit(); diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 0eea10e068a..e8ee3582135 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -24,160 +24,14 @@ #include "mysql_priv.h" #include "sql_select.h" - -int mysql_union(THD *thd, LEX *lex,select_result *result) +int mysql_union(THD *thd, LEX *lex, select_result *result) { - SELECT_LEX *sl; - SELECT_LEX_UNIT *unit= &(lex->unit); - List item_list; - TABLE *table; - int describe=(lex->select_lex.options & SELECT_DESCRIBE) ? 1 : 0; - int res; - bool found_rows_for_union=false; - TABLE_LIST result_table_list; - TMP_TABLE_PARAM tmp_table_param; - select_union *union_result; DBUG_ENTER("mysql_union"); - st_select_lex_node * global; - - /* Global option */ - if (((void*)(global= unit->global_parameters)) == ((void*)unit)) - { - found_rows_for_union = lex->select_lex.options & OPTION_FOUND_ROWS && - !describe && global->select_limit; - if (found_rows_for_union) - lex->select_lex.options ^= OPTION_FOUND_ROWS; - } - - if (describe) - { - Item *item; - item_list.push_back(new Item_empty_string("table",NAME_LEN)); - item_list.push_back(new Item_empty_string("type",10)); - item_list.push_back(item=new Item_empty_string("possible_keys", - NAME_LEN*MAX_KEY)); - item->maybe_null=1; - item_list.push_back(item=new Item_empty_string("key",NAME_LEN)); - item->maybe_null=1; - item_list.push_back(item=new Item_int("key_len",0,3)); - item->maybe_null=1; - item_list.push_back(item=new Item_empty_string("ref", - NAME_LEN*MAX_REF_PARTS)); - item->maybe_null=1; - item_list.push_back(new Item_real("rows",0.0,0,10)); - item_list.push_back(new Item_empty_string("Extra",255)); - } - else - { - Item *item; - List_iterator it(lex->select_lex.item_list); - TABLE_LIST *first_table= (TABLE_LIST*) lex->select_lex.table_list.first; - - /* Create a list of items that will be in the result set */ - while ((item= it++)) - if (item_list.push_back(item)) - DBUG_RETURN(-1); - if (setup_fields(thd,first_table,item_list,0,0,1)) - DBUG_RETURN(-1); - } - - bzero((char*) &tmp_table_param,sizeof(tmp_table_param)); - tmp_table_param.field_count=item_list.elements; - if (!(table= create_tmp_table(thd, &tmp_table_param, item_list, - (ORDER*) 0, !describe & !lex->union_option, - 1, 0, - (lex->select_lex.options | thd->options | - TMP_TABLE_ALL_COLUMNS), - unit))) - DBUG_RETURN(-1); - table->file->extra(HA_EXTRA_WRITE_CACHE); - table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); - bzero((char*) &result_table_list,sizeof(result_table_list)); - result_table_list.db= (char*) ""; - result_table_list.real_name=result_table_list.name=(char*) "union"; - result_table_list.table=table; - - if (!(union_result=new select_union(table))) - { - res= -1; - goto exit; - } - union_result->save_time_stamp=!describe; - union_result->tmp_table_param=&tmp_table_param; - for (sl= &lex->select_lex; sl; sl= sl->next_select()) - { - lex->select=sl; - unit->offset_limit_cnt= sl->offset_limit; - unit->select_limit_cnt= sl->select_limit+sl->offset_limit; - if (unit->select_limit_cnt < sl->select_limit) - unit->select_limit_cnt= HA_POS_ERROR; // no limit - if (unit->select_limit_cnt == HA_POS_ERROR) - sl->options&= ~OPTION_FOUND_ROWS; - - res= mysql_select(thd, - (TABLE_LIST*) sl->table_list.first, - sl->item_list, - sl->where, - (sl->braces) ? - (ORDER *)sl->order_list.first : (ORDER *) 0, - (ORDER*) sl->group_list.first, - sl->having, - (ORDER*) NULL, - sl->options | thd->options | - SELECT_NO_UNLOCK | ((describe) ? SELECT_DESCRIBE : 0), - union_result, unit); - if (res) - goto exit; - } - if (union_result->flush()) - { - res= 1; // Error is already sent - goto exit; - } - delete union_result; - - /* Send result to 'result' */ - lex->select = &lex->select_lex; - res =-1; - { - /* Create a list of fields in the temporary table */ - List_iterator it(item_list); - Field **field; -#if 0 - List ftfunc_list; - ftfunc_list.empty(); -#else - thd->lex.select_lex.ftfunc_list.empty(); -#endif - - for (field=table->field ; *field ; field++) - { - (void) it++; - (void) it.replace(new Item_field(*field)); - } - if (!thd->fatal_error) // Check if EOM - { - st_select_lex_node * global= unit->global_parameters; - unit->offset_limit_cnt= global->offset_limit; - unit->select_limit_cnt= global->select_limit+global->offset_limit; - if (unit->select_limit_cnt < global->select_limit) - unit->select_limit_cnt= HA_POS_ERROR; // no limit - if (unit->select_limit_cnt == HA_POS_ERROR) - thd->options&= ~OPTION_FOUND_ROWS; - if (describe) - unit->select_limit_cnt= HA_POS_ERROR; // no limit - res= mysql_select(thd,&result_table_list, - item_list, NULL, - (describe) ? 0 : (ORDER*)global->order_list.first, - (ORDER*) NULL, NULL, (ORDER*) NULL, - thd->options, result, unit); - if (found_rows_for_union && !res) - thd->limit_found_rows = (ulonglong)table->file->records; - } - } - -exit: - free_tmp_table(thd,table); + SELECT_LEX_UNIT *unit= &lex->unit; + int res= 0; + if (!(res= unit->prepare(thd, result))) + res= unit->exec(); + res|= unit->cleanup(); DBUG_RETURN(res); } @@ -246,3 +100,213 @@ bool select_union::flush() } return 0; } + +typedef JOIN * JOIN_P; +int st_select_lex_unit::prepare(THD *thd, select_result *result) +{ + describe=(first_select()->options & SELECT_DESCRIBE) ? 1 : 0; + res= 0; + found_rows_for_union= false; + TMP_TABLE_PARAM tmp_table_param; + DBUG_ENTER("st_select_lex_unit::prepare"); + this->thd= thd; + this->result= result; + + /* Global option */ + if (((void*)(global_parameters)) == ((void*)this)) + { + found_rows_for_union = first_select()->options & OPTION_FOUND_ROWS && + !describe && global_parameters->select_limit; + if (found_rows_for_union) + first_select()->options ^= OPTION_FOUND_ROWS; + } + item_list.empty(); + if (describe) + { + Item *item; + item_list.push_back(new Item_empty_string("table",NAME_LEN)); + item_list.push_back(new Item_empty_string("type",10)); + item_list.push_back(item=new Item_empty_string("possible_keys", + NAME_LEN*MAX_KEY)); + item->maybe_null=1; + item_list.push_back(item=new Item_empty_string("key",NAME_LEN)); + item->maybe_null=1; + item_list.push_back(item=new Item_int("key_len",0,3)); + item->maybe_null=1; + item_list.push_back(item=new Item_empty_string("ref", + NAME_LEN*MAX_REF_PARTS)); + item->maybe_null=1; + item_list.push_back(new Item_real("rows",0.0,0,10)); + item_list.push_back(new Item_empty_string("Extra",255)); + } + else + { + Item *item; + List_iterator it(first_select()->item_list); + TABLE_LIST *first_table= (TABLE_LIST*) first_select()->table_list.first; + + /* Create a list of items that will be in the result set */ + while ((item= it++)) + if (item_list.push_back(item)) + DBUG_RETURN(-1); + if (setup_fields(thd,first_table,item_list,0,0,1)) + DBUG_RETURN(-1); + } + + bzero((char*) &tmp_table_param,sizeof(tmp_table_param)); + tmp_table_param.field_count=item_list.elements; + if (!(table= create_tmp_table(thd, &tmp_table_param, item_list, + (ORDER*) 0, !describe & + !thd->lex.union_option, + 1, 0, + (first_select()->options | thd->options | + TMP_TABLE_ALL_COLUMNS), + this))) + DBUG_RETURN(-1); + table->file->extra(HA_EXTRA_WRITE_CACHE); + table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); + bzero((char*) &result_table_list,sizeof(result_table_list)); + result_table_list.db= (char*) ""; + result_table_list.real_name=result_table_list.name=(char*) "union"; + result_table_list.table=table; + + if (!(union_result=new select_union(table))) + DBUG_RETURN(-1); + + union_result->save_time_stamp=!describe; + union_result->tmp_table_param=&tmp_table_param; + + // prepare selects + joins.empty(); + for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select()) + { + JOIN *join= new JOIN(thd, sl->item_list, + sl->options | thd->options | SELECT_NO_UNLOCK | + ((describe) ? SELECT_DESCRIBE : 0), + union_result); + joins.push_back(new JOIN_P(join)); + thd->lex.select=sl; + offset_limit_cnt= sl->offset_limit; + select_limit_cnt= sl->select_limit+sl->offset_limit; + if (select_limit_cnt < sl->select_limit) + select_limit_cnt= HA_POS_ERROR; // no limit + if (select_limit_cnt == HA_POS_ERROR) + sl->options&= ~OPTION_FOUND_ROWS; + + res= join->prepare((TABLE_LIST*) sl->table_list.first, + sl->where, + (sl->braces) ? + (ORDER *)sl->order_list.first : (ORDER *) 0, + (ORDER*) sl->group_list.first, + sl->having, + (ORDER*) NULL, + sl, this, 0); + if (res | thd->fatal_error) + DBUG_RETURN(res | thd->fatal_error); + } + DBUG_RETURN(res | thd->fatal_error); +} + +int st_select_lex_unit::exec() +{ + DBUG_ENTER("st_select_lex_unit::exec"); + if(depended || !item || !item->assigned()) + { + if (optimized && item && item->assigned()) + item->assigned(0); // We will reinit & rexecute unit + + for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select()) + { + thd->lex.select=sl; + offset_limit_cnt= sl->offset_limit; + select_limit_cnt= sl->select_limit+sl->offset_limit; + if (select_limit_cnt < sl->select_limit) + select_limit_cnt= HA_POS_ERROR; // no limit + if (select_limit_cnt == HA_POS_ERROR) + sl->options&= ~OPTION_FOUND_ROWS; + + if (!optimized) + sl->join->optimize(); + else + sl->join->reinit(); + + sl->join->exec(); + res= sl->join->error; + + if (res) + DBUG_RETURN(res); + } + optimized= 1; + } + + if (union_result->flush()) + { + res= 1; // Error is already sent + DBUG_RETURN(res); + } + + /* Send result to 'result' */ + thd->lex.select = first_select(); + res =-1; + { + /* Create a list of fields in the temporary table */ + List_iterator it(item_list); + Field **field; +#if 0 + List ftfunc_list; + ftfunc_list.empty(); +#else + List empty_list; + empty_list.empty(); + thd->lex.select_lex.ftfunc_list= &empty_list; +#endif + + for (field=table->field ; *field ; field++) + { + (void) it++; + (void) it.replace(new Item_field(*field)); + } + if (!thd->fatal_error) // Check if EOM + { + offset_limit_cnt= global_parameters->offset_limit; + select_limit_cnt= global_parameters->select_limit+ + global_parameters->offset_limit; + if (select_limit_cnt < global_parameters->select_limit) + select_limit_cnt= HA_POS_ERROR; // no limit + if (select_limit_cnt == HA_POS_ERROR) + thd->options&= ~OPTION_FOUND_ROWS; + if (describe) + select_limit_cnt= HA_POS_ERROR; // no limit + res= mysql_select(thd,&result_table_list, + item_list, NULL, + (describe) ? + 0: + (ORDER*)global_parameters->order_list.first, + (ORDER*) NULL, NULL, (ORDER*) NULL, + thd->options, result, this, 1); + if (found_rows_for_union && !res) + thd->limit_found_rows = (ulonglong)table->file->records; + } + } + thd->lex.select_lex.ftfunc_list= &thd->lex.select_lex.ftfunc_list_alloc; + DBUG_RETURN(res); +} + +int st_select_lex_unit::cleanup() +{ + DBUG_ENTER("st_select_lex_unit::cleanup"); + delete union_result; + free_tmp_table(thd,table); + table= 0; // Safety + + List_iterator j(joins); + JOIN** join; + while ((join= j++)) + { + (*join)->cleanup(thd); + delete *join; + delete join; + } + joins.empty(); + DBUG_RETURN(0); +} diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 51453f955e8..9ea8f725947 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -642,6 +642,8 @@ bool multi_update::send_data(List &values) void multi_update::send_error(uint errcode,const char *err) { + + //TODO error should be sent at the query processing end /* First send error what ever it is ... */ ::send_error(&thd->net,errcode,err); @@ -766,6 +768,7 @@ bool multi_update::send_eof() if (error == -1) error = 0; thd->proc_info="end"; + //TODO error should be sent at the query processing end if (error) send_error(error,"An error occured in multi-table update"); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 160bc253dc9..b762388d9be 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1763,10 +1763,10 @@ simple_expr: | singleval_subselect { $$= $1; } | '{' ident expr '}' { $$= $3; } | MATCH ident_list_arg AGAINST '(' expr ')' - { Select->ftfunc_list.push_back((Item_func_match *) + { Select->ftfunc_list->push_back((Item_func_match *) ($$=new Item_func_match_nl(*$2,$5))); } | MATCH ident_list_arg AGAINST '(' expr IN_SYM BOOLEAN_SYM MODE_SYM ')' - { Select->ftfunc_list.push_back((Item_func_match *) + { Select->ftfunc_list->push_back((Item_func_match *) ($$=new Item_func_match_bool(*$2,$5))); } | BINARY expr %prec NEG { $$= new Item_func_binary($2); } | CAST_SYM '(' expr AS cast_type ')' { $$= create_func_cast($3, $5); } @@ -3999,7 +3999,8 @@ singleval_subselect: singleval_subselect_init: select_init { - $$= new Item_singleval_subselect(current_thd, Lex->select); + $$= new Item_singleval_subselect(current_thd, + Lex->select->master_unit()->first_select()); }; exists_subselect: @@ -4012,7 +4013,8 @@ exists_subselect: exists_subselect_init: select_init { - $$= new Item_exists_subselect(current_thd, Lex->select); + $$= new Item_exists_subselect(current_thd, + Lex->select->master_unit()->first_select()); }; subselect_start: From 9396cc5a4a063f2cccd83721932abb98ce238459 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Sep 2002 23:08:22 +0300 Subject: [PATCH 2/6] new EXPLAIN fixed bug in mysql-test/create-test-result fixed bug in union-subselect engine mysql-test/create-test-result: fixed bug in reject file name assembling mysql-test/r/compare.result: new EXPLAIN mysql-test/r/create.result: new EXPLAIN mysql-test/r/distinct.result: new EXPLAIN mysql-test/r/explain.result: new EXPLAIN mysql-test/r/group_by.result: new EXPLAIN mysql-test/r/heap.result: new EXPLAIN mysql-test/r/heap_btree.result: new EXPLAIN mysql-test/r/heap_hash.result: new EXPLAIN mysql-test/r/innodb.result: new EXPLAIN mysql-test/r/join_outer.result: new EXPLAIN mysql-test/r/key_diff.result: new EXPLAIN mysql-test/r/key_primary.result: new EXPLAIN mysql-test/r/merge.result: new EXPLAIN mysql-test/r/myisam.result: new EXPLAIN mysql-test/r/null_key.result: new EXPLAIN mysql-test/r/odbc.result: new EXPLAIN mysql-test/r/order_by.result: new EXPLAIN mysql-test/r/range.result: new EXPLAIN mysql-test/r/select.result: new EXPLAIN mysql-test/r/subselect.result: new EXPLAIN mysql-test/r/type_datetime.result: new EXPLAIN mysql-test/r/union.result: new EXPLAIN mysql-test/r/user_var.result: new EXPLAIN mysql-test/r/varbinary.result: new EXPLAIN mysql-test/t/subselect.test: new EXPLAIN mysql-test/t/union.test: new EXPLAIN sql/mysql_priv.h: new EXPLAIN sql/sql_class.cc: new EXPLAIN sql/sql_class.h: new EXPLAIN sql/sql_derived.cc: new EXPLAIN sql/sql_lex.h: new EXPLAIN sql/sql_parse.cc: new EXPLAIN sql/sql_select.cc: new EXPLAIN sql/sql_union.cc: fixed bug in subselect-UNION engine sql/table.h: new EXPLAIN --- mysql-test/create-test-result | 3 +- mysql-test/r/compare.result | 4 +- mysql-test/r/create.result | 4 +- mysql-test/r/distinct.result | 30 +++--- mysql-test/r/explain.result | 20 ++-- mysql-test/r/group_by.result | 20 ++-- mysql-test/r/heap.result | 30 +++--- mysql-test/r/heap_btree.result | 42 ++++---- mysql-test/r/heap_hash.result | 30 +++--- mysql-test/r/innodb.result | 52 +++++----- mysql-test/r/join_outer.result | 46 ++++----- mysql-test/r/key_diff.result | 6 +- mysql-test/r/key_primary.result | 8 +- mysql-test/r/merge.result | 12 +-- mysql-test/r/myisam.result | 32 +++---- mysql-test/r/null_key.result | 104 ++++++++++---------- mysql-test/r/odbc.result | 4 +- mysql-test/r/order_by.result | 98 +++++++++---------- mysql-test/r/range.result | 4 +- mysql-test/r/select.result | 74 +++++++-------- mysql-test/r/subselect.result | 23 +++++ mysql-test/r/type_datetime.result | 4 +- mysql-test/r/union.result | 38 ++++---- mysql-test/r/user_var.result | 16 ++-- mysql-test/r/varbinary.result | 4 +- mysql-test/t/subselect.test | 6 ++ mysql-test/t/union.test | 2 +- sql/mysql_priv.h | 9 +- sql/sql_class.cc | 22 +++++ sql/sql_class.h | 3 + sql/sql_derived.cc | 23 +++-- sql/sql_lex.h | 4 +- sql/sql_parse.cc | 108 +++++++++++++++++++-- sql/sql_select.cc | 153 ++++++++++++++---------------- sql/sql_union.cc | 23 +++-- sql/table.h | 3 + 36 files changed, 607 insertions(+), 457 deletions(-) diff --git a/mysql-test/create-test-result b/mysql-test/create-test-result index a50b4c87641..b9be2300976 100755 --- a/mysql-test/create-test-result +++ b/mysql-test/create-test-result @@ -27,6 +27,7 @@ test_name=$1 [ -z $test_name ] && usage result_file=$RESULT_DIR/$test_name.result +reject_file=$RESULT_DIR/$test_name.reject [ -f $result_file ] && die "result file $result_file has already been created" @@ -34,8 +35,6 @@ touch $result_file echo "Running the test case against empty file, will fail, but don't worry" ./mysql-test-run --local $test_name -reject_file=$result_file.reject - if [ -f $reject_file ] ; then echo "Below are the contents of the reject file:" echo "-----start---------------------" diff --git a/mysql-test/r/compare.result b/mysql-test/r/compare.result index 07f9ce4e81a..be11de8ebb9 100644 --- a/mysql-test/r/compare.result +++ b/mysql-test/r/compare.result @@ -2,8 +2,8 @@ drop table if exists t1; CREATE TABLE t1 (id CHAR(12) not null, PRIMARY KEY (id)); insert into t1 values ('000000000001'),('000000000002'); explain select * from t1 where id=000000000001; -table type possible_keys key key_len ref rows Extra -t1 index PRIMARY PRIMARY 12 NULL 2 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index PRIMARY PRIMARY 12 NULL 2 where used; Using index select * from t1 where id=000000000001; id 000000000001 diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index f9a3ef487f0..41a977695a6 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -62,8 +62,8 @@ create table t1 (a int auto_increment not null primary key, B CHAR(20)); insert into t1 (b) values ("hello"),("my"),("world"); create table t2 (key (b)) select * from t1; explain select * from t2 where b="world"; -table type possible_keys key key_len ref rows Extra -t2 ref B B 21 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 ref B B 21 const 1 where used select * from t2 where b="world"; a B 3 world diff --git a/mysql-test/r/distinct.result b/mysql-test/r/distinct.result index 89f4a8ae7f2..d8386ddcfc3 100644 --- a/mysql-test/r/distinct.result +++ b/mysql-test/r/distinct.result @@ -172,10 +172,10 @@ b INSERT INTO t2 values (1),(2),(3); INSERT INTO t3 VALUES (1,'1'),(2,'2'),(1,'1'),(2,'2'); explain SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a; -table type possible_keys key key_len ref rows Extra -t3 index a a 5 NULL 6 Using index; Using temporary -t2 index a a 4 NULL 5 Using index; Distinct -t1 eq_ref PRIMARY PRIMARY 4 t2.a 1 where used; Distinct +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t3 index a a 5 NULL 6 Using index; Using temporary +1 FIRST t2 index a a 4 NULL 5 Using index; Distinct +1 FIRST t1 eq_ref PRIMARY PRIMARY 4 t2.a 1 where used; Distinct SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a; a 1 @@ -188,9 +188,9 @@ insert into t3 select * from t4; insert into t4 select * from t3; insert into t3 select * from t4; explain select distinct t1.a from t1,t3 where t1.a=t3.a; -table type possible_keys key key_len ref rows Extra -t1 index PRIMARY PRIMARY 4 NULL 2 Using index; Using temporary -t3 ref a a 5 t1.a 10 Using index; Distinct +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index PRIMARY PRIMARY 4 NULL 2 Using index; Using temporary +1 FIRST t3 ref a a 5 t1.a 10 Using index; Distinct select distinct t1.a from t1,t3 where t1.a=t3.a; a 1 @@ -274,14 +274,14 @@ on j_lj_t3.id=t3_lj.id WHERE ((t1.id=j_lj_t2.id AND t2_lj.id IS NULL) OR (t1.id=t2.id AND t2.idx=2)) AND ((t1.id=j_lj_t3.id AND t3_lj.id IS NULL) OR (t1.id=t3.id AND t3.idx=2)); -table type possible_keys key key_len ref rows Extra -t1 index id id 4 NULL 2 Using index; Using temporary -t2 index id id 8 NULL 1 Using index; Distinct -t3 index id id 8 NULL 1 Using index; Distinct -j_lj_t2 index id id 4 NULL 2 where used; Using index; Distinct -t2_lj index id id 8 NULL 1 where used; Using index; Distinct -j_lj_t3 index id id 4 NULL 2 where used; Using index; Distinct -t3_lj index id id 8 NULL 1 where used; Using index; Distinct +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index id id 4 NULL 2 Using index; Using temporary +1 FIRST t2 index id id 8 NULL 1 Using index; Distinct +1 FIRST t3 index id id 8 NULL 1 Using index; Distinct +1 FIRST j_lj_t2 index id id 4 NULL 2 where used; Using index; Distinct +1 FIRST t2_lj index id id 8 NULL 1 where used; Using index; Distinct +1 FIRST j_lj_t3 index id id 4 NULL 2 where used; Using index; Distinct +1 FIRST t3_lj index id id 8 NULL 1 where used; Using index; Distinct SELECT DISTINCT t1.id from diff --git a/mysql-test/r/explain.result b/mysql-test/r/explain.result index 5b4da25d535..cd0ddeae120 100644 --- a/mysql-test/r/explain.result +++ b/mysql-test/r/explain.result @@ -9,22 +9,22 @@ select * from t1 where str="foo"; id str 3 foo explain select * from t1 where str is null; -table type possible_keys key key_len ref rows Extra -t1 ref str str 11 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref str str 11 const 1 where used explain select * from t1 where str="foo"; -table type possible_keys key key_len ref rows Extra -t1 const str str 11 const 1 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 const str str 11 const 1 explain select * from t1 ignore key (str) where str="foo"; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 where used explain select * from t1 use key (str,str) where str="foo"; -table type possible_keys key key_len ref rows Extra -t1 const str str 11 const 1 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 const str str 11 const 1 explain select * from t1 use key (str,str,foo) where str="foo"; Key column 'foo' doesn't exist in table explain select * from t1 ignore key (str,str,foo) where str="foo"; Key column 'foo' doesn't exist in table drop table t1; explain select 1; -Comment -No tables used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST No tables used diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index aaa03f2668a..0781468bc97 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -225,19 +225,19 @@ key (score) ); INSERT INTO t1 VALUES (1,1,1),(2,2,2),(2,1,1),(3,3,3),(4,3,3),(5,3,3); explain select userid,count(*) from t1 group by userid desc; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort select userid,count(*) from t1 group by userid desc; userid count(*) 3 3 2 1 1 2 explain select spid,count(*) from t1 where spid between 1 and 2 group by spid desc; -table type possible_keys key key_len ref rows Extra -t1 range spID spID 5 NULL 2 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range spID spID 5 NULL 2 where used; Using index explain select spid,count(*) from t1 where spid between 1 and 2 group by spid; -table type possible_keys key key_len ref rows Extra -t1 range spID spID 5 NULL 2 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range spID spID 5 NULL 2 where used; Using index select spid,count(*) from t1 where spid between 1 and 2 group by spid; spid count(*) 1 1 @@ -247,8 +247,8 @@ spid count(*) 2 2 1 1 explain select sql_big_result spid,sum(userid) from t1 group by spid desc; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 6 Using filesort +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 6 Using filesort select sql_big_result spid,sum(userid) from t1 group by spid desc; spid sum(userid) 5 3 @@ -257,8 +257,8 @@ spid sum(userid) 2 3 1 1 explain select sql_big_result score,count(*) from t1 group by score desc; -table type possible_keys key key_len ref rows Extra -t1 index NULL score 3 NULL 6 Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL score 3 NULL 6 Using index select sql_big_result score,count(*) from t1 group by score desc; score count(*) 3 3 diff --git a/mysql-test/r/heap.result b/mysql-test/r/heap.result index eb3bae0fea2..94fac7757ac 100644 --- a/mysql-test/r/heap.result +++ b/mysql-test/r/heap.result @@ -65,8 +65,8 @@ a 869751 alter table t1 type=myisam; explain select * from t1 where a in (869751,736494,226312,802616); -table type possible_keys key key_len ref rows Extra -t1 range uniq_id uniq_id 4 NULL 4 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range uniq_id uniq_id 4 NULL 4 where used; Using index drop table t1; create table t1 (x int not null, y int not null, key x (x), unique y (y)) type=heap; @@ -84,9 +84,9 @@ x y x y 2 5 2 2 2 6 2 2 explain select * from t1,t1 as t2 where t1.x=t2.y; -table type possible_keys key key_len ref rows Extra -t1 ALL x NULL NULL NULL 6 -t2 eq_ref y y 4 t1.x 1 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL x NULL NULL NULL 6 +1 FIRST t2 eq_ref y y 4 t1.x 1 drop table t1; create table t1 (a int) type=heap; insert into t1 values(1); @@ -158,18 +158,18 @@ drop table t1; create table t1 (btn char(10) not null, key(btn)) type=heap; insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); explain select * from t1 where btn like "q%"; -table type possible_keys key key_len ref rows Extra -t1 ALL btn NULL NULL NULL 14 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL btn NULL NULL NULL 14 where used select * from t1 where btn like "q%"; btn alter table t1 add column new_col char(1) not null, add key (btn,new_col), drop key btn; update t1 set new_col=btn; explain select * from t1 where btn="a"; -table type possible_keys key key_len ref rows Extra -t1 ALL btn NULL NULL NULL 14 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL btn NULL NULL NULL 14 where used explain select * from t1 where btn="a" and new_col="a"; -table type possible_keys key key_len ref rows Extra -t1 ref btn btn 11 const,const 10 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref btn btn 11 const,const 10 where used drop table t1; CREATE TABLE t1 ( a int default NULL, @@ -181,16 +181,16 @@ INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3); SELECT * FROM t1 WHERE a=NULL; a b explain SELECT * FROM t1 WHERE a IS NULL; -table type possible_keys key key_len ref rows Extra -t1 ref a a 5 const 10 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a a 5 const 10 where used SELECT * FROM t1 WHERE a<=>NULL; a b NULL 99 SELECT * FROM t1 WHERE b=NULL; a b explain SELECT * FROM t1 WHERE b IS NULL; -table type possible_keys key key_len ref rows Extra -t1 ref b b 5 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref b b 5 const 1 where used SELECT * FROM t1 WHERE b<=>NULL; a b 99 NULL diff --git a/mysql-test/r/heap_btree.result b/mysql-test/r/heap_btree.result index c3080389999..5a8289a16f7 100644 --- a/mysql-test/r/heap_btree.result +++ b/mysql-test/r/heap_btree.result @@ -65,8 +65,8 @@ a 869751 alter table t1 type=myisam; explain select * from t1 where a in (869751,736494,226312,802616); -table type possible_keys key key_len ref rows Extra -t1 range uniq_id uniq_id 4 NULL 4 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range uniq_id uniq_id 4 NULL 4 where used; Using index drop table t1; create table t1 (x int not null, y int not null, key x using BTREE (x), unique y using BTREE (y)) type=heap; @@ -84,9 +84,9 @@ x y x y 2 5 2 2 2 6 2 2 explain select * from t1,t1 as t2 where t1.x=t2.y; -table type possible_keys key key_len ref rows Extra -t1 ALL x NULL NULL NULL 6 -t2 eq_ref y y 4 t1.x 1 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL x NULL NULL NULL 6 +1 FIRST t2 eq_ref y y 4 t1.x 1 drop table t1; create table t1 (a int) type=heap; insert into t1 values(1); @@ -120,18 +120,18 @@ a b 1 6 1 6 explain select * from tx where a=x order by a,b; -table type possible_keys key key_len ref rows Extra -tx ref a a x const x where used +id select_type table type possible_keys key key_len ref rows Extra +x FIRST tx ref a a x const x where used explain select * from tx where a=x order by b; -table type possible_keys key key_len ref rows Extra -tx ref a a x const x where used +id select_type table type possible_keys key key_len ref rows Extra +x FIRST tx ref a a x const x where used select * from t1 where b=1; a b 1 1 1 1 explain select * from tx where b=x; -table type possible_keys key key_len ref rows Extra -tx ref b b x const x where used +id select_type table type possible_keys key key_len ref rows Extra +x FIRST tx ref b b x const x where used drop table t1; create table t1 (id int unsigned not null, primary key using BTREE (id)) type=HEAP; insert into t1 values(1); @@ -171,18 +171,18 @@ drop table t1; create table t1 (btn char(10) not null, key using BTREE (btn)) type=heap; insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); explain select * from t1 where btn like "q%"; -table type possible_keys key key_len ref rows Extra -t1 ALL btn NULL NULL NULL 14 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL btn NULL NULL NULL 14 where used select * from t1 where btn like "q%"; btn alter table t1 add column new_col char(1) not null, add key using BTREE (btn,new_col), drop key btn; update t1 set new_col=btn; explain select * from t1 where btn="a"; -table type possible_keys key key_len ref rows Extra -t1 ref btn btn 10 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref btn btn 10 const 1 where used explain select * from t1 where btn="a" and new_col="a"; -table type possible_keys key key_len ref rows Extra -t1 ref btn btn 11 const,const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref btn btn 11 const,const 1 where used drop table t1; CREATE TABLE t1 ( a int default NULL, @@ -194,16 +194,16 @@ INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3); SELECT * FROM t1 WHERE a=NULL; a b explain SELECT * FROM t1 WHERE a IS NULL; -table type possible_keys key key_len ref rows Extra -t1 ref a a 5 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a a 5 const 1 where used SELECT * FROM t1 WHERE a<=>NULL; a b NULL 99 SELECT * FROM t1 WHERE b=NULL; a b explain SELECT * FROM t1 WHERE b IS NULL; -table type possible_keys key key_len ref rows Extra -t1 ref b b 5 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref b b 5 const 1 where used SELECT * FROM t1 WHERE b<=>NULL; a b 99 NULL diff --git a/mysql-test/r/heap_hash.result b/mysql-test/r/heap_hash.result index 9b7f2cca6bc..4dd79e5c52b 100644 --- a/mysql-test/r/heap_hash.result +++ b/mysql-test/r/heap_hash.result @@ -65,8 +65,8 @@ a 869751 alter table t1 type=myisam; explain select * from t1 where a in (869751,736494,226312,802616); -table type possible_keys key key_len ref rows Extra -t1 range uniq_id uniq_id 4 NULL 4 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range uniq_id uniq_id 4 NULL 4 where used; Using index drop table t1; create table t1 (x int not null, y int not null, key x using HASH (x), unique y using HASH (y)) type=heap; @@ -84,9 +84,9 @@ x y x y 2 5 2 2 2 6 2 2 explain select * from t1,t1 as t2 where t1.x=t2.y; -table type possible_keys key key_len ref rows Extra -t1 ALL x NULL NULL NULL 6 -t2 eq_ref y y 4 t1.x 1 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL x NULL NULL NULL 6 +1 FIRST t2 eq_ref y y 4 t1.x 1 drop table t1; create table t1 (a int) type=heap; insert into t1 values(1); @@ -158,18 +158,18 @@ drop table t1; create table t1 (btn char(10) not null, key using HASH (btn)) type=heap; insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); explain select * from t1 where btn like "q%"; -table type possible_keys key key_len ref rows Extra -t1 ALL btn NULL NULL NULL 14 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL btn NULL NULL NULL 14 where used select * from t1 where btn like "q%"; btn alter table t1 add column new_col char(1) not null, add key using HASH (btn,new_col), drop key btn; update t1 set new_col=btn; explain select * from t1 where btn="a"; -table type possible_keys key key_len ref rows Extra -t1 ALL btn NULL NULL NULL 14 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL btn NULL NULL NULL 14 where used explain select * from t1 where btn="a" and new_col="a"; -table type possible_keys key key_len ref rows Extra -t1 ref btn btn 11 const,const 10 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref btn btn 11 const,const 10 where used drop table t1; CREATE TABLE t1 ( a int default NULL, @@ -181,16 +181,16 @@ INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3); SELECT * FROM t1 WHERE a=NULL; a b explain SELECT * FROM t1 WHERE a IS NULL; -table type possible_keys key key_len ref rows Extra -t1 ref a a 5 const 10 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a a 5 const 10 where used SELECT * FROM t1 WHERE a<=>NULL; a b NULL 99 SELECT * FROM t1 WHERE b=NULL; a b explain SELECT * FROM t1 WHERE b IS NULL; -table type possible_keys key key_len ref rows Extra -t1 ref b b 5 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref b b 5 const 1 where used SELECT * FROM t1 WHERE b<=>NULL; a b 99 NULL diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index b75248b5d5a..7b709d6f471 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -139,14 +139,14 @@ id parent_id level 1010 102 2 1015 102 2 explain select level from t1 where level=1; -table type possible_keys key key_len ref rows Extra -t1 ref level level 1 const 12 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref level level 1 const 12 where used; Using index explain select level,id from t1 where level=1; -table type possible_keys key key_len ref rows Extra -t1 ref level level 1 const 12 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref level level 1 const 12 where used; Using index explain select level,id,parent_id from t1 where level=1; -table type possible_keys key key_len ref rows Extra -t1 ref level level 1 const 12 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref level level 1 const 12 where used select level,id from t1 where level=1; level id 1 1002 @@ -596,8 +596,8 @@ id parent_id level 1025 102 2 1016 102 2 explain select level from t1 where level=1; -table type possible_keys key key_len ref rows Extra -t1 ref level level 1 const 6 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref level level 1 const 6 where used; Using index select level,id from t1 where level=1; level id 1 1004 @@ -758,8 +758,8 @@ DROP TABLE t1; create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h int, i int, j int, k int, l int, m int, n int, o int, p int, q int, r int, s int, t int, u int, v int, w int, x int, y int, z int, a1 int, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, b1 int, b2 int, b3 int, b4 int, b5 int, b6 int) type = innodb; insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); explain select * from t1 where a > 0 and a < 50; -table type possible_keys key key_len ref rows Extra -t1 range PRIMARY PRIMARY 4 NULL 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range PRIMARY PRIMARY 4 NULL 1 where used drop table t1; create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) type=innodb; insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL'); @@ -892,29 +892,29 @@ drop table t1; create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) type=innodb; insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4); explain select * from t1 order by a; -table type possible_keys key key_len ref rows Extra -t1 index NULL PRIMARY 4 NULL 4 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL PRIMARY 4 NULL 4 explain select * from t1 order by b; -table type possible_keys key key_len ref rows Extra -t1 index NULL b 4 NULL 4 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL b 4 NULL 4 explain select * from t1 order by c; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 Using filesort +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 Using filesort explain select a from t1 order by a; -table type possible_keys key key_len ref rows Extra -t1 index NULL PRIMARY 4 NULL 4 Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL PRIMARY 4 NULL 4 Using index explain select b from t1 order by b; -table type possible_keys key key_len ref rows Extra -t1 index NULL b 4 NULL 4 Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL b 4 NULL 4 Using index explain select a,b from t1 order by b; -table type possible_keys key key_len ref rows Extra -t1 index NULL b 4 NULL 4 Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL b 4 NULL 4 Using index explain select a,b from t1; -table type possible_keys key key_len ref rows Extra -t1 index NULL b 4 NULL 4 Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL b 4 NULL 4 Using index explain select a,b,c from t1; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 drop table t1; create table t1 (t int not null default 1, key (t)) type=innodb; desc t1; diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index 9d3c152e516..3b9b13bdd3c 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -90,12 +90,12 @@ grp a c id a c d 2 3 c NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1; -Comment -Impossible WHERE noticed after reading const tables +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST Impossible WHERE noticed after reading const tables explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 7 -t2 eq_ref PRIMARY PRIMARY 8 t1.a 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 7 +1 FIRST t2 eq_ref PRIMARY PRIMARY 8 t1.a 1 where used select t1.*,t2.*,t3.a from t1 left join t2 on (t1.a=t2.a) left join t1 as t3 on (t2.a=t3.a); grp a c id a c d a 1 1 a 1 1 a 1 1 @@ -311,13 +311,13 @@ select t1.name, t2.name, t2.id from t1 left join t2 on (t1.id = t2.owner) where name name id Lilliana Angelovska NULL NULL explain select t1.name, t2.name, t2.id from t1 left join t2 on (t1.id = t2.owner) where t2.id is null; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 3 -t2 ALL NULL NULL NULL NULL 3 where used; Not exists +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 3 +1 FIRST t2 ALL NULL NULL NULL NULL 3 where used; Not exists explain select t1.name, t2.name, t2.id from t1 left join t2 on (t1.id = t2.owner) where t2.name is null; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 3 -t2 ALL NULL NULL NULL NULL 3 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 3 +1 FIRST t2 ALL NULL NULL NULL NULL 3 where used select count(*) from t1 left join t2 on (t1.id = t2.owner); count(*) 4 @@ -331,13 +331,13 @@ select t1.name, t2.name, t2.id from t2 right join t1 on (t1.id = t2.owner) where name name id Lilliana Angelovska NULL NULL explain select t1.name, t2.name, t2.id from t2 right join t1 on (t1.id = t2.owner) where t2.id is null; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 3 -t2 ALL NULL NULL NULL NULL 3 where used; Not exists +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 3 +1 FIRST t2 ALL NULL NULL NULL NULL 3 where used; Not exists explain select t1.name, t2.name, t2.id from t2 right join t1 on (t1.id = t2.owner) where t2.name is null; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 3 -t2 ALL NULL NULL NULL NULL 3 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 3 +1 FIRST t2 ALL NULL NULL NULL NULL 3 where used select count(*) from t2 right join t1 on (t1.id = t2.owner); count(*) 4 @@ -618,9 +618,9 @@ UNIQUE id (id,idx) ); INSERT INTO t2 VALUES (1,1); explain SELECT * from t1 left join t2 on t1.id=t2.id where t2.id IS NULL; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 2 -t2 index id id 8 NULL 1 where used; Using index; Not exists +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 2 +1 FIRST t2 index id id 8 NULL 1 where used; Using index; Not exists SELECT * from t1 left join t2 on t1.id=t2.id where t2.id IS NULL; id name id idx 2 no NULL NULL @@ -638,9 +638,9 @@ create table t2 (fooID smallint unsigned not null, barID smallint unsigned not n insert into t1 (fooID) values (10),(20),(30); insert into t2 values (10,1),(20,2),(30,3); explain select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30; -table type possible_keys key key_len ref rows Extra -t2 index NULL PRIMARY 4 NULL 3 Using index -t1 eq_ref PRIMARY PRIMARY 2 const 1 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 index NULL PRIMARY 4 NULL 3 Using index +1 FIRST t1 eq_ref PRIMARY PRIMARY 2 const 1 where used; Using index select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30; fooID barID fooID 10 1 NULL diff --git a/mysql-test/r/key_diff.result b/mysql-test/r/key_diff.result index 0886850f38a..85d1f455b3f 100644 --- a/mysql-test/r/key_diff.result +++ b/mysql-test/r/key_diff.result @@ -34,9 +34,9 @@ C c a a D E a a a a a a explain select t1.*,t2.* from t1,t1 as t2 where t1.A=t2.B; -table type possible_keys key key_len ref rows Extra -t1 ALL a NULL NULL NULL 5 -t2 ALL b NULL NULL NULL 5 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL a NULL NULL NULL 5 +1 FIRST t2 ALL b NULL NULL NULL 5 where used select t1.*,t2.* from t1,t1 as t2 where t1.A=t2.B order by binary t1.a,t2.a; a b a b A B a a diff --git a/mysql-test/r/key_primary.result b/mysql-test/r/key_primary.result index 10771a134fc..b3c9cef64f0 100644 --- a/mysql-test/r/key_primary.result +++ b/mysql-test/r/key_primary.result @@ -11,9 +11,9 @@ select * from t1 where t1 like "a_\%"; t1 AB% describe select * from t1 where t1="ABC"; -table type possible_keys key key_len ref rows Extra -t1 const PRIMARY PRIMARY 3 const 1 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 const PRIMARY PRIMARY 3 const 1 describe select * from t1 where t1="ABCD"; -Comment -Impossible WHERE noticed after reading const tables +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST Impossible WHERE noticed after reading const tables drop table t1; diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index 6de77f7bdaa..f8711d5f0f6 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -34,11 +34,11 @@ insert into t2 select NULL,message from t1; insert into t1 select NULL,message from t2; create table t3 (a int not null, b char(20), key(a)) type=MERGE UNION=(test.t1,test.t2); explain select * from t3 where a < 10; -table type possible_keys key key_len ref rows Extra -t3 range a a 4 NULL 10 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t3 range a a 4 NULL 10 where used explain select * from t3 where a > 10 and a < 20; -table type possible_keys key key_len ref rows Extra -t3 range a a 4 NULL 10 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t3 range a a 4 NULL 10 where used select * from t3 where a = 10; a b 10 Testing @@ -84,8 +84,8 @@ a b 19 Testing 19 Testing explain select a from t3 order by a desc limit 10; -table type possible_keys key key_len ref rows Extra -t3 index NULL a 4 NULL 1131 Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t3 index NULL a 4 NULL 1131 Using index select a from t3 order by a desc limit 10; a 699 diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index fb18841ac3f..647fe70b694 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -51,27 +51,27 @@ drop table t1; create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) type=myisam; insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4); explain select * from t1 order by a; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 Using filesort +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 Using filesort explain select * from t1 order by b; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 Using filesort +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 Using filesort explain select * from t1 order by c; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 Using filesort +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 Using filesort explain select a from t1 order by a; -table type possible_keys key key_len ref rows Extra -t1 index NULL PRIMARY 4 NULL 4 Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL PRIMARY 4 NULL 4 Using index explain select b from t1 order by b; -table type possible_keys key key_len ref rows Extra -t1 index NULL b 4 NULL 4 Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL b 4 NULL 4 Using index explain select a,b from t1 order by b; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 Using filesort +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 Using filesort explain select a,b from t1; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 explain select a,b,c from t1; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 drop table t1; diff --git a/mysql-test/r/null_key.result b/mysql-test/r/null_key.result index a28830a696d..a11f8ce6090 100644 --- a/mysql-test/r/null_key.result +++ b/mysql-test/r/null_key.result @@ -2,38 +2,38 @@ drop table if exists t1; create table t1 (a int, b int not null,unique key (a,b),index(b)) type=myisam; insert ignore into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(null,7),(9,9),(8,8),(7,7),(null,9),(null,9),(6,6); explain select * from t1 where a is null; -table type possible_keys key key_len ref rows Extra -t1 ref a a 5 const 3 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a a 5 const 3 where used; Using index explain select * from t1 where a is null and b = 2; -table type possible_keys key key_len ref rows Extra -t1 ref a,b a 9 const,const 1 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a,b a 9 const,const 1 where used; Using index explain select * from t1 where a is null and b = 7; -table type possible_keys key key_len ref rows Extra -t1 ref a,b a 9 const,const 1 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a,b a 9 const,const 1 where used; Using index explain select * from t1 where a=2 and b = 2; -table type possible_keys key key_len ref rows Extra -t1 const a,b a 9 const,const 1 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 const a,b a 9 const,const 1 explain select * from t1 where a<=>b limit 2; -table type possible_keys key key_len ref rows Extra -t1 index NULL a 9 NULL 12 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL a 9 NULL 12 where used; Using index explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3; -table type possible_keys key key_len ref rows Extra -t1 range a,b a 9 NULL 3 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a,b a 9 NULL 3 where used; Using index explain select * from t1 where (a is null or a = 7) and b=7; -table type possible_keys key key_len ref rows Extra -t1 ref a,b b 4 const 2 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a,b b 4 const 2 where used explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2; -table type possible_keys key key_len ref rows Extra -t1 ref a,b a 5 const 3 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a,b a 5 const 3 where used; Using index explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3; -table type possible_keys key key_len ref rows Extra -t1 range a,b a 9 NULL 2 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a,b a 9 NULL 2 where used; Using index explain select * from t1 where a > 1 and a < 3 limit 1; -table type possible_keys key key_len ref rows Extra -t1 range a a 5 NULL 1 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 5 NULL 1 where used; Using index explain select * from t1 where a > 8 and a < 9; -table type possible_keys key key_len ref rows Extra -t1 range a a 5 NULL 1 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 5 NULL 1 where used; Using index select * from t1 where a is null; a b NULL 7 @@ -65,44 +65,44 @@ NULL 9 NULL 9 alter table t1 modify b blob not null, add c int not null, drop key a, add unique key (a,b(20),c), drop key b, add key (b(10)); explain select * from t1 where a is null and b = 2; -table type possible_keys key key_len ref rows Extra -t1 ref a,b a 5 const 3 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a,b a 5 const 3 where used explain select * from t1 where a is null and b = 2 and c=0; -table type possible_keys key key_len ref rows Extra -t1 ref a,b a 5 const 3 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a,b a 5 const 3 where used explain select * from t1 where a is null and b = 7 and c=0; -table type possible_keys key key_len ref rows Extra -t1 ref a,b a 5 const 3 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a,b a 5 const 3 where used explain select * from t1 where a=2 and b = 2; -table type possible_keys key key_len ref rows Extra -t1 ref a,b a 5 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a,b a 5 const 1 where used explain select * from t1 where a<=>b limit 2; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 12 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 12 where used explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 and c=0 limit 3; -table type possible_keys key key_len ref rows Extra -t1 range a,b a 5 NULL 5 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a,b a 5 NULL 5 where used explain select * from t1 where (a is null or a = 7) and b=7 and c=0; -table type possible_keys key key_len ref rows Extra -t1 range a,b a 5 NULL 4 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a,b a 5 NULL 4 where used explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2; -table type possible_keys key key_len ref rows Extra -t1 ref a,b a 5 const 3 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a,b a 5 const 3 where used explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3; -table type possible_keys key key_len ref rows Extra -t1 ref a,b a 5 const 3 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a,b a 5 const 3 where used explain select * from t1 where a > 1 and a < 3 limit 1; -table type possible_keys key key_len ref rows Extra -t1 range a a 5 NULL 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 5 NULL 1 where used explain select * from t1 where a is null and b=7 or a > 1 and a < 3 limit 1; -table type possible_keys key key_len ref rows Extra -t1 range a,b a 5 NULL 4 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a,b a 5 NULL 4 where used explain select * from t1 where a > 8 and a < 9; -table type possible_keys key key_len ref rows Extra -t1 range a a 5 NULL 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 5 NULL 1 where used explain select * from t1 where b like "6%"; -table type possible_keys key key_len ref rows Extra -t1 range b b 12 NULL 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range b b 12 NULL 1 where used select * from t1 where a is null; a b c NULL 7 0 @@ -151,11 +151,11 @@ PRIMARY KEY (id) INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL); INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL); explain select id from t1 where uniq_id is null; -table type possible_keys key key_len ref rows Extra -t1 ref idx1 idx1 5 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref idx1 idx1 5 const 1 where used explain select id from t1 where uniq_id =1; -table type possible_keys key key_len ref rows Extra -t1 const idx1 idx1 5 const 1 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 const idx1 idx1 5 const 1 UPDATE t1 SET id=id+100 where uniq_id is null; UPDATE t2 SET id=id+100 where uniq_id is null; select id from t1 where uniq_id is null; diff --git a/mysql-test/r/odbc.result b/mysql-test/r/odbc.result index c696cf94e9d..eb6123075fe 100644 --- a/mysql-test/r/odbc.result +++ b/mysql-test/r/odbc.result @@ -10,6 +10,6 @@ a b select * from t1 where a is null; a b explain select * from t1 where b is null; -Comment -Impossible WHERE noticed after reading const tables +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST Impossible WHERE noticed after reading const tables drop table t1; diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result index 9bc716ee8b9..08d52a782e1 100644 --- a/mysql-test/r/order_by.result +++ b/mysql-test/r/order_by.result @@ -263,14 +263,14 @@ drop table t1; create table t1 (a int not null, b int, c varchar(10), key (a, b, c)); insert into t1 values (1, NULL, NULL), (1, NULL, 'b'), (1, 1, NULL), (1, 1, 'b'), (1, 1, 'b'), (2, 1, 'a'), (2, 1, 'b'), (2, 2, 'a'), (2, 2, 'b'), (2, 3, 'c'),(1,3,'b'); explain select * from t1 where (a = 1 and b is null and c = 'b') or (a > 2) order by a desc; -table type possible_keys key key_len ref rows Extra -t1 range a a 20 NULL 2 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 20 NULL 2 where used; Using index select * from t1 where (a = 1 and b is null and c = 'b') or (a > 2) order by a desc; a b c 1 NULL b explain select * from t1 where a >= 1 and a < 3 order by a desc; -table type possible_keys key key_len ref rows Extra -t1 range a a 4 NULL 10 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 4 NULL 10 where used; Using index select * from t1 where a >= 1 and a < 3 order by a desc; a b c 2 3 c @@ -285,8 +285,8 @@ a b c 1 NULL b 1 NULL NULL explain select * from t1 where a = 1 order by a desc, b desc; -table type possible_keys key key_len ref rows Extra -t1 ref a a 4 const 5 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a a 4 const 5 where used; Using index select * from t1 where a = 1 order by a desc, b desc; a b c 1 3 b @@ -296,35 +296,35 @@ a b c 1 NULL b 1 NULL NULL explain select * from t1 where a = 1 and b is null order by a desc, b desc; -table type possible_keys key key_len ref rows Extra -t1 ref a a 9 const,const 2 where used; Using index; Using filesort +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a a 9 const,const 2 where used; Using index; Using filesort select * from t1 where a = 1 and b is null order by a desc, b desc; a b c 1 NULL NULL 1 NULL b explain select * from t1 where a >= 1 and a < 3 and b >0 order by a desc,b desc; -table type possible_keys key key_len ref rows Extra -t1 range a a 9 NULL 8 where used; Using index; Using filesort +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 9 NULL 8 where used; Using index; Using filesort explain select * from t1 where a = 2 and b >0 order by a desc,b desc; -table type possible_keys key key_len ref rows Extra -t1 range a a 9 NULL 5 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 9 NULL 5 where used; Using index explain select * from t1 where a = 2 and b is null order by a desc,b desc; -table type possible_keys key key_len ref rows Extra -t1 ref a a 9 const,const 1 where used; Using index; Using filesort +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref a a 9 const,const 1 where used; Using index; Using filesort explain select * from t1 where a = 2 and (b is null or b > 0) order by a desc,b desc; -table type possible_keys key key_len ref rows Extra -t1 range a a 9 NULL 6 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 9 NULL 6 where used; Using index explain select * from t1 where a = 2 and b > 0 order by a desc,b desc; -table type possible_keys key key_len ref rows Extra -t1 range a a 9 NULL 5 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 9 NULL 5 where used; Using index explain select * from t1 where a = 2 and b < 2 order by a desc,b desc; -table type possible_keys key key_len ref rows Extra -t1 range a a 9 NULL 2 where used; Using index; Using filesort +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 9 NULL 2 where used; Using index; Using filesort alter table t1 modify b int not null, modify c varchar(10) not null; explain select * from t1 order by a, b, c; -table type possible_keys key key_len ref rows Extra -t1 index NULL a 18 NULL 11 Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL a 18 NULL 11 Using index select * from t1 order by a, b, c; a b c 1 0 @@ -339,8 +339,8 @@ a b c 2 2 b 2 3 c explain select * from t1 order by a desc, b desc, c desc; -table type possible_keys key key_len ref rows Extra -t1 index NULL a 18 NULL 11 Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL a 18 NULL 11 Using index select * from t1 order by a desc, b desc, c desc; a b c 2 3 c @@ -355,15 +355,15 @@ a b c 1 0 b 1 0 explain select * from t1 where (a = 1 and b = 1 and c = 'b') or (a > 2) order by a desc; -table type possible_keys key key_len ref rows Extra -t1 range a a 18 NULL 3 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 18 NULL 3 where used; Using index select * from t1 where (a = 1 and b = 1 and c = 'b') or (a > 2) order by a desc; a b c 1 1 b 1 1 b explain select * from t1 where a < 2 and b <= 1 order by a desc, b desc; -table type possible_keys key key_len ref rows Extra -t1 range a a 4 NULL 6 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 4 NULL 6 where used; Using index select * from t1 where a < 2 and b <= 1 order by a desc, b desc; a b c 1 1 b @@ -386,8 +386,8 @@ a b c 1 1 b 1 1 explain select * from t1 where a between 1 and 3 and b <= 1 order by a desc, b desc; -table type possible_keys key key_len ref rows Extra -t1 range a a 8 NULL 10 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 8 NULL 10 where used; Using index select * from t1 where a between 1 and 3 and b <= 1 order by a desc, b desc; a b c 2 1 b @@ -398,8 +398,8 @@ a b c 1 0 b 1 0 explain select * from t1 where a between 0 and 1 order by a desc, b desc; -table type possible_keys key key_len ref rows Extra -t1 range a a 4 NULL 5 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 range a a 4 NULL 5 where used; Using index select * from t1 where a between 0 and 1 order by a desc, b desc; a b c 1 3 b @@ -449,25 +449,25 @@ gid sid uid 104505 5 117 103853 5 250 EXPLAIN select t1.gid, t2.sid, t3.uid from t3, t2, t1 where t2.gid = t1.gid and t2.uid = t3.uid order by t1.gid, t3.uid; -table type possible_keys key key_len ref rows Extra -t1 index PRIMARY PRIMARY 4 NULL 6 Using index -t2 eq_ref PRIMARY,uid PRIMARY 4 t1.gid 1 -t3 eq_ref PRIMARY PRIMARY 2 t2.uid 1 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index PRIMARY PRIMARY 4 NULL 6 Using index +1 FIRST t2 eq_ref PRIMARY,uid PRIMARY 4 t1.gid 1 +1 FIRST t3 eq_ref PRIMARY PRIMARY 2 t2.uid 1 where used; Using index EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t1.gid,t3.skr; -table type possible_keys key key_len ref rows Extra -t1 index PRIMARY PRIMARY 4 NULL 6 Using index -t3 eq_ref PRIMARY PRIMARY 2 t1.gid 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index PRIMARY PRIMARY 4 NULL 6 Using index +1 FIRST t3 eq_ref PRIMARY PRIMARY 2 t1.gid 1 where used EXPLAIN SELECT t1.gid, t2.sid, t3.uid from t2, t1, t3 where t2.gid = t1.gid and t2.uid = t3.uid order by t3.uid, t1.gid; -table type possible_keys key key_len ref rows Extra -t1 index PRIMARY PRIMARY 4 NULL 6 Using index; Using temporary; Using filesort -t2 eq_ref PRIMARY,uid PRIMARY 4 t1.gid 1 -t3 eq_ref PRIMARY PRIMARY 2 t2.uid 1 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index PRIMARY PRIMARY 4 NULL 6 Using index; Using temporary; Using filesort +1 FIRST t2 eq_ref PRIMARY,uid PRIMARY 4 t1.gid 1 +1 FIRST t3 eq_ref PRIMARY PRIMARY 2 t2.uid 1 where used; Using index EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t3.skr,t1.gid; -table type possible_keys key key_len ref rows Extra -t1 index PRIMARY PRIMARY 4 NULL 6 Using index; Using temporary; Using filesort -t3 eq_ref PRIMARY PRIMARY 2 t1.gid 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index PRIMARY PRIMARY 4 NULL 6 Using index; Using temporary; Using filesort +1 FIRST t3 eq_ref PRIMARY PRIMARY 2 t1.gid 1 where used EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.skr = t3.uid order by t1.gid,t3.skr; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort -t3 eq_ref PRIMARY PRIMARY 2 t1.skr 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort +1 FIRST t3 eq_ref PRIMARY PRIMARY 2 t1.skr 1 where used drop table t1,t2,t3; diff --git a/mysql-test/r/range.result b/mysql-test/r/range.result index a1d258455dc..722a1f5c62c 100644 --- a/mysql-test/r/range.result +++ b/mysql-test/r/range.result @@ -15,8 +15,8 @@ event_date type event_id 1999-07-13 100600 26 1999-07-14 100600 10 explain select event_date,type,event_id from t1 WHERE type = 100601 and event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date; -Comment -Impossible WHERE +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST Impossible WHERE select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND (type=100600 OR type=100100) or event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND type=100099; event_date type event_id 1999-07-10 100100 24 diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 49ce0608fc5..8b3e2aa298e 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -1327,20 +1327,20 @@ fld3 select t2.fld3 from t2 where fld3 LIKE 'don_t_find_me_please%'; fld3 explain select t2.fld3 from t2 where fld3 = 'honeysuckle'; -table type possible_keys key key_len ref rows Extra -t2 ref fld3 fld3 30 const 1 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 ref fld3 fld3 30 const 1 where used; Using index explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle'; -table type possible_keys key key_len ref rows Extra -t2 index NULL fld3 30 NULL 1199 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 index NULL fld3 30 NULL 1199 where used; Using index explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle'; -table type possible_keys key key_len ref rows Extra -t2 index NULL fld3 30 NULL 1199 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 index NULL fld3 30 NULL 1199 where used; Using index explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle'; -table type possible_keys key key_len ref rows Extra -t2 ref fld3 fld3 30 const 1 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 ref fld3 fld3 30 const 1 where used; Using index explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle'; -table type possible_keys key key_len ref rows Extra -t2 ref fld3 fld3 30 const 1 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 ref fld3 fld3 30 const 1 where used; Using index explain select fld3 from t2 ignore index (fld3,not_used); Key column 'not_used' doesn't exist in table explain select fld3 from t2 use index (not_used); @@ -1350,8 +1350,8 @@ fld3 honeysuckle honoring explain select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3; -table type possible_keys key key_len ref rows Extra -t2 range fld3 fld3 30 NULL 2 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 range fld3 fld3 30 NULL 2 where used; Using index select fld1,fld3 from t2 where fld3="Colombo" or fld3 = "nondecreasing" order by fld3; fld1 fld3 148504 Colombo @@ -1370,8 +1370,8 @@ fld1 250501 250502 explain select fld1 from t2 where fld1=250501 or fld1="250502"; -table type possible_keys key key_len ref rows Extra -t2 range fld1 fld1 4 NULL 2 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 range fld1 fld1 4 NULL 2 where used; Using index select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502; fld1 250501 @@ -1379,8 +1379,8 @@ fld1 250505 250601 explain select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502; -table type possible_keys key key_len ref rows Extra -t2 range fld1 fld1 4 NULL 4 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 range fld1 fld1 4 NULL 4 where used; Using index select fld1,fld3 from t2 where companynr = 37 and fld3 like 'f%'; fld1 fld3 218401 faithful @@ -1806,9 +1806,9 @@ companynr rtrim(space(512+companynr)) select distinct fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by fld3; fld3 explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3; -table type possible_keys key key_len ref rows Extra -t2 ALL fld1 NULL NULL NULL 1199 where used; Using temporary; Using filesort -t3 eq_ref PRIMARY PRIMARY 4 t2.fld1 1 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 ALL fld1 NULL NULL NULL 1199 where used; Using temporary; Using filesort +1 FIRST t3 eq_ref PRIMARY PRIMARY 4 t2.fld1 1 where used; Using index select period from t1; period 9410 @@ -1821,9 +1821,9 @@ select fld3,period from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3. fld3 period breaking 1001 explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period; -table type possible_keys key key_len ref rows Extra -t2 const fld1 fld1 4 const 1 -t3 const PRIMARY,period PRIMARY 4 const 1 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 const fld1 fld1 4 const 1 +1 FIRST t3 const PRIMARY,period PRIMARY 4 const 1 select fld3,period from t2,t1 where companynr*10 = 37*10; fld3 period breaking 9410 @@ -2561,21 +2561,21 @@ fld1 fld1 select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null; companynr companyname explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null; -table type possible_keys key key_len ref rows Extra -t2 ALL NULL NULL NULL NULL 1199 -t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 where used; Not exists +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 ALL NULL NULL NULL NULL 1199 +1 FIRST t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 where used; Not exists explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null; -table type possible_keys key key_len ref rows Extra -t4 ALL NULL NULL NULL NULL 12 -t2 ALL NULL NULL NULL NULL 1199 where used; Not exists +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t4 ALL NULL NULL NULL NULL 12 +1 FIRST t2 ALL NULL NULL NULL NULL 1199 where used; Not exists select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1; companynr companynr 37 36 41 40 explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1; -table type possible_keys key key_len ref rows Extra -t2 ALL NULL NULL NULL NULL 1199 Using temporary -t4 index NULL PRIMARY 1 NULL 12 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 ALL NULL NULL NULL NULL 1199 Using temporary +1 FIRST t4 index NULL PRIMARY 1 NULL 12 where used; Using index select t2.fld1,t2.companynr,fld3,period from t3,t2 where t2.fld1 = 38208 and t2.fld1=t3.t2nr and period = 1008 or t2.fld1 = 38008 and t2.fld1 =t3.t2nr and period = 1008; fld1 companynr fld3 period 038008 37 reporters 1008 @@ -3084,11 +3084,11 @@ select t2.fld1,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = fld1 sum(price) 038008 234298 explain select fld3 from t2 where 1>2 or 2>3; -Comment -Impossible WHERE +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST Impossible WHERE explain select fld3 from t2 where fld1=fld1; -table type possible_keys key key_len ref rows Extra -t2 ALL NULL NULL NULL NULL 1199 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 ALL NULL NULL NULL NULL 1199 select companynr,fld1 from t2 HAVING fld1=250501 or fld1=250502; companynr fld1 34 250501 @@ -3139,8 +3139,8 @@ select count(*) from t3 where companynr=512 and price2=76234234; count(*) 4181 explain select min(fld1),max(fld1),count(*) from t2; -Comment -Select tables optimized away +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST Select tables optimized away select min(fld1),max(fld1),count(*) from t2; min(fld1) max(fld1) count(*) 0 1232609 1199 diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index dada87803ad..54528f58697 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -46,6 +46,13 @@ a b 2 7 3 8 4 8 +explain select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1) +union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a); +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 ALL NULL NULL NULL NULL 2 where used +3 UNION t4 ALL NULL NULL NULL NULL 3 where used; Using filesort +4 SUBSELECT t2 ALL NULL NULL NULL NULL 2 +2 SUBSELECT t3 ALL NULL NULL NULL NULL 3 Using filesort select (select a from t3 where a1) as tt; (select t3.a from t3 where a<8 order by 1 desc limit 1) a 7 2 +explain select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from +(select * from t2 where a>1) as tt; +id select_type table type possible_keys key key_len ref rows Extra +3 DERIVED t2 ALL NULL NULL NULL NULL 2 where used +1 FIRST system NULL NULL NULL NULL 1 +2 SUBSELECT t3 ALL NULL NULL NULL NULL 3 where used; Using filesort select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1); a 2 @@ -67,6 +80,11 @@ b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) 8 7.5000 8 4.5000 9 7.5000 +explain select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t4 ALL NULL NULL NULL NULL 3 +2 DEPENDENT SUBSELECT t2 ALL NULL NULL NULL NULL 2 +3 DEPENDENT SUBSELECT t3 ALL NULL NULL NULL NULL 3 where used select * from t3 where exists (select * from t2 where t2.b=t3.a); a 7 @@ -97,6 +115,11 @@ select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a NULL 1 2 2 +explain select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t2 ALL NULL NULL NULL NULL 2 +2 DEPENDENT SUBSELECT t1 system NULL NULL NULL NULL 1 where used +3 DEPENDENT UNION t5 ALL NULL NULL NULL NULL 2 where used select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; Subselect return more than 1 record create table attend (patient_uq int, clinic_uq int, index i1 (clinic_uq)); diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index cae15d4f665..51148cd12e9 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -75,6 +75,6 @@ date numfacture expedition 0000-00-00 00:00:00 0 0001-00-00 00:00:00 0000-00-00 00:00:00 1212 0001-00-00 00:00:00 EXPLAIN SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00'; -table type possible_keys key key_len ref rows Extra -t1 ref expedition expedition 8 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref expedition expedition 8 const 1 where used drop table t1; diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index 29b925b6746..86f62d11bdb 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -85,35 +85,31 @@ a b 2 b 1 a explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 -t2 ALL NULL NULL NULL NULL 4 Using filesort -(select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2; -a b -1 a -2 b +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 +2 UNION t2 ALL NULL NULL NULL NULL 4 Using filesort select found_rows(); FOUND_ROWS() -6 +0 explain select a,b from t1 union all select a,b from t2; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 -t2 ALL NULL NULL NULL NULL 4 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 +2 UNION t2 ALL NULL NULL NULL NULL 4 explain select xx from t1 union select 1; Unknown column 'xx' in 'field list' explain select a,b from t1 union select 1; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 - 0 0 No tables used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 4 +2 UNION No tables used explain select 1 union select a,b from t1 union select 1; -table type possible_keys key key_len ref rows Extra - 0 0 No tables used -t1 ALL NULL NULL NULL NULL 4 - 0 0 No tables used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST No tables used +2 UNION t1 ALL NULL NULL NULL NULL 4 +3 UNION No tables used explain select a,b from t1 union select 1 limit 0; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 4 - 0 0 Impossible WHERE +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST Impossible WHERE +2 UNION Impossible WHERE select a,b from t1 into outfile 'skr' union select a,b from t2; Wrong usage of UNION and INTO select a,b from t1 order by a union select a,b from t2; diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result index 5c8b4581c5c..10cb4fe5c8e 100644 --- a/mysql-test/r/user_var.result +++ b/mysql-test/r/user_var.result @@ -18,15 +18,15 @@ i @vv1:=if(sv1.i,1,0) @vv2:=if(sv2.i,1,0) @vv3:=if(sv3.i,1,0) @vv1+@vv2+@vv3 1 1 0 1 2 2 1 0 0 1 explain select * from t1 where i=@vv1; -table type possible_keys key key_len ref rows Extra -t1 ref i i 4 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref i i 4 const 1 where used explain select * from t1 where @vv1:=@vv1+1 and i=@vv1; -table type possible_keys key key_len ref rows Extra -t1 ALL NULL NULL NULL NULL 3 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ALL NULL NULL NULL NULL 3 where used explain select @vv1:=i from t1 where i=@vv1; -table type possible_keys key key_len ref rows Extra -t1 index NULL i 4 NULL 3 where used; Using index +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 index NULL i 4 NULL 3 where used; Using index explain select * from t1 where i=@vv1; -table type possible_keys key key_len ref rows Extra -t1 ref i i 4 const 1 where used +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 ref i i 4 const 1 where used drop table t1,t2; diff --git a/mysql-test/r/varbinary.result b/mysql-test/r/varbinary.result index a63db14b736..a7bd29afd78 100644 --- a/mysql-test/r/varbinary.result +++ b/mysql-test/r/varbinary.result @@ -11,8 +11,8 @@ create table t1 (ID int(8) unsigned zerofill not null auto_increment,UNIQ bigint insert into t1 set UNIQ=0x38afba1d73e6a18a; insert into t1 set UNIQ=123; explain select * from t1 where UNIQ=0x38afba1d73e6a18a; -table type possible_keys key key_len ref rows Extra -t1 const UNIQ UNIQ 8 const 1 +id select_type table type possible_keys key key_len ref rows Extra +1 FIRST t1 const UNIQ UNIQ 8 const 1 drop table t1; select x'hello'; You have an error in your SQL syntax near 'x'hello'' at line 1 diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 8b9ed3b89c9..68a89796ec3 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -19,13 +19,18 @@ select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1) union (select * from t4 order by a limit 2) limit 3; select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a); +explain select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1) +union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a); select (select a from t3 where a1) as tt; +explain select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from +(select * from t2 where a>1) as tt; select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1); select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a > t1.a) order by 1 desc limit 1); select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1); select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +explain select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; select * from t3 where exists (select * from t2 where t2.b=t3.a); select * from t3 where not exists (select * from t2 where t2.b=t3.a); insert into t4 values (12,7),(1,7),(10,9),(9,6),(7,6),(3,9); @@ -39,6 +44,7 @@ insert into t5 values (5); select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; insert into t5 values (2); select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +explain select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; -- error 1230 select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; create table attend (patient_uq int, clinic_uq int, index i1 (clinic_uq)); diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index f5a92b05e0d..8f8f666bf55 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -21,7 +21,7 @@ select 't1',b,count(*) from t1 group by b UNION select 't2',b,count(*) from t2 g (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1); (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; -(select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2; +#(select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2; select found_rows(); # Test some error conditions with UNION explain select a,b from t1 union all select a,b from t2; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index d3901770230..dbf853431d6 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -373,9 +373,14 @@ int handle_select(THD *thd, LEX *lex, select_result *result); int mysql_select(THD *thd,TABLE_LIST *tables,List &list,COND *conds, ORDER *order, ORDER *group,Item *having,ORDER *proc_param, ulong select_type,select_result *result, - SELECT_LEX_UNIT *unit, bool fake_select_lex); + SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex, + bool fake_select_lex); +void fix_tables_pointers(SELECT_LEX *select_lex); +int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type, + select_result *result); int mysql_union(THD *thd, LEX *lex,select_result *result); -int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *s, TABLE_LIST *t); +int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *s, TABLE_LIST *t, + bool tables_is_opened); Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, Item_result_field ***copy_func, Field **from_field, bool group,bool modify_item); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index b84bcf1df72..c090f2336c1 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -357,6 +357,28 @@ CHANGED_TABLE_LIST* THD::changed_table_dup(TABLE *table) return new_table; } +int THD::send_explain_fields(select_result *result) +{ + List field_list; + Item *item; + field_list.push_back(new Item_int("id",0,3)); + field_list.push_back(new Item_empty_string("select_type",19)); + field_list.push_back(new Item_empty_string("table",NAME_LEN)); + field_list.push_back(new Item_empty_string("type",10)); + field_list.push_back(item=new Item_empty_string("possible_keys", + NAME_LEN*MAX_KEY)); + item->maybe_null=1; + field_list.push_back(item=new Item_empty_string("key",NAME_LEN)); + item->maybe_null=1; + field_list.push_back(item=new Item_int("key_len",0,3)); + item->maybe_null=1; + field_list.push_back(item=new Item_empty_string("ref", + NAME_LEN*MAX_REF_PARTS)); + item->maybe_null=1; + field_list.push_back(new Item_real("rows",0.0,0,10)); + field_list.push_back(new Item_empty_string("Extra",255)); + return (result->send_fields(field_list,1)); +} /***************************************************************************** ** Functions to provide a interface to select results diff --git a/sql/sql_class.h b/sql/sql_class.h index 82241f0ff1f..7be9a5ad9fe 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -315,6 +315,7 @@ public: }; class delayed_insert; +class select_result; #define THD_SENTRY_MAGIC 0xfeedd1ff #define THD_SENTRY_GONE 0xdeadbeef @@ -442,6 +443,7 @@ public: uint server_status,open_options; uint32 query_length; uint32 db_length; + uint select_number; //number of select (used for EXPLAIN) enum_tx_isolation tx_isolation, session_tx_isolation; char scramble[9]; uint8 query_cache_type; // type of query cache processing @@ -576,6 +578,7 @@ public: } void add_changed_table(TABLE *table); CHANGED_TABLE_LIST * changed_table_dup(TABLE *table); + int send_explain_fields(select_result *result); }; /* diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index cde120f3774..539a9edb479 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -28,7 +28,8 @@ static const char *any_db="*any*"; // Special symbol for check_access -int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t) +int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t, + bool tables_is_opened) { /* TODO: make derived tables with union inside (now only 1 SELECT may be @@ -37,7 +38,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t) SELECT_LEX *sl= unit->first_select(); List item_list; TABLE *table; - int res; + int res= 0; select_union *derived_result; TABLE_LIST *tables= (TABLE_LIST *)sl->table_list.first; TMP_TABLE_PARAM tmp_table_param; @@ -56,7 +57,8 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t) { if (cursor->derived) { - res=mysql_derived(thd, lex, (SELECT_LEX_UNIT *)cursor->derived, cursor); + res=mysql_derived(thd, lex, (SELECT_LEX_UNIT *)cursor->derived, + cursor, 0); if (res) DBUG_RETURN(res); } } @@ -66,7 +68,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t) while ((item= it++)) item_list.push_back(item); - if (!(res=open_and_lock_tables(thd,tables))) + if (tables_is_opened || !(res=open_and_lock_tables(thd,tables))) { if (tables && setup_fields(thd,tables,item_list,0,0,1)) { @@ -94,12 +96,12 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t) if (unit->select_limit_cnt == HA_POS_ERROR) sl->options&= ~OPTION_FOUND_ROWS; - res=mysql_select(thd, tables, sl->item_list, - sl->where, (ORDER *) sl->order_list.first, - (ORDER*) sl->group_list.first, - sl->having, (ORDER*) NULL, - sl->options | thd->options | SELECT_NO_UNLOCK, - derived_result, unit, 0); + res= mysql_select(thd, tables, sl->item_list, + sl->where, (ORDER *) sl->order_list.first, + (ORDER*) sl->group_list.first, + sl->having, (ORDER*) NULL, + sl->options | thd->options | SELECT_NO_UNLOCK, + derived_result, unit, sl, 0); if (!res) { // Here we entirely fix both TABLE_LIST and list of SELECT's as there were no derived tables @@ -109,6 +111,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t) { t->real_name=table->real_name; t->table=table; + table->derived_select_number= sl->select_number; sl->exclude(); t->derived=(SELECT_LEX *)0; // just in case ... } diff --git a/sql/sql_lex.h b/sql/sql_lex.h index b75826663ca..e6054f5604b 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -282,8 +282,10 @@ public: List *ftfunc_list; List ftfunc_list_alloc; JOIN *join; /* after JOIN::prepare it is pointer to corresponding JOIN */ + const char *type; /* type of select for EXPLAIN */ uint in_sum_expr; - bool create_refs, + uint select_number; /* number of select (used for EXPLAIN) */ + bool create_refs, braces, /* SELECT ... UNION (SELECT ... ) <- this braces */ depended, /* depended from outer select subselect */ /* TRUE when having fix field called in processing of this SELECT */ diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 9977eaad0ff..8166a156b8c 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1254,7 +1254,7 @@ mysql_execute_command(void) THD *thd= current_thd; LEX *lex= &thd->lex; TABLE_LIST *tables= (TABLE_LIST*) lex->select_lex.table_list.first; - SELECT_LEX *select_lex= lex->select; + SELECT_LEX *select_lex= &lex->select_lex; SELECT_LEX_UNIT *unit= &lex->unit; DBUG_ENTER("mysql_execute_command"); @@ -1281,18 +1281,69 @@ mysql_execute_command(void) #endif } + select_result *explain_result= 0; /* - Skip if we are in the slave thread, some table rules have been given - and the table list says the query should not be replicated + TODO: make derived tables processing 'inside' SELECT processing. + TODO: solve problem with depended derived tables in subselects */ - if (lex->derived_tables) + if (lex->sql_command == SQLCOM_SELECT && + (select_lex->options & SELECT_DESCRIBE) && + lex->derived_tables) + { + if (!(explain_result= new select_send())) + { + send_error(&thd->net, ER_OUT_OF_RESOURCES); + DBUG_VOID_RETURN; + } + //check rights + for (TABLE_LIST *cursor= tables; + cursor; + cursor= cursor->next) + if (cursor->derived) + { + TABLE_LIST *tables= + (TABLE_LIST *)((SELECT_LEX_UNIT *) + cursor->derived)->first_select()->table_list.first; + int res; + if (tables) + res= check_table_access(thd,SELECT_ACL, tables); + else + res= check_access(thd, SELECT_ACL, any_db); + if (res) + DBUG_VOID_RETURN; + } + thd->send_explain_fields(explain_result); + // EXPLAIN derived tables + for (TABLE_LIST *cursor= tables; + cursor; + cursor= cursor->next) + if (cursor->derived) + { + SELECT_LEX *select_lex= ((SELECT_LEX_UNIT *) + cursor->derived)->first_select(); + if (!open_and_lock_tables(thd, + (TABLE_LIST*) select_lex->table_list.first)) + { + mysql_explain_select(thd, select_lex, + "DERIVED", explain_result); + // execute derived table SELECT to provide table for other SELECTs + if (mysql_derived(thd, lex, (SELECT_LEX_UNIT *)cursor->derived, + cursor, 1)) + DBUG_VOID_RETURN; + } + else + DBUG_VOID_RETURN; + } + + } + else if (lex->derived_tables) { for (TABLE_LIST *cursor= tables; cursor; cursor= cursor->next) if (cursor->derived && mysql_derived(thd, lex, (SELECT_LEX_UNIT *)cursor->derived, - cursor)) + cursor, 0)) DBUG_VOID_RETURN; } if ((lex->select_lex.next_select_in_list() && @@ -1374,8 +1425,44 @@ mysql_execute_command(void) if (!(res=open_and_lock_tables(thd,tables))) { - query_cache_store_query(thd, tables); - res=handle_select(thd, lex, result); + if (select_lex->options & SELECT_DESCRIBE) + { + delete result; // we do not need it for explain + if (!explain_result) + if (!(explain_result= new select_send())) + { + send_error(&thd->net, ER_OUT_OF_RESOURCES); + DBUG_VOID_RETURN; + } + else + thd->send_explain_fields(explain_result); + fix_tables_pointers(select_lex); + for ( SELECT_LEX *sl= select_lex; + sl && res == 0; + sl= sl->next_select_in_list()) + { + SELECT_LEX *first= sl->master_unit()->first_select(); + res= mysql_explain_select(thd, sl, + ((select_lex==sl)?"FIRST": + ((sl == first)? + ((sl->depended)?"DEPENDENT SUBSELECT": + "SUBSELECT"): + ((sl->depended)?"DEPENDENT UNION": + "UNION"))), + explain_result); + } + if (res > 0) + res= -res; // mysql_explain_select do not report error + MYSQL_LOCK *save_lock= thd->lock; + thd->lock= (MYSQL_LOCK *)0; + explain_result->send_eof(); + thd->lock= save_lock; + } + else + { + query_cache_store_query(thd, tables); + res=handle_select(thd, lex, result); + } } else delete result; @@ -1866,7 +1953,7 @@ mysql_execute_command(void) (ORDER *)NULL, select_lex->options | thd->options | SELECT_NO_JOIN_CACHE, - result, unit, 0); + result, unit, select_lex, 0); delete result; } else @@ -2037,7 +2124,7 @@ mysql_execute_command(void) (ORDER *)NULL, select_lex->options | thd->options | SELECT_NO_JOIN_CACHE, - result, unit, 0); + result, unit, select_lex, 0); delete result; } else @@ -2803,6 +2890,7 @@ mysql_init_query(THD *thd) thd->lex.unit.global_parameters= &thd->lex.select_lex; //Global limit & order thd->lex.select_lex.master= &thd->lex.unit; thd->lex.select_lex.prev= &thd->lex.unit.slave; + thd->select_number= thd->lex.select_lex.select_number= 1; thd->lex.value_list.empty(); thd->free_list= 0; thd->lex.union_option= 0; @@ -2832,6 +2920,7 @@ bool mysql_new_select(LEX *lex, bool move_down) { SELECT_LEX *select_lex = (SELECT_LEX *) lex->thd->calloc(sizeof(SELECT_LEX)); + select_lex->select_number= ++lex->thd->select_number; if (!select_lex) return 1; select_lex->init_query(); @@ -2874,6 +2963,7 @@ mysql_parse(THD *thd, char *inBuf, uint length) mysql_init_query(thd); thd->query_length = length; + thd->lex.derived_tables= false; if (query_cache_send_result_to_client(thd, inBuf, length) <= 0) { LEX *lex=lex_start(thd, (uchar*) inBuf, length); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index d071743aec4..b87a79cc2c6 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -144,7 +144,6 @@ static void init_sum_functions(Item_sum **func); static bool update_sum_func(Item_sum **func); static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, bool distinct, const char *message=NullS); -static void describe_info(THD *thd, const char *info); /* This handles SELECT with and without UNION @@ -154,19 +153,7 @@ int handle_select(THD *thd, LEX *lex, select_result *result) { int res; register SELECT_LEX *select_lex = &lex->select_lex; - if (select_lex->next_select_in_list()) - { - /* Fix tables 'to-be-unioned-from' list to point at opened tables */ - for (SELECT_LEX *sl= select_lex; - sl; - sl= sl->next_select_in_list()) - { - for (TABLE_LIST *cursor= (TABLE_LIST *)sl->table_list.first; - cursor; - cursor=cursor->next) - cursor->table= cursor->table_list->table; - } - } + fix_tables_pointers(select_lex); if (select_lex->next_select()) res=mysql_union(thd,lex,result); else @@ -178,7 +165,7 @@ int handle_select(THD *thd, LEX *lex, select_result *result) select_lex->having, (ORDER*) lex->proc_list.first, select_lex->options | thd->options, - result, &(lex->unit), 0); + result, &(lex->unit), &(lex->select_lex), 0); if (res && result) result->abort(); if (res || thd->net.report_error) @@ -190,6 +177,22 @@ int handle_select(THD *thd, LEX *lex, select_result *result) return res; } +void fix_tables_pointers(SELECT_LEX *select_lex) +{ + if (select_lex->next_select_in_list()) + { + /* Fix tables 'to-be-unioned-from' list to point at opened tables */ + for (SELECT_LEX *sl= select_lex; + sl; + sl= sl->next_select_in_list()) + { + for (TABLE_LIST *cursor= (TABLE_LIST *)sl->table_list.first; + cursor; + cursor=cursor->next) + cursor->table= cursor->table_list->table; + } + } +} /***************************************************************************** ** check fields, find best join, do the select and output fields. @@ -209,7 +212,7 @@ JOIN::prepare(TABLE_LIST *tables_init, SELECT_LEX_UNIT *unit, bool fake_select_lex) { DBUG_ENTER("JOIN::prepare"); - + conds= conds_init; order= order_init; group_list= group_init; @@ -344,7 +347,7 @@ int JOIN::optimize() { DBUG_ENTER("JOIN::optimize"); - + #ifdef HAVE_REF_TO_FIELDS // Not done yet /* Add HAVING to WHERE if possible */ if (having && !group_list && ! sum_func_count) @@ -389,11 +392,8 @@ JOIN::optimize() } if (select_options & SELECT_DESCRIBE) { - if (union_part) - select_describe(this, false, false, false, - "Select tables optimized away"); - else - describe_info(thd, "Select tables optimized away"); + select_describe(this, false, false, false, + "Select tables optimized away"); delete procedure; DBUG_RETURN(1); } @@ -647,10 +647,7 @@ JOIN::exec() error=0; if (select_options & SELECT_DESCRIBE) { - if (union_part) - select_describe(this, false, false, false, "No tables used"); - else - describe_info(thd, "No tables used"); + select_describe(this, false, false, false, "No tables used"); } else { @@ -674,16 +671,16 @@ JOIN::exec() if (zero_result_cause) { - if (select_options & SELECT_DESCRIBE && union_part) + if (select_options & SELECT_DESCRIBE) select_describe(this, false, false, false, zero_result_cause); else - error=return_zero_rows(result, tables_list, fields_list, - tmp_table_param.sum_func_count != 0 && - !group_list, - select_options, - zero_result_cause, - having,procedure, - unit); + error= return_zero_rows(result, tables_list, fields_list, + tmp_table_param.sum_func_count != 0 && + !group_list, + select_options, + zero_result_cause, + having,procedure, + unit); DBUG_VOID_RETURN; } @@ -1004,7 +1001,8 @@ int mysql_select(THD *thd, TABLE_LIST *tables, List &fields, COND *conds, ORDER *order, ORDER *group,Item *having, ORDER *proc_param, ulong select_options, select_result *result, - SELECT_LEX_UNIT *unit, bool fake_select_lex) + SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex, + bool fake_select_lex) { JOIN *join = new JOIN(thd, fields, select_options, result); @@ -1013,7 +1011,7 @@ mysql_select(THD *thd, TABLE_LIST *tables, List &fields, COND *conds, thd->used_tables=0; // Updated by setup_fields if (join->prepare(tables, conds, order, group, having, proc_param, - &(thd->lex.select_lex), unit, fake_select_lex)) + select_lex, unit, fake_select_lex)) { DBUG_RETURN(-1); } @@ -3087,11 +3085,6 @@ return_zero_rows(select_result *result,TABLE_LIST *tables,List &fields, { DBUG_ENTER("return_zero_rows"); - if (select_options & SELECT_DESCRIBE) - { - describe_info(current_thd, info); - DBUG_RETURN(0); - } if (procedure) { if (result->prepare(fields, unit)) // This hasn't been done yet @@ -3725,6 +3718,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, table->blob_ptr_size=mi_portable_sizeof_char_ptr; table->map=1; table->tmp_table= TMP_TABLE; + table->derived_select_number= 0; table->db_low_byte_first=1; // True for HEAP and MyISAM table->temp_pool_slot = temp_pool_slot; @@ -7139,7 +7133,6 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, Item *item; List item_list; THD *thd=join->thd; - MYSQL_LOCK *save_lock; SELECT_LEX *select_lex = &(join->thd->lex.select_lex); select_result *result=join->result; DBUG_ENTER("select_describe"); @@ -7147,28 +7140,13 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, /* Don't log this into the slow query log */ select_lex->options&= ~(QUERY_NO_INDEX_USED | QUERY_NO_GOOD_INDEX_USED); join->unit->offset_limit_cnt= 0; - if (thd->lex.select == select_lex) - { - field_list.push_back(new Item_empty_string("table",NAME_LEN)); - field_list.push_back(new Item_empty_string("type",10)); - field_list.push_back(item=new Item_empty_string("possible_keys", - NAME_LEN*MAX_KEY)); - item->maybe_null=1; - field_list.push_back(item=new Item_empty_string("key",NAME_LEN)); - item->maybe_null=1; - field_list.push_back(item=new Item_int("key_len",0,3)); - item->maybe_null=1; - field_list.push_back(item=new Item_empty_string("ref", - NAME_LEN*MAX_REF_PARTS)); - item->maybe_null=1; - field_list.push_back(new Item_real("rows",0.0,0,10)); - field_list.push_back(new Item_empty_string("Extra",255)); - if (result->send_fields(field_list,1)) - return; - } if (message) { + item_list.push_back(new Item_int((int)thd->lex.select->select_number)); + item_list.push_back(new Item_string(thd->lex.select->type, + strlen(thd->lex.select->type), + default_charset_info)); item_list.push_back(new Item_empty_string("",0)); item_list.push_back(new Item_empty_string("",0)); item_list.push_back(new Item_empty_string("",0)); @@ -7192,9 +7170,24 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, String tmp1(buff1,sizeof(buff1),default_charset_info); String tmp2(buff2,sizeof(buff2),default_charset_info); item_list.empty(); + item_list.push_back(new Item_int((int)thd->lex.select->select_number)); + item_list.push_back(new Item_string(thd->lex.select->type, + strlen(thd->lex.select->type), + default_charset_info)); if (tab->type == JT_ALL && tab->select && tab->select->quick) tab->type= JT_RANGE; - item_list.push_back(new Item_string(table->table_name,strlen(table->table_name),default_charset_info)); + if (table->tmp_table == TMP_TABLE && table->derived_select_number != 0) + { + // Derived table name generation + buff[512]; + int len= my_snprintf(buff, 512, "", + table->derived_select_number); + item_list.push_back(new Item_string(buff, len, default_charset_info)); + } + else + item_list.push_back(new Item_string(table->table_name, + strlen(table->table_name), + default_charset_info)); item_list.push_back(new Item_string(join_type_str[tab->type],strlen(join_type_str[tab->type]),default_charset_info)); tmp1.length(0); tmp2.length(0); key_map bits; @@ -7311,29 +7304,25 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, result->send_error(0,NullS); } } - if (!join->thd->lex.select->next_select()) - { - save_lock=thd->lock; - thd->lock=(MYSQL_LOCK *)0; - result->send_eof(); - thd->lock=save_lock; - } DBUG_VOID_RETURN; } - -static void describe_info(THD *thd, const char *info) +int mysql_explain_select(THD *thd, SELECT_LEX *select_lex, char const *type, + select_result *result) { - List field_list; - String *packet= &thd->packet; + select_lex->type= type; + thd->lex.select= select_lex; + SELECT_LEX_UNIT *unit= select_lex->master_unit(); + int res= mysql_select(thd,(TABLE_LIST*) select_lex->table_list.first, + select_lex->item_list, + select_lex->where, + (ORDER*) select_lex->order_list.first, + (ORDER*) select_lex->group_list.first, + select_lex->having, + (ORDER*) thd->lex.proc_list.first, + select_lex->options | thd->options | SELECT_DESCRIBE, + result, unit, select_lex, 0); - /* Don't log this into the slow query log */ - thd->lex.select_lex.options&= ~(QUERY_NO_INDEX_USED | QUERY_NO_GOOD_INDEX_USED); - field_list.push_back(new Item_empty_string("Comment",80)); - if (send_fields(thd,field_list,1)) - return; /* purecov: inspected */ - packet->length(0); - net_store_data(packet,info); - if (!my_net_write(&thd->net,(char*) packet->ptr(),packet->length())) - send_eof(&thd->net); + return res; } + diff --git a/sql/sql_union.cc b/sql/sql_union.cc index e8ee3582135..f6ac17e5fe3 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -111,6 +111,7 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result) DBUG_ENTER("st_select_lex_unit::prepare"); this->thd= thd; this->result= result; + SELECT_LEX *lex_select_save= thd->lex.select; /* Global option */ if (((void*)(global_parameters)) == ((void*)this)) @@ -148,9 +149,9 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result) /* Create a list of items that will be in the result set */ while ((item= it++)) if (item_list.push_back(item)) - DBUG_RETURN(-1); + goto err; if (setup_fields(thd,first_table,item_list,0,0,1)) - DBUG_RETURN(-1); + goto err; } bzero((char*) &tmp_table_param,sizeof(tmp_table_param)); @@ -162,7 +163,7 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result) (first_select()->options | thd->options | TMP_TABLE_ALL_COLUMNS), this))) - DBUG_RETURN(-1); + goto err; table->file->extra(HA_EXTRA_WRITE_CACHE); table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); bzero((char*) &result_table_list,sizeof(result_table_list)); @@ -171,7 +172,7 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result) result_table_list.table=table; if (!(union_result=new select_union(table))) - DBUG_RETURN(-1); + goto err; union_result->save_time_stamp=!describe; union_result->tmp_table_param=&tmp_table_param; @@ -202,9 +203,13 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result) (ORDER*) NULL, sl, this, 0); if (res | thd->fatal_error) - DBUG_RETURN(res | thd->fatal_error); + goto err; } + thd->lex.select= lex_select_save; DBUG_RETURN(res | thd->fatal_error); +err: + thd->lex.select= lex_select_save; + DBUG_RETURN(-1); } int st_select_lex_unit::exec() @@ -214,7 +219,7 @@ int st_select_lex_unit::exec() { if (optimized && item && item->assigned()) item->assigned(0); // We will reinit & rexecute unit - + SELECT_LEX *lex_select_save= thd->lex.select; for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select()) { thd->lex.select=sl; @@ -234,8 +239,12 @@ int st_select_lex_unit::exec() res= sl->join->error; if (res) + { + thd->lex.select= lex_select_save; DBUG_RETURN(res); + } } + thd->lex.select= lex_select_save; optimized= 1; } @@ -283,7 +292,7 @@ int st_select_lex_unit::exec() 0: (ORDER*)global_parameters->order_list.first, (ORDER*) NULL, NULL, (ORDER*) NULL, - thd->options, result, this, 1); + thd->options, result, this, first_select(), 1); if (found_rows_for_union && !res) thd->limit_found_rows = (ulonglong)table->file->records; } diff --git a/sql/table.h b/sql/table.h index b89701bfc8e..3b8a62a09b5 100644 --- a/sql/table.h +++ b/sql/table.h @@ -128,6 +128,9 @@ struct st_table { uint temp_pool_slot; + /* number of select if it is derived table */ + uint derived_select_number; + THD *in_use; /* Which thread uses this */ struct st_table *next,*prev; }; From da891a571e49804e3743bf2776bcf2648a4832da Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 27 Sep 2002 23:11:51 +0300 Subject: [PATCH 3/6] fixed Item_subselect constructor --- sql/item_subselect.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 29034549367..a8909430155 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -34,7 +34,7 @@ SUBSELECT TODO: Item_subselect::Item_subselect(THD *thd, st_select_lex *select_lex, select_subselect *result): - engine_owner(1), value_assigned(0) + Item(), engine_owner(1), value_assigned(0) { DBUG_ENTER("Item_subselect::Item_subselect"); DBUG_PRINT("subs", ("select_lex 0x%xl", (long) select_lex)); From c9a2b58986635015b3f3867999ef3fafa2bd2728 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 28 Sep 2002 18:34:56 +0300 Subject: [PATCH 4/6] fixed bug in string & date types with group function in subselect mysql-test/r/subselect.result: test suite of string & date types with group function in subselects mysql-test/t/subselect.test: test suite of string & date types with group function in subselects sql/item_subselect.cc: fixed bug in string type with group function sql/item_subselect.h: fixed bug in string type with group function sql/sql_class.cc: fixed bug in date type with group function --- mysql-test/r/subselect.result | 16 ++++++++++++ mysql-test/t/subselect.test | 13 ++++++++++ sql/item_subselect.cc | 47 ++++++++++++++++++++++++++++++++++- sql/item_subselect.h | 12 +++++++-- sql/sql_class.cc | 8 ++++-- 5 files changed, 91 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 54528f58697..5a96cc08cbf 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -131,4 +131,20 @@ patient_uq clinic_uq 1 1 1 2 2 2 +drop table if exists t1,t2,t3; +CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0'); +INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b'); +CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0'); +INSERT INTO t2 VALUES ('W','1'),('A','3'),('J','2'); +CREATE TABLE t1 (a varchar(20),b date NOT NULL default '0000-00-00'); +INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13'); +SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1); +a b +W 1732-02-22 +SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2); +a b +W 1 +SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3); +a b +W a drop table t1,t2,t3,t4,t5,attend,clinic; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 68a89796ec3..3ae695c8967 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -53,4 +53,17 @@ insert into clinic values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta" insert into attend values (1,1),(1,2),(2,2),(1,3); select * from attend where exists (select * from clinic where uq = clinic_uq); +# different tipes & group functions +drop table if exists t1,t2,t3; + +CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0'); +INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b'); +CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0'); +INSERT INTO t2 VALUES ('W','1'),('A','3'),('J','2'); +CREATE TABLE t1 (a varchar(20),b date NOT NULL default '0000-00-00'); +INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13'); +SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1); +SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2); +SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3); + drop table t1,t2,t3,t4,t5,attend,clinic; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index a8909430155..99fc0bcdb67 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -82,7 +82,14 @@ bool Item_subselect::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) my_message(ER_SUBSELECT_NO_1_COL, ER(ER_SUBSELECT_NO_1_COL), MYF(0)); return 1; } - return engine->prepare(); + int res= engine->prepare(); + fix_length_and_dec(); + return res; +} + +void Item_subselect::fix_length_and_dec() +{ + engine->fix_length_and_dec(); } inline table_map Item_subselect::used_tables() const @@ -98,6 +105,12 @@ Item_singleval_subselect::Item_singleval_subselect(THD *thd, maybe_null= 1; } +void Item_singleval_subselect::fix_length_and_dec() +{ + engine->fix_length_and_dec(); + res_type= engine->type(); +} + Item::Type Item_subselect::type() const { return SUBSELECT_ITEM; @@ -135,6 +148,12 @@ Item_exists_subselect::Item_exists_subselect(THD *thd, select_lex->select_limit= 1; // we need only 1 row to determinate existence } +void Item_exists_subselect::fix_length_and_dec() +{ + max_length= 1; + +} + double Item_exists_subselect::val () { if (engine->exec()) @@ -221,6 +240,32 @@ int subselect_union_engine::prepare() return unit->prepare(thd, result); } +void subselect_single_select_engine::fix_length_and_dec() +{ + List_iterator_fast li(select_lex->item_list); + Item *sel_item= li++; + item->max_length= sel_item->max_length; + res_type= sel_item->result_type(); + item->decimals= sel_item->decimals; +} + +void subselect_union_engine::fix_length_and_dec() +{ + uint32 mlen= 0, len; + Item *sel_item= 0; + for(SELECT_LEX *sl= unit->first_select(); sl; sl= sl->next_select()) + { + List_iterator_fast li(sl->item_list); + Item *s_item= li++; + if ((len= s_item->max_length)) + mlen= len; + if (!sel_item) + sel_item= s_item; + } + item->max_length= mlen; + res_type= sel_item->result_type(); + item->decimals= sel_item->decimals; +} int subselect_single_select_engine::exec() { diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 0d8495d3ae8..92839eb0e5f 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -61,6 +61,7 @@ public: bool is_null() { return null_value; } void make_field (Send_field *); bool fix_fields(THD *thd, TABLE_LIST *tables, Item **ref); + virtual void fix_length_and_dec(); table_map used_tables() const; friend class select_subselect; @@ -100,7 +101,7 @@ public: String *val_str (String *); Item *new_item() { return new Item_singleval_subselect(this); } enum Item_result result_type() const { return res_type; } - + void fix_length_and_dec(); friend class select_singleval_subselect; }; @@ -128,7 +129,7 @@ public: longlong val_int(); double val(); String *val_str(String*); - + void fix_length_and_dec(); friend class select_exists_subselect; }; @@ -138,6 +139,7 @@ protected: select_subselect *result; /* results storage class */ THD *thd; /* pointer to current THD */ Item_subselect *item; /* item, that use this engine */ + enum Item_result res_type; /* type of results */ public: static void *operator new(size_t size) { @@ -150,11 +152,15 @@ public: result= res; item= si; this->thd= thd; + res_type= STRING_RESULT; } + virtual int prepare()= 0; + virtual void fix_length_and_dec()= 0; virtual int exec()= 0; virtual uint cols()= 0; /* return number of columnss in select */ virtual bool depended()= 0; /* depended from outer select */ + enum Item_result type() { return res_type; } }; class subselect_single_select_engine: public subselect_engine @@ -168,6 +174,7 @@ public: select_subselect *result, Item_subselect *item); virtual int prepare(); + virtual void fix_length_and_dec(); virtual int exec(); virtual uint cols(); virtual bool depended(); @@ -182,6 +189,7 @@ public: select_subselect *result, Item_subselect *item); virtual int prepare(); + virtual void fix_length_and_dec(); virtual int exec(); virtual uint cols(); virtual bool depended(); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index c090f2336c1..98551fa35ba 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -838,12 +838,16 @@ bool select_singleval_subselect::send_data(List &items) if ((it->null_value= val_item->is_null())) { it->assign_null(); - } else { + } + else + { it->max_length= val_item->max_length; it->decimals= val_item->decimals; it->binary= val_item->binary; - val_item->val_str(&it->str_value); it->int_value= val_item->val_int(); + String *s= val_item->val_str(&it->str_value); + if (s != &it->str_value) + it->str_value.set(*s, 0, s->length()); it->res_type= val_item->result_type(); } it->assigned(1); From f094b6af4c5c32bfda7f74461d47675ab61722a0 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 3 Oct 2002 18:47:04 +0300 Subject: [PATCH 5/6] fixing EXPLAIN select types --- mysql-test/r/compare.result | 2 +- mysql-test/r/create.result | 2 +- mysql-test/r/distinct.result | 24 ++++++------- mysql-test/r/explain.result | 10 +++--- mysql-test/r/group_by.result | 10 +++--- mysql-test/r/heap.result | 16 ++++----- mysql-test/r/heap_btree.result | 22 ++++++------ mysql-test/r/heap_hash.result | 16 ++++----- mysql-test/r/innodb.result | 26 +++++++------- mysql-test/r/join_outer.result | 30 ++++++++--------- mysql-test/r/key_diff.result | 4 +-- mysql-test/r/key_primary.result | 4 +-- mysql-test/r/merge.result | 6 ++-- mysql-test/r/myisam.result | 16 ++++----- mysql-test/r/null_key.result | 52 ++++++++++++++-------------- mysql-test/r/odbc.result | 2 +- mysql-test/r/order_by.result | 56 +++++++++++++++---------------- mysql-test/r/range.result | 2 +- mysql-test/r/select.result | 42 +++++++++++------------ mysql-test/r/subselect.result | 8 ++--- mysql-test/r/type_datetime.result | 2 +- mysql-test/r/union.result | 10 +++--- mysql-test/r/user_var.result | 8 ++--- mysql-test/r/varbinary.result | 2 +- sql/sql_parse.cc | 4 ++- 25 files changed, 189 insertions(+), 187 deletions(-) diff --git a/mysql-test/r/compare.result b/mysql-test/r/compare.result index be11de8ebb9..10f149e7a9b 100644 --- a/mysql-test/r/compare.result +++ b/mysql-test/r/compare.result @@ -3,7 +3,7 @@ CREATE TABLE t1 (id CHAR(12) not null, PRIMARY KEY (id)); insert into t1 values ('000000000001'),('000000000002'); explain select * from t1 where id=000000000001; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index PRIMARY PRIMARY 12 NULL 2 where used; Using index +1 SIMPLE t1 index PRIMARY PRIMARY 12 NULL 2 where used; Using index select * from t1 where id=000000000001; id 000000000001 diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 41a977695a6..625ef684698 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -63,7 +63,7 @@ insert into t1 (b) values ("hello"),("my"),("world"); create table t2 (key (b)) select * from t1; explain select * from t2 where b="world"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 ref B B 21 const 1 where used +1 SIMPLE t2 ref B B 21 const 1 where used select * from t2 where b="world"; a B 3 world diff --git a/mysql-test/r/distinct.result b/mysql-test/r/distinct.result index d8386ddcfc3..5848e583d7e 100644 --- a/mysql-test/r/distinct.result +++ b/mysql-test/r/distinct.result @@ -173,9 +173,9 @@ INSERT INTO t2 values (1),(2),(3); INSERT INTO t3 VALUES (1,'1'),(2,'2'),(1,'1'),(2,'2'); explain SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t3 index a a 5 NULL 6 Using index; Using temporary -1 FIRST t2 index a a 4 NULL 5 Using index; Distinct -1 FIRST t1 eq_ref PRIMARY PRIMARY 4 t2.a 1 where used; Distinct +1 SIMPLE t3 index a a 5 NULL 6 Using index; Using temporary +1 SIMPLE t2 index a a 4 NULL 5 Using index; Distinct +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 t2.a 1 where used; Distinct SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a; a 1 @@ -189,8 +189,8 @@ insert into t4 select * from t3; insert into t3 select * from t4; explain select distinct t1.a from t1,t3 where t1.a=t3.a; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index PRIMARY PRIMARY 4 NULL 2 Using index; Using temporary -1 FIRST t3 ref a a 5 t1.a 10 Using index; Distinct +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 2 Using index; Using temporary +1 SIMPLE t3 ref a a 5 t1.a 10 Using index; Distinct select distinct t1.a from t1,t3 where t1.a=t3.a; a 1 @@ -275,13 +275,13 @@ WHERE ((t1.id=j_lj_t2.id AND t2_lj.id IS NULL) OR (t1.id=t2.id AND t2.idx=2)) AND ((t1.id=j_lj_t3.id AND t3_lj.id IS NULL) OR (t1.id=t3.id AND t3.idx=2)); id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index id id 4 NULL 2 Using index; Using temporary -1 FIRST t2 index id id 8 NULL 1 Using index; Distinct -1 FIRST t3 index id id 8 NULL 1 Using index; Distinct -1 FIRST j_lj_t2 index id id 4 NULL 2 where used; Using index; Distinct -1 FIRST t2_lj index id id 8 NULL 1 where used; Using index; Distinct -1 FIRST j_lj_t3 index id id 4 NULL 2 where used; Using index; Distinct -1 FIRST t3_lj index id id 8 NULL 1 where used; Using index; Distinct +1 SIMPLE t1 index id id 4 NULL 2 Using index; Using temporary +1 SIMPLE t2 index id id 8 NULL 1 Using index; Distinct +1 SIMPLE t3 index id id 8 NULL 1 Using index; Distinct +1 SIMPLE j_lj_t2 index id id 4 NULL 2 where used; Using index; Distinct +1 SIMPLE t2_lj index id id 8 NULL 1 where used; Using index; Distinct +1 SIMPLE j_lj_t3 index id id 4 NULL 2 where used; Using index; Distinct +1 SIMPLE t3_lj index id id 8 NULL 1 where used; Using index; Distinct SELECT DISTINCT t1.id from diff --git a/mysql-test/r/explain.result b/mysql-test/r/explain.result index cd0ddeae120..0d97aeaf531 100644 --- a/mysql-test/r/explain.result +++ b/mysql-test/r/explain.result @@ -10,16 +10,16 @@ id str 3 foo explain select * from t1 where str is null; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref str str 11 const 1 where used +1 SIMPLE t1 ref str str 11 const 1 where used explain select * from t1 where str="foo"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 const str str 11 const 1 +1 SIMPLE t1 const str str 11 const 1 explain select * from t1 ignore key (str) where str="foo"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 where used +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 where used explain select * from t1 use key (str,str) where str="foo"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 const str str 11 const 1 +1 SIMPLE t1 const str str 11 const 1 explain select * from t1 use key (str,str,foo) where str="foo"; Key column 'foo' doesn't exist in table explain select * from t1 ignore key (str,str,foo) where str="foo"; @@ -27,4 +27,4 @@ Key column 'foo' doesn't exist in table drop table t1; explain select 1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST No tables used +1 SIMPLE No tables used diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 0781468bc97..54b4e3fba6d 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -226,7 +226,7 @@ key (score) INSERT INTO t1 VALUES (1,1,1),(2,2,2),(2,1,1),(3,3,3),(4,3,3),(5,3,3); explain select userid,count(*) from t1 group by userid desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort select userid,count(*) from t1 group by userid desc; userid count(*) 3 3 @@ -234,10 +234,10 @@ userid count(*) 1 2 explain select spid,count(*) from t1 where spid between 1 and 2 group by spid desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range spID spID 5 NULL 2 where used; Using index +1 SIMPLE t1 range spID spID 5 NULL 2 where used; Using index explain select spid,count(*) from t1 where spid between 1 and 2 group by spid; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range spID spID 5 NULL 2 where used; Using index +1 SIMPLE t1 range spID spID 5 NULL 2 where used; Using index select spid,count(*) from t1 where spid between 1 and 2 group by spid; spid count(*) 1 1 @@ -248,7 +248,7 @@ spid count(*) 1 1 explain select sql_big_result spid,sum(userid) from t1 group by spid desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 6 Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using filesort select sql_big_result spid,sum(userid) from t1 group by spid desc; spid sum(userid) 5 3 @@ -258,7 +258,7 @@ spid sum(userid) 1 1 explain select sql_big_result score,count(*) from t1 group by score desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL score 3 NULL 6 Using index +1 SIMPLE t1 index NULL score 3 NULL 6 Using index select sql_big_result score,count(*) from t1 group by score desc; score count(*) 3 3 diff --git a/mysql-test/r/heap.result b/mysql-test/r/heap.result index 94fac7757ac..8fe87cdda8b 100644 --- a/mysql-test/r/heap.result +++ b/mysql-test/r/heap.result @@ -66,7 +66,7 @@ a alter table t1 type=myisam; explain select * from t1 where a in (869751,736494,226312,802616); id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range uniq_id uniq_id 4 NULL 4 where used; Using index +1 SIMPLE t1 range uniq_id uniq_id 4 NULL 4 where used; Using index drop table t1; create table t1 (x int not null, y int not null, key x (x), unique y (y)) type=heap; @@ -85,8 +85,8 @@ x y x y 2 6 2 2 explain select * from t1,t1 as t2 where t1.x=t2.y; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL x NULL NULL NULL 6 -1 FIRST t2 eq_ref y y 4 t1.x 1 +1 SIMPLE t1 ALL x NULL NULL NULL 6 +1 SIMPLE t2 eq_ref y y 4 t1.x 1 drop table t1; create table t1 (a int) type=heap; insert into t1 values(1); @@ -159,17 +159,17 @@ create table t1 (btn char(10) not null, key(btn)) type=heap; insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); explain select * from t1 where btn like "q%"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL btn NULL NULL NULL 14 where used +1 SIMPLE t1 ALL btn NULL NULL NULL 14 where used select * from t1 where btn like "q%"; btn alter table t1 add column new_col char(1) not null, add key (btn,new_col), drop key btn; update t1 set new_col=btn; explain select * from t1 where btn="a"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL btn NULL NULL NULL 14 where used +1 SIMPLE t1 ALL btn NULL NULL NULL 14 where used explain select * from t1 where btn="a" and new_col="a"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref btn btn 11 const,const 10 where used +1 SIMPLE t1 ref btn btn 11 const,const 10 where used drop table t1; CREATE TABLE t1 ( a int default NULL, @@ -182,7 +182,7 @@ SELECT * FROM t1 WHERE a=NULL; a b explain SELECT * FROM t1 WHERE a IS NULL; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a a 5 const 10 where used +1 SIMPLE t1 ref a a 5 const 10 where used SELECT * FROM t1 WHERE a<=>NULL; a b NULL 99 @@ -190,7 +190,7 @@ SELECT * FROM t1 WHERE b=NULL; a b explain SELECT * FROM t1 WHERE b IS NULL; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref b b 5 const 1 where used +1 SIMPLE t1 ref b b 5 const 1 where used SELECT * FROM t1 WHERE b<=>NULL; a b 99 NULL diff --git a/mysql-test/r/heap_btree.result b/mysql-test/r/heap_btree.result index 5a8289a16f7..0e8a32bd7b7 100644 --- a/mysql-test/r/heap_btree.result +++ b/mysql-test/r/heap_btree.result @@ -66,7 +66,7 @@ a alter table t1 type=myisam; explain select * from t1 where a in (869751,736494,226312,802616); id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range uniq_id uniq_id 4 NULL 4 where used; Using index +1 SIMPLE t1 range uniq_id uniq_id 4 NULL 4 where used; Using index drop table t1; create table t1 (x int not null, y int not null, key x using BTREE (x), unique y using BTREE (y)) type=heap; @@ -85,8 +85,8 @@ x y x y 2 6 2 2 explain select * from t1,t1 as t2 where t1.x=t2.y; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL x NULL NULL NULL 6 -1 FIRST t2 eq_ref y y 4 t1.x 1 +1 SIMPLE t1 ALL x NULL NULL NULL 6 +1 SIMPLE t2 eq_ref y y 4 t1.x 1 drop table t1; create table t1 (a int) type=heap; insert into t1 values(1); @@ -121,17 +121,17 @@ a b 1 6 explain select * from tx where a=x order by a,b; id select_type table type possible_keys key key_len ref rows Extra -x FIRST tx ref a a x const x where used +x SIMPLE tx ref a a x const x where used explain select * from tx where a=x order by b; id select_type table type possible_keys key key_len ref rows Extra -x FIRST tx ref a a x const x where used +x SIMPLE tx ref a a x const x where used select * from t1 where b=1; a b 1 1 1 1 explain select * from tx where b=x; id select_type table type possible_keys key key_len ref rows Extra -x FIRST tx ref b b x const x where used +x SIMPLE tx ref b b x const x where used drop table t1; create table t1 (id int unsigned not null, primary key using BTREE (id)) type=HEAP; insert into t1 values(1); @@ -172,17 +172,17 @@ create table t1 (btn char(10) not null, key using BTREE (btn)) type=heap; insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); explain select * from t1 where btn like "q%"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL btn NULL NULL NULL 14 where used +1 SIMPLE t1 ALL btn NULL NULL NULL 14 where used select * from t1 where btn like "q%"; btn alter table t1 add column new_col char(1) not null, add key using BTREE (btn,new_col), drop key btn; update t1 set new_col=btn; explain select * from t1 where btn="a"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref btn btn 10 const 1 where used +1 SIMPLE t1 ref btn btn 10 const 1 where used explain select * from t1 where btn="a" and new_col="a"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref btn btn 11 const,const 1 where used +1 SIMPLE t1 ref btn btn 11 const,const 1 where used drop table t1; CREATE TABLE t1 ( a int default NULL, @@ -195,7 +195,7 @@ SELECT * FROM t1 WHERE a=NULL; a b explain SELECT * FROM t1 WHERE a IS NULL; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a a 5 const 1 where used +1 SIMPLE t1 ref a a 5 const 1 where used SELECT * FROM t1 WHERE a<=>NULL; a b NULL 99 @@ -203,7 +203,7 @@ SELECT * FROM t1 WHERE b=NULL; a b explain SELECT * FROM t1 WHERE b IS NULL; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref b b 5 const 1 where used +1 SIMPLE t1 ref b b 5 const 1 where used SELECT * FROM t1 WHERE b<=>NULL; a b 99 NULL diff --git a/mysql-test/r/heap_hash.result b/mysql-test/r/heap_hash.result index 4dd79e5c52b..43a86069d3d 100644 --- a/mysql-test/r/heap_hash.result +++ b/mysql-test/r/heap_hash.result @@ -66,7 +66,7 @@ a alter table t1 type=myisam; explain select * from t1 where a in (869751,736494,226312,802616); id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range uniq_id uniq_id 4 NULL 4 where used; Using index +1 SIMPLE t1 range uniq_id uniq_id 4 NULL 4 where used; Using index drop table t1; create table t1 (x int not null, y int not null, key x using HASH (x), unique y using HASH (y)) type=heap; @@ -85,8 +85,8 @@ x y x y 2 6 2 2 explain select * from t1,t1 as t2 where t1.x=t2.y; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL x NULL NULL NULL 6 -1 FIRST t2 eq_ref y y 4 t1.x 1 +1 SIMPLE t1 ALL x NULL NULL NULL 6 +1 SIMPLE t2 eq_ref y y 4 t1.x 1 drop table t1; create table t1 (a int) type=heap; insert into t1 values(1); @@ -159,17 +159,17 @@ create table t1 (btn char(10) not null, key using HASH (btn)) type=heap; insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); explain select * from t1 where btn like "q%"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL btn NULL NULL NULL 14 where used +1 SIMPLE t1 ALL btn NULL NULL NULL 14 where used select * from t1 where btn like "q%"; btn alter table t1 add column new_col char(1) not null, add key using HASH (btn,new_col), drop key btn; update t1 set new_col=btn; explain select * from t1 where btn="a"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL btn NULL NULL NULL 14 where used +1 SIMPLE t1 ALL btn NULL NULL NULL 14 where used explain select * from t1 where btn="a" and new_col="a"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref btn btn 11 const,const 10 where used +1 SIMPLE t1 ref btn btn 11 const,const 10 where used drop table t1; CREATE TABLE t1 ( a int default NULL, @@ -182,7 +182,7 @@ SELECT * FROM t1 WHERE a=NULL; a b explain SELECT * FROM t1 WHERE a IS NULL; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a a 5 const 10 where used +1 SIMPLE t1 ref a a 5 const 10 where used SELECT * FROM t1 WHERE a<=>NULL; a b NULL 99 @@ -190,7 +190,7 @@ SELECT * FROM t1 WHERE b=NULL; a b explain SELECT * FROM t1 WHERE b IS NULL; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref b b 5 const 1 where used +1 SIMPLE t1 ref b b 5 const 1 where used SELECT * FROM t1 WHERE b<=>NULL; a b 99 NULL diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index 7b709d6f471..de08465a2a0 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -140,13 +140,13 @@ id parent_id level 1015 102 2 explain select level from t1 where level=1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref level level 1 const 12 where used; Using index +1 SIMPLE t1 ref level level 1 const 12 where used; Using index explain select level,id from t1 where level=1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref level level 1 const 12 where used; Using index +1 SIMPLE t1 ref level level 1 const 12 where used; Using index explain select level,id,parent_id from t1 where level=1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref level level 1 const 12 where used +1 SIMPLE t1 ref level level 1 const 12 where used select level,id from t1 where level=1; level id 1 1002 @@ -597,7 +597,7 @@ id parent_id level 1016 102 2 explain select level from t1 where level=1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref level level 1 const 6 where used; Using index +1 SIMPLE t1 ref level level 1 const 6 where used; Using index select level,id from t1 where level=1; level id 1 1004 @@ -759,7 +759,7 @@ create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); explain select * from t1 where a > 0 and a < 50; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range PRIMARY PRIMARY 4 NULL 1 where used +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 where used drop table t1; create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) type=innodb; insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL'); @@ -893,28 +893,28 @@ create table t1 (a int not null, b int not null, c int not null, primary key (a) insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4); explain select * from t1 order by a; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL PRIMARY 4 NULL 4 +1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 explain select * from t1 order by b; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL b 4 NULL 4 +1 SIMPLE t1 index NULL b 4 NULL 4 explain select * from t1 order by c; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort explain select a from t1 order by a; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL PRIMARY 4 NULL 4 Using index +1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 Using index explain select b from t1 order by b; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL b 4 NULL 4 Using index +1 SIMPLE t1 index NULL b 4 NULL 4 Using index explain select a,b from t1 order by b; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL b 4 NULL 4 Using index +1 SIMPLE t1 index NULL b 4 NULL 4 Using index explain select a,b from t1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL b 4 NULL 4 Using index +1 SIMPLE t1 index NULL b 4 NULL 4 Using index explain select a,b,c from t1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 drop table t1; create table t1 (t int not null default 1, key (t)) type=innodb; desc t1; diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index 3b9b13bdd3c..9c44792724b 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -91,11 +91,11 @@ grp a c id a c d NULL NULL NULL NULL NULL NULL explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST Impossible WHERE noticed after reading const tables +1 SIMPLE Impossible WHERE noticed after reading const tables explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 7 -1 FIRST t2 eq_ref PRIMARY PRIMARY 8 t1.a 1 where used +1 SIMPLE t1 ALL NULL NULL NULL NULL 7 +1 SIMPLE t2 eq_ref PRIMARY PRIMARY 8 t1.a 1 where used select t1.*,t2.*,t3.a from t1 left join t2 on (t1.a=t2.a) left join t1 as t3 on (t2.a=t3.a); grp a c id a c d a 1 1 a 1 1 a 1 1 @@ -312,12 +312,12 @@ name name id Lilliana Angelovska NULL NULL explain select t1.name, t2.name, t2.id from t1 left join t2 on (t1.id = t2.owner) where t2.id is null; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 3 -1 FIRST t2 ALL NULL NULL NULL NULL 3 where used; Not exists +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 where used; Not exists explain select t1.name, t2.name, t2.id from t1 left join t2 on (t1.id = t2.owner) where t2.name is null; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 3 -1 FIRST t2 ALL NULL NULL NULL NULL 3 where used +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 where used select count(*) from t1 left join t2 on (t1.id = t2.owner); count(*) 4 @@ -332,12 +332,12 @@ name name id Lilliana Angelovska NULL NULL explain select t1.name, t2.name, t2.id from t2 right join t1 on (t1.id = t2.owner) where t2.id is null; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 3 -1 FIRST t2 ALL NULL NULL NULL NULL 3 where used; Not exists +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 where used; Not exists explain select t1.name, t2.name, t2.id from t2 right join t1 on (t1.id = t2.owner) where t2.name is null; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 3 -1 FIRST t2 ALL NULL NULL NULL NULL 3 where used +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 where used select count(*) from t2 right join t1 on (t1.id = t2.owner); count(*) 4 @@ -619,8 +619,8 @@ UNIQUE id (id,idx) INSERT INTO t2 VALUES (1,1); explain SELECT * from t1 left join t2 on t1.id=t2.id where t2.id IS NULL; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 2 -1 FIRST t2 index id id 8 NULL 1 where used; Using index; Not exists +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +1 SIMPLE t2 index id id 8 NULL 1 where used; Using index; Not exists SELECT * from t1 left join t2 on t1.id=t2.id where t2.id IS NULL; id name id idx 2 no NULL NULL @@ -639,8 +639,8 @@ insert into t1 (fooID) values (10),(20),(30); insert into t2 values (10,1),(20,2),(30,3); explain select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 index NULL PRIMARY 4 NULL 3 Using index -1 FIRST t1 eq_ref PRIMARY PRIMARY 2 const 1 where used; Using index +1 SIMPLE t2 index NULL PRIMARY 4 NULL 3 Using index +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 2 const 1 where used; Using index select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30; fooID barID fooID 10 1 NULL diff --git a/mysql-test/r/key_diff.result b/mysql-test/r/key_diff.result index 85d1f455b3f..bdeff4f60d8 100644 --- a/mysql-test/r/key_diff.result +++ b/mysql-test/r/key_diff.result @@ -35,8 +35,8 @@ D E a a a a a a explain select t1.*,t2.* from t1,t1 as t2 where t1.A=t2.B; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL a NULL NULL NULL 5 -1 FIRST t2 ALL b NULL NULL NULL 5 where used +1 SIMPLE t1 ALL a NULL NULL NULL 5 +1 SIMPLE t2 ALL b NULL NULL NULL 5 where used select t1.*,t2.* from t1,t1 as t2 where t1.A=t2.B order by binary t1.a,t2.a; a b a b A B a a diff --git a/mysql-test/r/key_primary.result b/mysql-test/r/key_primary.result index b3c9cef64f0..df9d962b3ac 100644 --- a/mysql-test/r/key_primary.result +++ b/mysql-test/r/key_primary.result @@ -12,8 +12,8 @@ t1 AB% describe select * from t1 where t1="ABC"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 const PRIMARY PRIMARY 3 const 1 +1 SIMPLE t1 const PRIMARY PRIMARY 3 const 1 describe select * from t1 where t1="ABCD"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST Impossible WHERE noticed after reading const tables +1 SIMPLE Impossible WHERE noticed after reading const tables drop table t1; diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index f8711d5f0f6..590169338a6 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -35,10 +35,10 @@ insert into t1 select NULL,message from t2; create table t3 (a int not null, b char(20), key(a)) type=MERGE UNION=(test.t1,test.t2); explain select * from t3 where a < 10; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t3 range a a 4 NULL 10 where used +1 SIMPLE t3 range a a 4 NULL 10 where used explain select * from t3 where a > 10 and a < 20; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t3 range a a 4 NULL 10 where used +1 SIMPLE t3 range a a 4 NULL 10 where used select * from t3 where a = 10; a b 10 Testing @@ -85,7 +85,7 @@ a b 19 Testing explain select a from t3 order by a desc limit 10; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t3 index NULL a 4 NULL 1131 Using index +1 SIMPLE t3 index NULL a 4 NULL 1131 Using index select a from t3 order by a desc limit 10; a 699 diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index 647fe70b694..4b4a88a54f7 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -52,26 +52,26 @@ create table t1 (a int not null, b int not null, c int not null, primary key (a) insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4); explain select * from t1 order by a; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort explain select * from t1 order by b; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort explain select * from t1 order by c; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort explain select a from t1 order by a; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL PRIMARY 4 NULL 4 Using index +1 SIMPLE t1 index NULL PRIMARY 4 NULL 4 Using index explain select b from t1 order by b; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL b 4 NULL 4 Using index +1 SIMPLE t1 index NULL b 4 NULL 4 Using index explain select a,b from t1 order by b; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort explain select a,b from t1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 explain select a,b,c from t1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 drop table t1; diff --git a/mysql-test/r/null_key.result b/mysql-test/r/null_key.result index a11f8ce6090..0a708ff298c 100644 --- a/mysql-test/r/null_key.result +++ b/mysql-test/r/null_key.result @@ -3,37 +3,37 @@ create table t1 (a int, b int not null,unique key (a,b),index(b)) type=myisam; insert ignore into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(null,7),(9,9),(8,8),(7,7),(null,9),(null,9),(6,6); explain select * from t1 where a is null; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a a 5 const 3 where used; Using index +1 SIMPLE t1 ref a a 5 const 3 where used; Using index explain select * from t1 where a is null and b = 2; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a,b a 9 const,const 1 where used; Using index +1 SIMPLE t1 ref a,b a 9 const,const 1 where used; Using index explain select * from t1 where a is null and b = 7; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a,b a 9 const,const 1 where used; Using index +1 SIMPLE t1 ref a,b a 9 const,const 1 where used; Using index explain select * from t1 where a=2 and b = 2; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 const a,b a 9 const,const 1 +1 SIMPLE t1 const a,b a 9 const,const 1 explain select * from t1 where a<=>b limit 2; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL a 9 NULL 12 where used; Using index +1 SIMPLE t1 index NULL a 9 NULL 12 where used; Using index explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a,b a 9 NULL 3 where used; Using index +1 SIMPLE t1 range a,b a 9 NULL 3 where used; Using index explain select * from t1 where (a is null or a = 7) and b=7; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a,b b 4 const 2 where used +1 SIMPLE t1 ref a,b b 4 const 2 where used explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a,b a 5 const 3 where used; Using index +1 SIMPLE t1 ref a,b a 5 const 3 where used; Using index explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a,b a 9 NULL 2 where used; Using index +1 SIMPLE t1 range a,b a 9 NULL 2 where used; Using index explain select * from t1 where a > 1 and a < 3 limit 1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 5 NULL 1 where used; Using index +1 SIMPLE t1 range a a 5 NULL 1 where used; Using index explain select * from t1 where a > 8 and a < 9; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 5 NULL 1 where used; Using index +1 SIMPLE t1 range a a 5 NULL 1 where used; Using index select * from t1 where a is null; a b NULL 7 @@ -66,43 +66,43 @@ NULL 9 alter table t1 modify b blob not null, add c int not null, drop key a, add unique key (a,b(20),c), drop key b, add key (b(10)); explain select * from t1 where a is null and b = 2; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a,b a 5 const 3 where used +1 SIMPLE t1 ref a,b a 5 const 3 where used explain select * from t1 where a is null and b = 2 and c=0; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a,b a 5 const 3 where used +1 SIMPLE t1 ref a,b a 5 const 3 where used explain select * from t1 where a is null and b = 7 and c=0; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a,b a 5 const 3 where used +1 SIMPLE t1 ref a,b a 5 const 3 where used explain select * from t1 where a=2 and b = 2; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a,b a 5 const 1 where used +1 SIMPLE t1 ref a,b a 5 const 1 where used explain select * from t1 where a<=>b limit 2; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 12 where used +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 where used explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 and c=0 limit 3; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a,b a 5 NULL 5 where used +1 SIMPLE t1 range a,b a 5 NULL 5 where used explain select * from t1 where (a is null or a = 7) and b=7 and c=0; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a,b a 5 NULL 4 where used +1 SIMPLE t1 range a,b a 5 NULL 4 where used explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a,b a 5 const 3 where used +1 SIMPLE t1 ref a,b a 5 const 3 where used explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a,b a 5 const 3 where used +1 SIMPLE t1 ref a,b a 5 const 3 where used explain select * from t1 where a > 1 and a < 3 limit 1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 5 NULL 1 where used +1 SIMPLE t1 range a a 5 NULL 1 where used explain select * from t1 where a is null and b=7 or a > 1 and a < 3 limit 1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a,b a 5 NULL 4 where used +1 SIMPLE t1 range a,b a 5 NULL 4 where used explain select * from t1 where a > 8 and a < 9; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 5 NULL 1 where used +1 SIMPLE t1 range a a 5 NULL 1 where used explain select * from t1 where b like "6%"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range b b 12 NULL 1 where used +1 SIMPLE t1 range b b 12 NULL 1 where used select * from t1 where a is null; a b c NULL 7 0 @@ -152,10 +152,10 @@ INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4 INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL); explain select id from t1 where uniq_id is null; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref idx1 idx1 5 const 1 where used +1 SIMPLE t1 ref idx1 idx1 5 const 1 where used explain select id from t1 where uniq_id =1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 const idx1 idx1 5 const 1 +1 SIMPLE t1 const idx1 idx1 5 const 1 UPDATE t1 SET id=id+100 where uniq_id is null; UPDATE t2 SET id=id+100 where uniq_id is null; select id from t1 where uniq_id is null; diff --git a/mysql-test/r/odbc.result b/mysql-test/r/odbc.result index eb6123075fe..f377d54e1a0 100644 --- a/mysql-test/r/odbc.result +++ b/mysql-test/r/odbc.result @@ -11,5 +11,5 @@ select * from t1 where a is null; a b explain select * from t1 where b is null; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST Impossible WHERE noticed after reading const tables +1 SIMPLE Impossible WHERE noticed after reading const tables drop table t1; diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result index 08d52a782e1..563aa178c87 100644 --- a/mysql-test/r/order_by.result +++ b/mysql-test/r/order_by.result @@ -264,13 +264,13 @@ create table t1 (a int not null, b int, c varchar(10), key (a, b, c)); insert into t1 values (1, NULL, NULL), (1, NULL, 'b'), (1, 1, NULL), (1, 1, 'b'), (1, 1, 'b'), (2, 1, 'a'), (2, 1, 'b'), (2, 2, 'a'), (2, 2, 'b'), (2, 3, 'c'),(1,3,'b'); explain select * from t1 where (a = 1 and b is null and c = 'b') or (a > 2) order by a desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 20 NULL 2 where used; Using index +1 SIMPLE t1 range a a 20 NULL 2 where used; Using index select * from t1 where (a = 1 and b is null and c = 'b') or (a > 2) order by a desc; a b c 1 NULL b explain select * from t1 where a >= 1 and a < 3 order by a desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 4 NULL 10 where used; Using index +1 SIMPLE t1 range a a 4 NULL 10 where used; Using index select * from t1 where a >= 1 and a < 3 order by a desc; a b c 2 3 c @@ -286,7 +286,7 @@ a b c 1 NULL NULL explain select * from t1 where a = 1 order by a desc, b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a a 4 const 5 where used; Using index +1 SIMPLE t1 ref a a 4 const 5 where used; Using index select * from t1 where a = 1 order by a desc, b desc; a b c 1 3 b @@ -297,34 +297,34 @@ a b c 1 NULL NULL explain select * from t1 where a = 1 and b is null order by a desc, b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a a 9 const,const 2 where used; Using index; Using filesort +1 SIMPLE t1 ref a a 9 const,const 2 where used; Using index; Using filesort select * from t1 where a = 1 and b is null order by a desc, b desc; a b c 1 NULL NULL 1 NULL b explain select * from t1 where a >= 1 and a < 3 and b >0 order by a desc,b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 9 NULL 8 where used; Using index; Using filesort +1 SIMPLE t1 range a a 9 NULL 8 where used; Using index; Using filesort explain select * from t1 where a = 2 and b >0 order by a desc,b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 9 NULL 5 where used; Using index +1 SIMPLE t1 range a a 9 NULL 5 where used; Using index explain select * from t1 where a = 2 and b is null order by a desc,b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref a a 9 const,const 1 where used; Using index; Using filesort +1 SIMPLE t1 ref a a 9 const,const 1 where used; Using index; Using filesort explain select * from t1 where a = 2 and (b is null or b > 0) order by a desc,b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 9 NULL 6 where used; Using index +1 SIMPLE t1 range a a 9 NULL 6 where used; Using index explain select * from t1 where a = 2 and b > 0 order by a desc,b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 9 NULL 5 where used; Using index +1 SIMPLE t1 range a a 9 NULL 5 where used; Using index explain select * from t1 where a = 2 and b < 2 order by a desc,b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 9 NULL 2 where used; Using index; Using filesort +1 SIMPLE t1 range a a 9 NULL 2 where used; Using index; Using filesort alter table t1 modify b int not null, modify c varchar(10) not null; explain select * from t1 order by a, b, c; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL a 18 NULL 11 Using index +1 SIMPLE t1 index NULL a 18 NULL 11 Using index select * from t1 order by a, b, c; a b c 1 0 @@ -340,7 +340,7 @@ a b c 2 3 c explain select * from t1 order by a desc, b desc, c desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL a 18 NULL 11 Using index +1 SIMPLE t1 index NULL a 18 NULL 11 Using index select * from t1 order by a desc, b desc, c desc; a b c 2 3 c @@ -356,14 +356,14 @@ a b c 1 0 explain select * from t1 where (a = 1 and b = 1 and c = 'b') or (a > 2) order by a desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 18 NULL 3 where used; Using index +1 SIMPLE t1 range a a 18 NULL 3 where used; Using index select * from t1 where (a = 1 and b = 1 and c = 'b') or (a > 2) order by a desc; a b c 1 1 b 1 1 b explain select * from t1 where a < 2 and b <= 1 order by a desc, b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 4 NULL 6 where used; Using index +1 SIMPLE t1 range a a 4 NULL 6 where used; Using index select * from t1 where a < 2 and b <= 1 order by a desc, b desc; a b c 1 1 b @@ -387,7 +387,7 @@ a b c 1 1 explain select * from t1 where a between 1 and 3 and b <= 1 order by a desc, b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 8 NULL 10 where used; Using index +1 SIMPLE t1 range a a 8 NULL 10 where used; Using index select * from t1 where a between 1 and 3 and b <= 1 order by a desc, b desc; a b c 2 1 b @@ -399,7 +399,7 @@ a b c 1 0 explain select * from t1 where a between 0 and 1 order by a desc, b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 range a a 4 NULL 5 where used; Using index +1 SIMPLE t1 range a a 4 NULL 5 where used; Using index select * from t1 where a between 0 and 1 order by a desc, b desc; a b c 1 3 b @@ -450,24 +450,24 @@ gid sid uid 103853 5 250 EXPLAIN select t1.gid, t2.sid, t3.uid from t3, t2, t1 where t2.gid = t1.gid and t2.uid = t3.uid order by t1.gid, t3.uid; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index PRIMARY PRIMARY 4 NULL 6 Using index -1 FIRST t2 eq_ref PRIMARY,uid PRIMARY 4 t1.gid 1 -1 FIRST t3 eq_ref PRIMARY PRIMARY 2 t2.uid 1 where used; Using index +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 6 Using index +1 SIMPLE t2 eq_ref PRIMARY,uid PRIMARY 4 t1.gid 1 +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 2 t2.uid 1 where used; Using index EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t1.gid,t3.skr; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index PRIMARY PRIMARY 4 NULL 6 Using index -1 FIRST t3 eq_ref PRIMARY PRIMARY 2 t1.gid 1 where used +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 6 Using index +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 2 t1.gid 1 where used EXPLAIN SELECT t1.gid, t2.sid, t3.uid from t2, t1, t3 where t2.gid = t1.gid and t2.uid = t3.uid order by t3.uid, t1.gid; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index PRIMARY PRIMARY 4 NULL 6 Using index; Using temporary; Using filesort -1 FIRST t2 eq_ref PRIMARY,uid PRIMARY 4 t1.gid 1 -1 FIRST t3 eq_ref PRIMARY PRIMARY 2 t2.uid 1 where used; Using index +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 6 Using index; Using temporary; Using filesort +1 SIMPLE t2 eq_ref PRIMARY,uid PRIMARY 4 t1.gid 1 +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 2 t2.uid 1 where used; Using index EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.gid = t3.uid order by t3.skr,t1.gid; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index PRIMARY PRIMARY 4 NULL 6 Using index; Using temporary; Using filesort -1 FIRST t3 eq_ref PRIMARY PRIMARY 2 t1.gid 1 where used +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 6 Using index; Using temporary; Using filesort +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 2 t1.gid 1 where used EXPLAIN SELECT t1.gid, t3.uid from t1, t3 where t1.skr = t3.uid order by t1.gid,t3.skr; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort -1 FIRST t3 eq_ref PRIMARY PRIMARY 2 t1.skr 1 where used +1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 2 t1.skr 1 where used drop table t1,t2,t3; diff --git a/mysql-test/r/range.result b/mysql-test/r/range.result index 722a1f5c62c..b10738a9505 100644 --- a/mysql-test/r/range.result +++ b/mysql-test/r/range.result @@ -16,7 +16,7 @@ event_date type event_id 1999-07-14 100600 10 explain select event_date,type,event_id from t1 WHERE type = 100601 and event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST Impossible WHERE +1 SIMPLE Impossible WHERE select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND (type=100600 OR type=100100) or event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND type=100099; event_date type event_id 1999-07-10 100100 24 diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 8b3e2aa298e..8c7f3326912 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -1328,19 +1328,19 @@ select t2.fld3 from t2 where fld3 LIKE 'don_t_find_me_please%'; fld3 explain select t2.fld3 from t2 where fld3 = 'honeysuckle'; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 ref fld3 fld3 30 const 1 where used; Using index +1 SIMPLE t2 ref fld3 fld3 30 const 1 where used; Using index explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle'; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 index NULL fld3 30 NULL 1199 where used; Using index +1 SIMPLE t2 index NULL fld3 30 NULL 1199 where used; Using index explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle'; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 index NULL fld3 30 NULL 1199 where used; Using index +1 SIMPLE t2 index NULL fld3 30 NULL 1199 where used; Using index explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle'; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 ref fld3 fld3 30 const 1 where used; Using index +1 SIMPLE t2 ref fld3 fld3 30 const 1 where used; Using index explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle'; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 ref fld3 fld3 30 const 1 where used; Using index +1 SIMPLE t2 ref fld3 fld3 30 const 1 where used; Using index explain select fld3 from t2 ignore index (fld3,not_used); Key column 'not_used' doesn't exist in table explain select fld3 from t2 use index (not_used); @@ -1351,7 +1351,7 @@ honeysuckle honoring explain select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 range fld3 fld3 30 NULL 2 where used; Using index +1 SIMPLE t2 range fld3 fld3 30 NULL 2 where used; Using index select fld1,fld3 from t2 where fld3="Colombo" or fld3 = "nondecreasing" order by fld3; fld1 fld3 148504 Colombo @@ -1371,7 +1371,7 @@ fld1 250502 explain select fld1 from t2 where fld1=250501 or fld1="250502"; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 range fld1 fld1 4 NULL 2 where used; Using index +1 SIMPLE t2 range fld1 fld1 4 NULL 2 where used; Using index select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502; fld1 250501 @@ -1380,7 +1380,7 @@ fld1 250601 explain select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 range fld1 fld1 4 NULL 4 where used; Using index +1 SIMPLE t2 range fld1 fld1 4 NULL 4 where used; Using index select fld1,fld3 from t2 where companynr = 37 and fld3 like 'f%'; fld1 fld3 218401 faithful @@ -1807,8 +1807,8 @@ select distinct fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr orde fld3 explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 ALL fld1 NULL NULL NULL 1199 where used; Using temporary; Using filesort -1 FIRST t3 eq_ref PRIMARY PRIMARY 4 t2.fld1 1 where used; Using index +1 SIMPLE t2 ALL fld1 NULL NULL NULL 1199 where used; Using temporary; Using filesort +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 t2.fld1 1 where used; Using index select period from t1; period 9410 @@ -1822,8 +1822,8 @@ fld3 period breaking 1001 explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 const fld1 fld1 4 const 1 -1 FIRST t3 const PRIMARY,period PRIMARY 4 const 1 +1 SIMPLE t2 const fld1 fld1 4 const 1 +1 SIMPLE t3 const PRIMARY,period PRIMARY 4 const 1 select fld3,period from t2,t1 where companynr*10 = 37*10; fld3 period breaking 9410 @@ -2562,20 +2562,20 @@ select t2.companynr,companyname from t2 left join t4 using (companynr) where t4. companynr companyname explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 ALL NULL NULL NULL NULL 1199 -1 FIRST t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 where used; Not exists +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 where used; Not exists explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t4 ALL NULL NULL NULL NULL 12 -1 FIRST t2 ALL NULL NULL NULL NULL 1199 where used; Not exists +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 where used; Not exists select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1; companynr companynr 37 36 41 40 explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 ALL NULL NULL NULL NULL 1199 Using temporary -1 FIRST t4 index NULL PRIMARY 1 NULL 12 where used; Using index +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using temporary +1 SIMPLE t4 index NULL PRIMARY 1 NULL 12 where used; Using index select t2.fld1,t2.companynr,fld3,period from t3,t2 where t2.fld1 = 38208 and t2.fld1=t3.t2nr and period = 1008 or t2.fld1 = 38008 and t2.fld1 =t3.t2nr and period = 1008; fld1 companynr fld3 period 038008 37 reporters 1008 @@ -3085,10 +3085,10 @@ fld1 sum(price) 038008 234298 explain select fld3 from t2 where 1>2 or 2>3; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST Impossible WHERE +1 SIMPLE Impossible WHERE explain select fld3 from t2 where fld1=fld1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 ALL NULL NULL NULL NULL 1199 +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 select companynr,fld1 from t2 HAVING fld1=250501 or fld1=250502; companynr fld1 34 250501 @@ -3140,7 +3140,7 @@ count(*) 4181 explain select min(fld1),max(fld1),count(*) from t2; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST Select tables optimized away +1 SIMPLE Select tables optimized away select min(fld1),max(fld1),count(*) from t2; min(fld1) max(fld1) count(*) 0 1232609 1199 diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 5a96cc08cbf..aa058a97109 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -49,7 +49,7 @@ a b explain select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a); id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 ALL NULL NULL NULL NULL 2 where used +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 where used 3 UNION t4 ALL NULL NULL NULL NULL 3 where used; Using filesort 4 SUBSELECT t2 ALL NULL NULL NULL NULL 2 2 SUBSELECT t3 ALL NULL NULL NULL NULL 3 Using filesort @@ -65,7 +65,7 @@ explain select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from (select * from t2 where a>1) as tt; id select_type table type possible_keys key key_len ref rows Extra 3 DERIVED t2 ALL NULL NULL NULL NULL 2 where used -1 FIRST system NULL NULL NULL NULL 1 +1 PRIMARY system NULL NULL NULL NULL 1 2 SUBSELECT t3 ALL NULL NULL NULL NULL 3 where used; Using filesort select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1); a @@ -82,7 +82,7 @@ b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) 9 7.5000 explain select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t4 ALL NULL NULL NULL NULL 3 +1 PRIMARY t4 ALL NULL NULL NULL NULL 3 2 DEPENDENT SUBSELECT t2 ALL NULL NULL NULL NULL 2 3 DEPENDENT SUBSELECT t3 ALL NULL NULL NULL NULL 3 where used select * from t3 where exists (select * from t2 where t2.b=t3.a); @@ -117,7 +117,7 @@ NULL 1 2 2 explain select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t2 ALL NULL NULL NULL NULL 2 +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 2 DEPENDENT SUBSELECT t1 system NULL NULL NULL NULL 1 where used 3 DEPENDENT UNION t5 ALL NULL NULL NULL NULL 2 where used select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index 51148cd12e9..22cfd2ceefa 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -76,5 +76,5 @@ date numfacture expedition 0000-00-00 00:00:00 1212 0001-00-00 00:00:00 EXPLAIN SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00'; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref expedition expedition 8 const 1 where used +1 SIMPLE t1 ref expedition expedition 8 const 1 where used drop table t1; diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index 86f62d11bdb..c64ee2ecd78 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -86,29 +86,29 @@ a b 1 a explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 2 UNION t2 ALL NULL NULL NULL NULL 4 Using filesort select found_rows(); FOUND_ROWS() 0 explain select a,b from t1 union all select a,b from t2; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 2 UNION t2 ALL NULL NULL NULL NULL 4 explain select xx from t1 union select 1; Unknown column 'xx' in 'field list' explain select a,b from t1 union select 1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 4 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 2 UNION No tables used explain select 1 union select a,b from t1 union select 1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST No tables used +1 PRIMARY No tables used 2 UNION t1 ALL NULL NULL NULL NULL 4 3 UNION No tables used explain select a,b from t1 union select 1 limit 0; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST Impossible WHERE +1 PRIMARY Impossible WHERE 2 UNION Impossible WHERE select a,b from t1 into outfile 'skr' union select a,b from t2; Wrong usage of UNION and INTO diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result index 10cb4fe5c8e..9b2c0316c18 100644 --- a/mysql-test/r/user_var.result +++ b/mysql-test/r/user_var.result @@ -19,14 +19,14 @@ i @vv1:=if(sv1.i,1,0) @vv2:=if(sv2.i,1,0) @vv3:=if(sv3.i,1,0) @vv1+@vv2+@vv3 2 1 0 0 1 explain select * from t1 where i=@vv1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref i i 4 const 1 where used +1 SIMPLE t1 ref i i 4 const 1 where used explain select * from t1 where @vv1:=@vv1+1 and i=@vv1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ALL NULL NULL NULL NULL 3 where used +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 where used explain select @vv1:=i from t1 where i=@vv1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 index NULL i 4 NULL 3 where used; Using index +1 SIMPLE t1 index NULL i 4 NULL 3 where used; Using index explain select * from t1 where i=@vv1; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 ref i i 4 const 1 where used +1 SIMPLE t1 ref i i 4 const 1 where used drop table t1,t2; diff --git a/mysql-test/r/varbinary.result b/mysql-test/r/varbinary.result index a7bd29afd78..1b6cf5e708e 100644 --- a/mysql-test/r/varbinary.result +++ b/mysql-test/r/varbinary.result @@ -12,7 +12,7 @@ insert into t1 set UNIQ=0x38afba1d73e6a18a; insert into t1 set UNIQ=123; explain select * from t1 where UNIQ=0x38afba1d73e6a18a; id select_type table type possible_keys key key_len ref rows Extra -1 FIRST t1 const UNIQ UNIQ 8 const 1 +1 SIMPLE t1 const UNIQ UNIQ 8 const 1 drop table t1; select x'hello'; You have an error in your SQL syntax near 'x'hello'' at line 1 diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 8166a156b8c..a898df89383 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1443,7 +1443,9 @@ mysql_execute_command(void) { SELECT_LEX *first= sl->master_unit()->first_select(); res= mysql_explain_select(thd, sl, - ((select_lex==sl)?"FIRST": + ((select_lex==sl)? + ((sl->next_select_in_list())?"PRIMARY": + "SIMPLE"): ((sl == first)? ((sl->depended)?"DEPENDENT SUBSELECT": "SUBSELECT"): From 9e5a4be4605cf71c5e3d6c07283c95fc4f29db70 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 4 Oct 2002 16:41:09 +0500 Subject: [PATCH 6/6] a bit speeding-up of key_cmp() function --- mysys/my_handler.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/mysys/my_handler.c b/mysys/my_handler.c index 5b68b427f3a..fe610b73fe9 100644 --- a/mysys/my_handler.c +++ b/mysys/my_handler.c @@ -78,10 +78,9 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, uint32 u_1,u_2; float f_1,f_2; double d_1,d_2; - uint next_key_length; *diff_pos=0; - for ( ; (int) key_length >0 ; key_length=next_key_length, keyseg++) + for ( ; (int) key_length >0 ; keyseg++) { uchar *end; uint piks=! (keyseg->flag & HA_NO_SORT); @@ -101,12 +100,10 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, { if (nextflag == (SEARCH_FIND | SEARCH_UPDATE)) nextflag=SEARCH_SAME; /* Allow duplicate keys */ - next_key_length=key_length; continue; /* To next key part */ } } end= a+ min(keyseg->length,key_length); - next_key_length=key_length-keyseg->length; switch ((enum ha_base_keytype) keyseg->type) { case HA_KEYTYPE_TEXT: /* Ascii; Key is converted */ @@ -115,12 +112,12 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, int a_length,b_length,pack_length; get_key_length(a_length,a); get_key_pack_length(b_length,pack_length,b); - next_key_length=key_length-b_length-pack_length; + key_length-= b_length + pack_length; if (piks && (flag= mi_compare_text(keyseg->charset,a,a_length,b,b_length, (my_bool) ((nextflag & SEARCH_PREFIX) && - next_key_length <= 0)))) + key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a+=a_length; b+=b_length; @@ -129,6 +126,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, else { uint length=(uint) (end-a), a_length=length, b_length=length; + key_length-= keyseg->length; if (!(nextflag & SEARCH_PREFIX)) { while (a_length && a[a_length-1] == ' ') @@ -139,7 +137,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, if (piks && (flag= mi_compare_text(keyseg->charset,a,a_length,b,b_length, (my_bool) ((nextflag & SEARCH_PREFIX) && - next_key_length <= 0)))) + key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a=end; b+=length; @@ -151,12 +149,12 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, int a_length,b_length,pack_length; get_key_length(a_length,a); get_key_pack_length(b_length,pack_length,b); - next_key_length=key_length-b_length-pack_length; + key_length-= b_length + pack_length; if (piks && (flag=compare_bin(a,a_length,b,b_length, (my_bool) ((nextflag & SEARCH_PREFIX) && - next_key_length <= 0)))) + key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a+=a_length; b+=b_length; @@ -165,10 +163,11 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, else { uint length=keyseg->length; + key_length-= keyseg->length; if (piks && (flag=compare_bin(a,length,b,length, (my_bool) ((nextflag & SEARCH_PREFIX) && - next_key_length <= 0)))) + key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a+=length; b+=length; @@ -179,12 +178,12 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, int a_length,b_length,pack_length; get_key_length(a_length,a); get_key_pack_length(b_length,pack_length,b); - next_key_length=key_length-b_length-pack_length; + key_length-= b_length + pack_length; if (piks && (flag= mi_compare_text(keyseg->charset,a,a_length,b,b_length, (my_bool) ((nextflag & SEARCH_PREFIX) && - next_key_length <= 0)))) + key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a+=a_length; b+=b_length; @@ -196,12 +195,12 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, int a_length,b_length,pack_length; get_key_length(a_length,a); get_key_pack_length(b_length,pack_length,b); - next_key_length=key_length-b_length-pack_length; + key_length-= b_length + pack_length; if (piks && (flag=compare_bin(a,a_length,b,b_length, (my_bool) ((nextflag & SEARCH_PREFIX) && - next_key_length <= 0)))) + key_length <= 0)))) return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a+=a_length; b+=b_length; @@ -216,6 +215,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b++; + key_length-= keyseg->length; break; } case HA_KEYTYPE_SHORT_INT: @@ -225,6 +225,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 2; /* sizeof(short int); */ + key_length-= keyseg->length; break; case HA_KEYTYPE_USHORT_INT: { @@ -235,6 +236,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+=2; /* sizeof(short int); */ + key_length-= keyseg->length; break; } case HA_KEYTYPE_LONG_INT: @@ -244,6 +246,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 4; /* sizeof(long int); */ + key_length-= keyseg->length; break; case HA_KEYTYPE_ULONG_INT: u_1= mi_sint4korr(a); @@ -252,6 +255,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 4; /* sizeof(long int); */ + key_length-= keyseg->length; break; case HA_KEYTYPE_INT24: l_1=mi_sint3korr(a); @@ -260,6 +264,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 3; + key_length-= keyseg->length; break; case HA_KEYTYPE_UINT24: l_1=mi_uint3korr(a); @@ -268,6 +273,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 3; + key_length-= keyseg->length; break; case HA_KEYTYPE_FLOAT: mi_float4get(f_1,a); @@ -276,6 +282,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 4; /* sizeof(float); */ + key_length-= keyseg->length; break; case HA_KEYTYPE_DOUBLE: mi_float8get(d_1,a); @@ -284,6 +291,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 8; /* sizeof(double); */ + key_length-= keyseg->length; break; case HA_KEYTYPE_NUM: /* Numeric key */ { @@ -300,7 +308,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, { alength= *a++; blength= *b++; end=a+alength; - next_key_length=key_length-blength-1; + key_length-= blength + 1; } else { @@ -309,6 +317,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, /* remove pre space from keys */ for ( ; alength && *a == ' ' ; a++, alength--) ; for ( ; blength && *b == ' ' ; b++, blength--) ; + key_length-= keyseg->length; } if (piks) @@ -360,6 +369,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 8; + key_length-= keyseg->length; break; } case HA_KEYTYPE_ULONGLONG: @@ -371,6 +381,7 @@ int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, return ((keyseg->flag & HA_REVERSE_SORT) ? -flag : flag); a= end; b+= 8; + key_length-= keyseg->length; break; } #endif