Commit d9f99816 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

fixed bug of multi-level EXPLAIN

parent f6d9e96f
...@@ -159,6 +159,14 @@ UNIQUE KEY `email` (`email`) ...@@ -159,6 +159,14 @@ UNIQUE KEY `email` (`email`)
INSERT INTO inscrit (pseudo,email) VALUES ('joce','test'); INSERT INTO inscrit (pseudo,email) VALUES ('joce','test');
INSERT INTO inscrit (pseudo,email) VALUES ('joce1','test1'); INSERT INTO inscrit (pseudo,email) VALUES ('joce1','test1');
INSERT INTO inscrit (pseudo,email) VALUES ('2joce1','2test1'); INSERT INTO inscrit (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN SELECT pseudo,(SELECT email FROM inscrit WHERE pseudo=(SELECT
pseudo FROM inscrit WHERE pseudo='joce')) FROM inscrit WHERE pseudo=(SELECT
pseudo FROM inscrit WHERE pseudo='joce');
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY inscrit const PRIMARY PRIMARY 35 const 1
4 SUBSELECT inscrit const PRIMARY PRIMARY 35 const 1
2 SUBSELECT inscrit const PRIMARY PRIMARY 35 const 1
3 SUBSELECT inscrit const PRIMARY PRIMARY 35 const 1
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo,email FROM SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo,email FROM
inscrit WHERE pseudo='joce'); inscrit WHERE pseudo='joce');
Subselect returns more than 1 field Subselect returns more than 1 field
......
...@@ -82,6 +82,9 @@ CREATE TABLE `inscrit` ( ...@@ -82,6 +82,9 @@ CREATE TABLE `inscrit` (
INSERT INTO inscrit (pseudo,email) VALUES ('joce','test'); INSERT INTO inscrit (pseudo,email) VALUES ('joce','test');
INSERT INTO inscrit (pseudo,email) VALUES ('joce1','test1'); INSERT INTO inscrit (pseudo,email) VALUES ('joce1','test1');
INSERT INTO inscrit (pseudo,email) VALUES ('2joce1','2test1'); INSERT INTO inscrit (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN SELECT pseudo,(SELECT email FROM inscrit WHERE pseudo=(SELECT
pseudo FROM inscrit WHERE pseudo='joce')) FROM inscrit WHERE pseudo=(SELECT
pseudo FROM inscrit WHERE pseudo='joce');
-- error 1239 -- error 1239
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo,email FROM SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo,email FROM
inscrit WHERE pseudo='joce'); inscrit WHERE pseudo='joce');
......
...@@ -212,7 +212,7 @@ subselect_single_select_engine::subselect_single_select_engine(THD *thd, ...@@ -212,7 +212,7 @@ subselect_single_select_engine::subselect_single_select_engine(THD *thd,
select_subselect *result, select_subselect *result,
Item_subselect *item): Item_subselect *item):
subselect_engine(thd, item, result), subselect_engine(thd, item, result),
executed(0), optimized(0) prepared(0), optimized(0), executed(0)
{ {
select_lex= select; select_lex= select;
SELECT_LEX_UNIT *unit= select_lex->master_unit(); SELECT_LEX_UNIT *unit= select_lex->master_unit();
...@@ -251,6 +251,9 @@ subselect_union_engine::subselect_union_engine(THD *thd, ...@@ -251,6 +251,9 @@ subselect_union_engine::subselect_union_engine(THD *thd,
int subselect_single_select_engine::prepare() int subselect_single_select_engine::prepare()
{ {
if (prepared)
return 0;
prepared= 1;
SELECT_LEX *save_select= thd->lex.select; SELECT_LEX *save_select= thd->lex.select;
thd->lex.select= select_lex; thd->lex.select= select_lex;
if(join->prepare((TABLE_LIST*) select_lex->table_list.first, if(join->prepare((TABLE_LIST*) select_lex->table_list.first,
......
...@@ -179,8 +179,9 @@ class subselect_engine ...@@ -179,8 +179,9 @@ class subselect_engine
class subselect_single_select_engine: public subselect_engine class subselect_single_select_engine: public subselect_engine
{ {
my_bool executed; /* simple subselect is executed */ my_bool prepared; /* simple subselect is prepared */
my_bool optimized; /* simple subselect is optimized */ my_bool optimized; /* simple subselect is optimized */
my_bool executed; /* simple subselect is executed */
st_select_lex *select_lex; /* corresponding select_lex */ st_select_lex *select_lex; /* corresponding select_lex */
JOIN * join; /* corresponding JOIN structure */ JOIN * join; /* corresponding JOIN structure */
public: public:
......
...@@ -944,7 +944,7 @@ void st_select_lex_unit::init_query() ...@@ -944,7 +944,7 @@ void st_select_lex_unit::init_query()
global_parameters= this; global_parameters= this;
select_limit_cnt= HA_POS_ERROR; select_limit_cnt= HA_POS_ERROR;
offset_limit_cnt= 0; offset_limit_cnt= 0;
optimized= 0; prepared= optimized= 0;
item= 0; item= 0;
} }
......
...@@ -227,6 +227,7 @@ class st_select_lex_unit: public st_select_lex_node { ...@@ -227,6 +227,7 @@ class st_select_lex_unit: public st_select_lex_node {
select_result *result; select_result *result;
int res; int res;
bool describe, found_rows_for_union, bool describe, found_rows_for_union,
prepared, //prepare phase already performed for UNION (unit)
optimized; // optimize phase already performed for UNION (unit) optimized; // optimize phase already performed for UNION (unit)
public: public:
/* /*
......
...@@ -104,11 +104,16 @@ bool select_union::flush() ...@@ -104,11 +104,16 @@ bool select_union::flush()
typedef JOIN * JOIN_P; typedef JOIN * JOIN_P;
int st_select_lex_unit::prepare(THD *thd, select_result *result) int st_select_lex_unit::prepare(THD *thd, select_result *result)
{ {
DBUG_ENTER("st_select_lex_unit::prepare");
if (prepared)
DBUG_RETURN(0);
prepared= 1;
describe=(first_select()->options & SELECT_DESCRIBE) ? 1 : 0; describe=(first_select()->options & SELECT_DESCRIBE) ? 1 : 0;
res= 0; res= 0;
found_rows_for_union= false; found_rows_for_union= false;
TMP_TABLE_PARAM tmp_table_param; TMP_TABLE_PARAM tmp_table_param;
DBUG_ENTER("st_select_lex_unit::prepare");
this->thd= thd; this->thd= thd;
this->result= result; this->result= result;
SELECT_LEX *lex_select_save= thd->lex.select; SELECT_LEX *lex_select_save= thd->lex.select;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment