Commit 0a689e6c authored by unknown's avatar unknown

many bug fixes


mysql-test/r/derived.result:
  test for a bug fix which caused a deadlock !
  Also test for a bug fix with using() on derived tables
mysql-test/r/subselect.result:
  correcting previous changes caused by a bug ..
mysql-test/t/derived.test:
  test for a bug fix which caused a deadlock !
  Also test for a bug fix with using() on derived tables
mysql-test/t/subselect.test:
  corrections of previous changes caused by a bug ..
sql/sql_base.cc:
  A for for a bug which caused a deadlock !
  Also fix for a bug with using() on derived tables
sql/sql_derived.cc:
  code cleanup
sql/sql_lex.cc:
  fix for deadlock
parent 6df255d9
......@@ -64,7 +64,13 @@ a t
18 18
19 19
20 20
explain select count(*) from t1 as tt1, (select * from t1) as tt2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE Select tables optimized away
drop table if exists t1;
SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a) as a )) as b;
(SELECT * FROM (SELECT 1 as a) as a )
1
select * from (select 1 as a) b left join (select 2 as a) c using(a);
a a
1 NULL
......@@ -17,14 +17,14 @@ SELECT (SELECT 1),MAX(1) FROM (SELECT 1) as a;
1 1
SELECT (SELECT a) as a;
Reference 'a' not supported (forward reference in item list)
EXPLAIN SELECT 1,a FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
EXPLAIN SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1
3 DEPENDENT SUBSELECT No tables used
2 DERIVED No tables used
SELECT 1,a FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
1 a
1 1
SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
1
1
SELECT (SELECT 1), a;
Unknown column 'a' in 'field list'
SELECT 1 as a FROM (SELECT 1) as b HAVING (SELECT a)=1;
......@@ -387,9 +387,9 @@ id select_type table type possible_keys key key_len ref rows Extra
drop table t1;
CREATE TABLE t1 (a int(1));
INSERT INTO t1 VALUES (1);
SELECT 1,a FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
1 a
1 1
SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
1
1
drop table t1;
create table t1 (a int NOT NULL, b int, primary key (a));
create table t2 (a int NOT NULL, b int, primary key (a));
......
......@@ -33,5 +33,7 @@ while ($1)
}
enable_query_log;
SELECT * FROM (SELECT * FROM t1) as b ORDER BY a ASC LIMIT 0,20;
explain select count(*) from t1 as tt1, (select * from t1) as tt2;
drop table if exists t1;
SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a) as a )) as b;
select * from (select 1 as a) b left join (select 2 as a) c using(a);
......@@ -8,8 +8,8 @@ SELECT (SELECT 1 FROM (SELECT 1) as b HAVING b=1) as a,(SELECT 1 FROM (SELECT 1)
SELECT (SELECT 1),MAX(1) FROM (SELECT 1) as a;
-- error 1245
SELECT (SELECT a) as a;
EXPLAIN SELECT 1,a FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
SELECT 1,a FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
EXPLAIN SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
-- error 1054
SELECT (SELECT 1), a;
SELECT 1 as a FROM (SELECT 1) as b HAVING (SELECT a)=1;
......@@ -230,7 +230,7 @@ drop table t1;
CREATE TABLE t1 (a int(1));
INSERT INTO t1 VALUES (1);
SELECT 1,a FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
drop table t1;
#update with subselects
......
......@@ -1894,13 +1894,13 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
const char *name=item->field_name;
uint length=(uint) strlen(name);
if (table_name)
if (table_name && table_name[0])
{ /* Qualified field */
bool found_table=0;
for (; tables ; tables=tables->next)
{
if (!strcmp(tables->alias,table_name) &&
(!db || !strcmp(db,tables->db)))
(!db || !tables->db || !tables->db[0] || !strcmp(db,tables->db)))
{
found_table=1;
Field *find=find_field_in_table(thd,tables->table,name,length,
......
......@@ -106,9 +106,9 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t)
t->table=table;
table->derived_select_number= sl->select_number;
table->tmp_table=TMP_TABLE;
if (!lex->describe)
if (lex->describe)
sl->exclude();
t->db=(tables && tables->db) ? tables->db : (char *)"";
t->db=(char *)"";
t->derived=(SELECT_LEX *)0; // just in case ...
}
}
......
......@@ -1173,6 +1173,8 @@ bool st_select_lex_unit::create_total_list_n_last_return(THD *thd, st_lex *lex,
net_printf(thd,ER_WRONG_USAGE,"UNION","ORDER BY");
return 1;
}
if (sl->linkage == DERIVED_TABLE_TYPE)
continue;
for (SELECT_LEX_UNIT *inner= sl->first_inner_unit();
inner;
inner= inner->next_unit())
......
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