Many fixes.

I still have to make a test case for :

UPDATE from sub-select with derived table
parent 4158538d
......@@ -235,4 +235,19 @@ select * from t2;
n d
1 30
1 30
UPDATE t1 a ,t2 b SET t1.d=t2.d,t2.d=30 WHERE a.n=b.n;
select * from t1;
n d
1 30
3 2
select * from t2;
n d
1 30
1 30
DELETE t1, t2 FROM t1 a,t2 b where a.n=b.n;
select * from t1;
n d
3 2
select * from t2;
n d
drop table t1,t2;
......@@ -86,20 +86,20 @@ select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1);
a b
1 7
2 7
select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)
(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;
a b
1 7
2 7
3 8
select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)
(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);
a b
1 7
2 7
3 8
4 8
explain select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)
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 Using where
......
......@@ -213,4 +213,10 @@ insert into t2 values(1,10),(1,20);
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
select * from t1;
select * from t2;
UPDATE t1 a ,t2 b SET t1.d=t2.d,t2.d=30 WHERE a.n=b.n;
select * from t1;
select * from t2;
DELETE t1, t2 FROM t1 a,t2 b where a.n=b.n;
select * from t1;
select * from t2;
drop table t1,t2;
......@@ -44,11 +44,11 @@ select (select a from t3), a from t2;
select * from t2 where t2.a=(select a from t1);
insert into t3 values (6),(7),(3);
select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1);
select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)
(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)
(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)
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 a<t2.a*4 order by 1 desc limit 1), a from t2;
select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from
......
......@@ -1062,6 +1062,8 @@ void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used,
for (; tables_used; tables_used=tables_used->next)
{
DBUG_ASSERT(!using_transactions || tables_used->table!=0);
if (tables_used->derived)
continue;
if (using_transactions &&
tables_used->table->file->has_transactions())
/*
......
......@@ -168,14 +168,9 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, TABLE_LIST *t)
tables->table_list->table=tables->table; // to fix a problem in EXPLAIN
}
else
{
if (is_union)
unit->exclude();
else
sl->exclude();
}
unit->exclude();
t->db=(char *)"";
t->derived=(SELECT_LEX *)0; // just in case ...
t->derived=(SELECT_LEX *)1; // just in case ...
table->file->info(HA_STATUS_VARIABLE);
}
}
......
......@@ -3001,6 +3001,7 @@ mysql_init_query(THD *thd)
lex->select_lex.link_prev= (st_select_lex_node**)&(lex->all_selects_list);
lex->olap=lex->describe=0;
lex->derived_tables= false;
lex->lock_option=TL_UNLOCK;
thd->check_loops_counter= thd->select_number=
lex->select_lex.select_number= 1;
thd->free_list= 0;
......
......@@ -1469,7 +1469,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
end= int10_to_str((long) thd->query_id, buff, 10);
break;
case SHOW_RPL_STATUS:
end= int10_to_str((long) rpl_status_type[(int)rpl_status], buff, 10);
end= strmov(buff, rpl_status_type[(int)rpl_status]);
break;
case SHOW_SLAVE_RUNNING:
{
......
......@@ -1668,12 +1668,17 @@ select_init:
'(' SELECT_SYM select_part2 ')'
{
LEX *lex= Lex;
SELECT_LEX_NODE * sel= lex->current_select;
SELECT_LEX * sel= lex->current_select->select_lex();
if (sel->set_braces(1))
{
send_error(lex->thd, ER_SYNTAX_ERROR);
YYABORT;
}
if (sel->linkage == UNION_TYPE && !sel->master_unit()->first_select()->braces)
{
send_error(lex->thd, ER_SYNTAX_ERROR);
YYABORT;
}
/* select in braces, can't contain global parameters */
sel->master_unit()->global_parameters=
sel->master_unit();
......@@ -1683,11 +1688,17 @@ select_init2:
select_part2
{
LEX *lex= Lex;
SELECT_LEX * sel= lex->current_select->select_lex();
if (lex->current_select->set_braces(0))
{
send_error(lex->thd, ER_SYNTAX_ERROR);
YYABORT;
}
if (sel->linkage == UNION_TYPE && sel->master_unit()->first_select()->braces)
{
send_error(lex->thd, ER_SYNTAX_ERROR);
YYABORT;
}
}
union_clause
;
......@@ -1695,6 +1706,7 @@ select_init2:
select_part2:
{
LEX *lex=Lex;
SELECT_LEX * sel= lex->current_select->select_lex();
if (lex->current_select == &lex->select_lex)
lex->lock_option= TL_READ; /* Only for global SELECT */
mysql_init_select(lex);
......@@ -2509,7 +2521,9 @@ join_table:
lex->current_select= unit->outer_select();
if (!($$= lex->current_select->
add_table_to_list(lex->thd, new Table_ident(unit), $5, 0,
lex->lock_option)))
lex->lock_option,(List<String> *)0,
(List<String> *)0)))
YYABORT;
};
......@@ -3187,16 +3201,16 @@ table_wild_list:
| table_wild_list ',' table_wild_one {};
table_wild_one:
ident opt_wild
ident opt_wild opt_table_alias
{
if (!Select->add_table_to_list(YYTHD, new Table_ident($1), NULL, 1,
if (!Select->add_table_to_list(YYTHD, new Table_ident($1), $3, 1,
Lex->lock_option))
YYABORT;
}
| ident '.' ident opt_wild
| ident '.' ident opt_wild opt_table_alias
{
if (!Select->add_table_to_list(YYTHD, new Table_ident($1, $3, 0),
NULL, 1, Lex->lock_option))
$5, 1, Lex->lock_option))
YYABORT;
}
;
......
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