mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 04:53:01 +01:00
Merge sanja.is.com.ua:/home/bell/mysql/mysql-4.1
into sanja.is.com.ua:/home/bell/mysql/work-distinct-4.1
This commit is contained in:
commit
8c547fae57
6 changed files with 116 additions and 45 deletions
|
@ -54,9 +54,9 @@ 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 PRIMARY t2 ALL NULL NULL NULL NULL 2 where used
|
||||
2 SUBSELECT t3 ALL NULL NULL NULL NULL 3 Using filesort
|
||||
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 a<t2.a*4 order by 1 desc limit 1), a from t2;
|
||||
(select a from t3 where a<t2.a*4 order by 1 desc limit 1) a
|
||||
3 1
|
||||
|
@ -163,9 +163,7 @@ UNIQUE KEY `email` (`email`)
|
|||
INSERT INTO inscrit (pseudo,email) VALUES ('joce','test');
|
||||
INSERT INTO inscrit (pseudo,email) VALUES ('joce1','test1');
|
||||
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');
|
||||
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
|
||||
|
@ -183,3 +181,21 @@ joce
|
|||
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo LIKE '%joce%');
|
||||
Subselect returns more than 1 record
|
||||
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit;
|
||||
drop table if exists searchconthardwarefr3;
|
||||
CREATE TABLE `searchconthardwarefr3` (
|
||||
`topic` mediumint(8) unsigned NOT NULL default '0',
|
||||
`date` date NOT NULL default '0000-00-00',
|
||||
`pseudo` varchar(35) character set latin1 NOT NULL default '',
|
||||
PRIMARY KEY (`pseudo`,`date`,`topic`),
|
||||
KEY `topic` (`topic`)
|
||||
) TYPE=MyISAM ROW_FORMAT=DYNAMIC;
|
||||
INSERT INTO searchconthardwarefr3 (topic,date,pseudo) VALUES
|
||||
('43506','2002-10-02','joce'),('40143','2002-08-03','joce');
|
||||
EXPLAIN SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03';
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE searchconthardwarefr3 index NULL PRIMARY 41 NULL 2 where used; Using index
|
||||
EXPLAIN SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03');
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY No tables used
|
||||
2 SUBSELECT searchconthardwarefr3 index NULL PRIMARY 41 NULL 2 where used; Using index
|
||||
drop table searchconthardwarefr3;
|
||||
|
|
|
@ -83,9 +83,7 @@ CREATE TABLE `inscrit` (
|
|||
INSERT INTO inscrit (pseudo,email) VALUES ('joce','test');
|
||||
INSERT INTO inscrit (pseudo,email) VALUES ('joce1','test1');
|
||||
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');
|
||||
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
|
||||
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo,email FROM
|
||||
inscrit WHERE pseudo='joce');
|
||||
|
@ -96,4 +94,18 @@ SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo
|
|||
-- error 1240
|
||||
SELECT pseudo FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo LIKE '%joce%');
|
||||
|
||||
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit;
|
||||
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit;
|
||||
|
||||
drop table if exists searchconthardwarefr3;
|
||||
CREATE TABLE `searchconthardwarefr3` (
|
||||
`topic` mediumint(8) unsigned NOT NULL default '0',
|
||||
`date` date NOT NULL default '0000-00-00',
|
||||
`pseudo` varchar(35) character set latin1 NOT NULL default '',
|
||||
PRIMARY KEY (`pseudo`,`date`,`topic`),
|
||||
KEY `topic` (`topic`)
|
||||
) TYPE=MyISAM ROW_FORMAT=DYNAMIC;
|
||||
INSERT INTO searchconthardwarefr3 (topic,date,pseudo) VALUES
|
||||
('43506','2002-10-02','joce'),('40143','2002-08-03','joce');
|
||||
EXPLAIN SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03';
|
||||
EXPLAIN SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03');
|
||||
drop table searchconthardwarefr3;
|
|
@ -392,6 +392,8 @@ int mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &list,COND *conds,
|
|||
SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex,
|
||||
bool fake_select_lex);
|
||||
void fix_tables_pointers(SELECT_LEX *select_lex);
|
||||
int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
|
||||
select_result *result);
|
||||
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);
|
||||
|
|
|
@ -955,6 +955,7 @@ void st_select_lex::init_query()
|
|||
table_list.first= 0;
|
||||
table_list.next= (byte**) &table_list.first;
|
||||
item_list.empty();
|
||||
join= 0;
|
||||
}
|
||||
|
||||
void st_select_lex::init_select()
|
||||
|
@ -973,7 +974,6 @@ void st_select_lex::init_select()
|
|||
ftfunc_list= &ftfunc_list_alloc;
|
||||
linkage= UNSPECIFIED_TYPE;
|
||||
depended= having_fix_field= 0;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1485,24 +1485,7 @@ mysql_execute_command(THD *thd)
|
|||
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)?
|
||||
((sl->next_select_in_list())?"PRIMARY":
|
||||
"SIMPLE"):
|
||||
((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
|
||||
res= mysql_explain_union(thd, &thd->lex.unit, explain_result);
|
||||
MYSQL_LOCK *save_lock= thd->lock;
|
||||
thd->lock= (MYSQL_LOCK *)0;
|
||||
explain_result->send_eof();
|
||||
|
|
|
@ -213,7 +213,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;
|
||||
|
@ -348,7 +348,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)
|
||||
|
@ -1018,36 +1018,60 @@ mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds,
|
|||
SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex,
|
||||
bool fake_select_lex)
|
||||
{
|
||||
JOIN *join = new JOIN(thd, fields, select_options, result);
|
||||
|
||||
DBUG_ENTER("mysql_select");
|
||||
thd->proc_info="init";
|
||||
thd->used_tables=0; // Updated by setup_fields
|
||||
|
||||
if (join->prepare(tables, conds, order, group, having, proc_param,
|
||||
select_lex, unit, fake_select_lex))
|
||||
bool free_join= 1;
|
||||
JOIN *join;
|
||||
if (!fake_select_lex && select_lex->join != 0)
|
||||
{
|
||||
DBUG_RETURN(-1);
|
||||
//here is EXPLAIN of subselect or derived table
|
||||
join= select_lex->join;
|
||||
join->result= result;
|
||||
if (!join->procedure && result->prepare(join->fields_list, unit))
|
||||
{
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
join->select_options= select_options;
|
||||
free_join= 0;
|
||||
}
|
||||
switch (join->optimize()) {
|
||||
else
|
||||
{
|
||||
join= new JOIN(thd, fields, select_options, result);
|
||||
thd->proc_info="init";
|
||||
thd->used_tables=0; // Updated by setup_fields
|
||||
|
||||
if (join->prepare(tables, conds, order, group, having, proc_param,
|
||||
select_lex, unit, fake_select_lex))
|
||||
{
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
}
|
||||
|
||||
switch (join->optimize())
|
||||
{
|
||||
case 1:
|
||||
DBUG_RETURN(join->error);
|
||||
case -1:
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (join->global_optimize())
|
||||
if (free_join && join->global_optimize())
|
||||
goto err;
|
||||
|
||||
join->exec();
|
||||
|
||||
err:
|
||||
thd->limit_found_rows = join->send_records;
|
||||
thd->examined_row_count = join->examined_rows;
|
||||
thd->proc_info="end";
|
||||
int error= (fake_select_lex?0:join->cleanup(thd)) || thd->net.report_error;
|
||||
delete join;
|
||||
DBUG_RETURN(error);
|
||||
if (free_join)
|
||||
{
|
||||
thd->limit_found_rows = join->send_records;
|
||||
thd->examined_row_count = join->examined_rows;
|
||||
thd->proc_info="end";
|
||||
int error= (fake_select_lex?0:join->cleanup(thd)) || thd->net.report_error;
|
||||
delete join;
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
else
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
|
@ -7365,9 +7389,43 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
|
|||
result->send_error(0,NullS);
|
||||
}
|
||||
}
|
||||
for (SELECT_LEX_UNIT *unit= join->select_lex->first_inner_unit();
|
||||
unit;
|
||||
unit= unit->next_unit())
|
||||
{
|
||||
if (mysql_explain_union(thd, unit, result))
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
|
||||
{
|
||||
int res= 0;
|
||||
SELECT_LEX *first= unit->first_select();
|
||||
for (SELECT_LEX *sl= first;
|
||||
sl;
|
||||
sl= sl->next_select())
|
||||
{
|
||||
res= mysql_explain_select(thd, sl,
|
||||
(((&thd->lex.select_lex)==sl)?
|
||||
((sl->next_select_in_list())?"PRIMARY":
|
||||
"SIMPLE"):
|
||||
((sl == first)?
|
||||
((sl->depended)?"DEPENDENT SUBSELECT":
|
||||
"SUBSELECT"):
|
||||
((sl->depended)?"DEPENDENT UNION":
|
||||
"UNION"))),
|
||||
result);
|
||||
if (res)
|
||||
break;
|
||||
|
||||
}
|
||||
if (res > 0)
|
||||
res= -res; // mysql_explain_select do not report error
|
||||
return res;
|
||||
}
|
||||
|
||||
int mysql_explain_select(THD *thd, SELECT_LEX *select_lex, char const *type,
|
||||
select_result *result)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue