List:Commits« Previous MessageNext Message »
From:Dmitry Shulga Date:April 15 2011 6:12am
Subject:bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3527) Bug#11749345
View as plain text  
#At file:///Users/shulga/projects/mysql/5.1-bugteam-bug38813/ based on revid:luis.soares@stripped

 3527 Dmitry Shulga	2011-04-15
      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.
     @ sql/sql_show.cc
        Added last argument to fill_schema_show_cols_or_idxs() that contains
        pointer to TABLE_LIST to SHOW.
        get_all_tables() was modified: created temporal LEX object before 
        processing tables. This LEX objects destroyed before return from
        get_all_tables() function and clean up data associated with itself.
        As well temporal arena object was created and assigned as default
        arena for successive processing. Memory allocated into this arena
        cleaned up before return from get_all_tables().

    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-15 06:12:12 +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-15 06:12:12 +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,21 +3310,42 @@ 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;
+  Query_arena i_s_arena(thd->mem_root,
+                        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;
+  old_arena= thd->stmt_arena;
+  // use temporal arena for statement execution
+  thd->stmt_arena= &i_s_arena;
+  // and use temporal LEX
+  thd->lex= &temp_lex;
+  lex_start(thd);
+  // copy some attributes from original LEX
+  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);
 
   /*
+    assign temporal arena to THD object and save original arena'a
+    value for successive restoring
+  */
+  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
     open and will ignore possible name-locks for these tables.
@@ -3340,8 +3359,27 @@ 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;
+
+    // get table's object to SHOW and pass it to
+    // fill_schema_show_cols_or_idxs() for processing
+    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 +3575,19 @@ 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;
+
+  /*
+    Restore original LEX value, statement's arena and THD arena values
+  */
+  lex_end(thd->lex);
+  thd->lex= old_lex;
+
+  if (i_s_arena.free_list)
+    i_s_arena.free_items();
+
+  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-20110415061212-xgtazi5lc1r82s61.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3527) Bug#11749345Dmitry Shulga15 Apr
  • Re: bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3527)Bug#11749345Dmitry Lenev11 May