Fix for bug #7476: crash on SELECT * FROM INFORMATION_SCHEMA.TABLES(after review)

parent 82571d6b
...@@ -610,3 +610,8 @@ create view v1 as select * from t1, t2; ...@@ -610,3 +610,8 @@ create view v1 as select * from t1, t2;
set @got_val= (select count(*) from information_schema.columns); set @got_val= (select count(*) from information_schema.columns);
drop view v1; drop view v1;
drop table t1, t2; drop table t1, t2;
CREATE TABLE t_crashme ( f1 BIGINT);
CREATE VIEW a1 (t_CRASHME) AS SELECT f1 FROM t_crashme GROUP BY f1;
CREATE VIEW a2 AS SELECT t_CRASHME FROM a1;
drop view a2, a1;
drop table t_crashme;
...@@ -363,3 +363,30 @@ create view v1 as select * from t1, t2; ...@@ -363,3 +363,30 @@ create view v1 as select * from t1, t2;
set @got_val= (select count(*) from information_schema.columns); set @got_val= (select count(*) from information_schema.columns);
drop view v1; drop view v1;
drop table t1, t2; drop table t1, t2;
#
# Bug #7476: crash on SELECT * FROM INFORMATION_SCHEMA.TABLES
#
CREATE TABLE t_crashme ( f1 BIGINT);
CREATE VIEW a1 (t_CRASHME) AS SELECT f1 FROM t_crashme GROUP BY f1;
CREATE VIEW a2 AS SELECT t_CRASHME FROM a1;
let $tab_count= 65;
--disable_query_log
while ($tab_count)
{
EVAL CREATE TABLE t_$tab_count (f1 BIGINT);
dec $tab_count ;
}
--disable_result_log
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES;
--enable_result_log
let $tab_count= 65;
while ($tab_count)
{
EVAL DROP TABLE t_$tab_count;
dec $tab_count ;
}
--enable_query_log
drop view a2, a1;
drop table t_crashme;
...@@ -1778,6 +1778,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -1778,6 +1778,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
LEX *lex= thd->lex; LEX *lex= thd->lex;
TABLE *table= tables->table; TABLE *table= tables->table;
SELECT_LEX *select_lex= &lex->select_lex; SELECT_LEX *select_lex= &lex->select_lex;
SELECT_LEX *old_all_select_lex= lex->all_selects_list;
SELECT_LEX *lsel= tables->schema_select_lex; SELECT_LEX *lsel= tables->schema_select_lex;
ST_SCHEMA_TABLE *schema_table= tables->schema_table; ST_SCHEMA_TABLE *schema_table= tables->schema_table;
SELECT_LEX sel; SELECT_LEX sel;
...@@ -1790,6 +1791,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -1790,6 +1791,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
List<char> bases; List<char> bases;
List_iterator_fast<char> it(bases); List_iterator_fast<char> it(bases);
COND *partial_cond; COND *partial_cond;
uint derived_tables= lex->derived_tables;
int error= 1; int error= 1;
DBUG_ENTER("get_all_tables"); DBUG_ENTER("get_all_tables");
...@@ -1814,7 +1816,6 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -1814,7 +1816,6 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
goto err; goto err;
} }
lex->all_selects_list= &sel;
schema_table_idx= get_schema_table_idx(schema_table); schema_table_idx= get_schema_table_idx(schema_table);
lock_type= TL_UNLOCK; lock_type= TL_UNLOCK;
...@@ -1911,6 +1912,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -1911,6 +1912,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
goto err; goto err;
TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first; TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
show_table_list->lock_type= lock_type; show_table_list->lock_type= lock_type;
lex->all_selects_list= &sel;
lex->derived_tables= 0;
res= open_and_lock_tables(thd, show_table_list); res= open_and_lock_tables(thd, show_table_list);
if (schema_table->process_table(thd, show_table_list, table, if (schema_table->process_table(thd, show_table_list, table,
res, base_name, res, base_name,
...@@ -1930,7 +1933,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -1930,7 +1933,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
error= 0; error= 0;
err: err:
lex->all_selects_list= select_lex; lex->derived_tables= derived_tables;
lex->all_selects_list= old_all_select_lex;
DBUG_RETURN(error); DBUG_RETURN(error);
} }
......
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