#At file:///Users/shulga/projects/mysql/5.1-bugteam-bug38813/ based on revid:luis.soares@stripped
3527 Dmitry Shulga 2011-04-11
Fixed bug#11749345 (formerly #38813) - increasing memory consumption
when selecting from I_S and views exist, in SP
The problem was that when view is being opened its LEX is incorporated
into SQL-statement's LEX.
The solution is to create temporal LEX when make opening of tables.
@ mysql-test/r/information_schema.result
Previous result set for explain plan statement was invalid.
modified:
mysql-test/r/information_schema.result
sql/sql_show.cc
=== modified file 'mysql-test/r/information_schema.result'
--- a/mysql-test/r/information_schema.result 2010-11-30 17:51:25 +0000
+++ b/mysql-test/r/information_schema.result 2011-04-11 09:41:32 +0000
@@ -1342,7 +1342,7 @@ id select_type table type possible_keys
1 SIMPLE tables ALL NULL NULL NULL NULL NULL Open_frm_only; Scanned all databases; Using filesort
explain select * from (select table_name from information_schema.tables) as a;
id select_type table type possible_keys key key_len ref rows Extra
-1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 54
2 DERIVED tables ALL NULL NULL NULL NULL NULL Skip_open_table; Scanned all databases
drop view v1;
create table t1 (f1 int(11));
=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc 2010-12-14 09:33:03 +0000
+++ b/sql/sql_show.cc 2011-04-11 09:41:32 +0000
@@ -3021,18 +3021,17 @@ make_table_name_list(THD *thd, List<LEX_
static int
fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables,
ST_SCHEMA_TABLE *schema_table,
- Open_tables_state *open_tables_state_backup)
+ Open_tables_state *open_tables_state_backup,
+ TABLE_LIST *show_table_list)
{
LEX *lex= thd->lex;
bool res;
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
enum_sql_command save_sql_command= lex->sql_command;
- TABLE_LIST *show_table_list= tables->schema_select_lex->table_list.first;
TABLE *table= tables->table;
int error= 1;
DBUG_ENTER("fill_schema_show");
- lex->all_selects_list= tables->schema_select_lex;
/*
Restore thd->temporary_tables to be able to process
temporary tables(only for 'show index' & 'show columns').
@@ -3300,7 +3299,6 @@ int get_all_tables(THD *thd, TABLE_LIST
{
LEX *lex= thd->lex;
TABLE *table= tables->table;
- SELECT_LEX *old_all_select_lex= lex->all_selects_list;
enum_sql_command save_sql_command= lex->sql_command;
SELECT_LEX *lsel= tables->schema_select_lex;
ST_SCHEMA_TABLE *schema_table= tables->schema_table;
@@ -3312,20 +3310,37 @@ int get_all_tables(THD *thd, TABLE_LIST
List<LEX_STRING> db_names;
List_iterator_fast<LEX_STRING> it(db_names);
COND *partial_cond= 0;
- uint derived_tables= lex->derived_tables;
int error= 1;
Open_tables_state open_tables_state_backup;
- uint8 save_context_analysis_only= lex->context_analysis_only;
Query_tables_list query_tables_list_backup;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
Security_context *sctx= thd->security_ctx;
#endif
+
uint table_open_method;
+ MEM_ROOT mem_root_for_i_s;
+ Query_arena i_s_arena(&mem_root_for_i_s,
+ Query_arena::CONVENTIONAL_EXECUTION),
+ backup_arena, *old_arena;
+ LEX *old_lex= thd->lex, temp_lex;
DBUG_ENTER("get_all_tables");
- lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
+ // use dedicated MEM_ROOT
+ old_arena= thd->stmt_arena;
+ init_sql_alloc(&mem_root_for_i_s, MEM_ROOT_BLOCK_SIZE, 0);
+ thd->stmt_arena= &i_s_arena;
+ thd->lex= &temp_lex;
+ lex_start(thd);
+ lex= thd->lex;
+ lex->sql_command= old_lex->sql_command;
+ lex->wild= old_lex->wild;
+ lex->select_lex.db= old_lex->select_lex.db;
+
+ lex->context_analysis_only= CONTEXT_ANALYSIS_ONLY_VIEW;
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
+ thd->set_n_backup_active_arena(&i_s_arena, &backup_arena);
+
/*
We should not introduce deadlocks even if we already have some
tables open and locked, since we won't lock tables which we will
@@ -3340,8 +3355,24 @@ int get_all_tables(THD *thd, TABLE_LIST
*/
if (lsel && lsel->table_list.first)
{
+ LEX_STRING db_name, table_name;
+ db_name.str= lsel->table_list.first->db;
+ db_name.length= strlen(db_name.str);
+
+ table_name.str= lsel->table_list.first->table_name;
+ table_name.length= strlen(table_name.str);
+
+ sel.parent_lex= lex;
+
+ if (make_table_list(thd, &sel, &db_name, &table_name))
+ goto err;
+
+ TABLE_LIST *show_table_list= sel.table_list.first;
+ lex->all_selects_list= &sel;
+ lex->derived_tables= 0;
error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
- &open_tables_state_backup);
+ &open_tables_state_backup,
+ show_table_list);
goto err;
}
@@ -3537,11 +3568,17 @@ int get_all_tables(THD *thd, TABLE_LIST
error= 0;
err:
thd->restore_backup_open_tables_state(&open_tables_state_backup);
- lex->restore_backup_query_tables_list(&query_tables_list_backup);
- lex->derived_tables= derived_tables;
- lex->all_selects_list= old_all_select_lex;
- lex->context_analysis_only= save_context_analysis_only;
- lex->sql_command= save_sql_command;
+
+ lex_end(thd->lex);
+ thd->lex= old_lex;
+
+ if (i_s_arena.free_list)
+ i_s_arena.free_items();
+
+ free_root(&mem_root_for_i_s, MYF(0));
+ thd->stmt_arena= old_arena;
+ thd->restore_active_arena(&i_s_arena, &backup_arena);
+
DBUG_RETURN(error);
}
Attachment: [text/bzr-bundle] bzr/dmitry.shulga@oracle.com-20110411094132-spzcgy3kbtv1e6g4.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3527) Bug#11749345 | Dmitry Shulga | 11 Apr |