List:Commits« Previous MessageNext Message »
From:gluh Date:April 25 2006 5:52am
Subject:bk commit into 5.0 tree (gluh:1.2097) BUG#18282
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of gluh. When gluh does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2097 06/04/25 10:52:20 gluh@stripped +7 -0
  Bug#17204 second CALL to procedure crashes Server
  Bug#18282 INFORMATION_SCHEMA.TABLES provides inconsistent info about invalid views
  This bug caused crashes or resulted in wrong data being returned
  when one tried to obtain information from I_S tables about views
  using stored functions.
  
  It was caused by the fact that we were using LEX representing
  statement which were doing select from I_S tables as active LEX
  when contents of I_S table were built. So state of this LEX both
  affected and was affected by open_tables() calls which happened
  during this process. This resulted in wrong behavior and in
  violations of some of invariants which caused crashes.
  This fix tries to solve this problem by properly saving/resetting
  and restoring members of LEX which affect and are affected by the
  process of opening tables and views in get_all_tables() routine.

  sql/sql_show.cc
    1.314 06/04/25 10:52:14 gluh@stripped +11 -3
    Bug#17204 second CALL to procedure crashes Server
    Bug#18282 INFORMATION_SCHEMA.TABLES provides inconsistent info about invalid views

  sql/sql_lex.h
    1.215 06/04/25 10:52:14 gluh@stripped +2 -1
    Bug#17204 second CALL to procedure crashes Server
    Bug#18282 INFORMATION_SCHEMA.TABLES provides inconsistent info about invalid views

  sql/sql_lex.cc
    1.181 06/04/25 10:52:14 gluh@stripped +7 -6
    Bug#17204 second CALL to procedure crashes Server
    Bug#18282 INFORMATION_SCHEMA.TABLES provides inconsistent info about invalid views

  sql/sql_base.cc
    1.331 06/04/25 10:52:14 gluh@stripped +2 -2
    Bug#17204 second CALL to procedure crashes Server
    Bug#18282 INFORMATION_SCHEMA.TABLES provides inconsistent info about invalid views

  sql/sp.cc
    1.110 06/04/25 10:52:14 gluh@stripped +10 -10
    Bug#17204 second CALL to procedure crashes Server
    Bug#18282 INFORMATION_SCHEMA.TABLES provides inconsistent info about invalid views

  mysql-test/t/information_schema_db.test
    1.4 06/04/25 10:52:14 gluh@stripped +54 -1
    test case

  mysql-test/r/information_schema_db.result
    1.7 06/04/25 10:52:14 gluh@stripped +52 -1
    test case

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	gluh
# Host:	eagle.intranet.mysql.r18.ru
# Root:	/home/gluh/MySQL/Bugs/5.0.17204

--- 1.330/sql/sql_base.cc	Mon Mar  6 13:41:16 2006
+++ 1.331/sql/sql_base.cc	Tue Apr 25 10:52:14 2006
@@ -1999,7 +1999,7 @@ int open_tables(THD *thd, TABLE_LIST **s
   */
 
   if (!thd->prelocked_mode && !thd->lex->requires_prelocking() &&
-      thd->lex->sroutines_list.elements)
+      thd->lex->sroutines_list->elements)
   {
     bool first_no_prelocking, need_prelocking, tabs_changed;
     TABLE_LIST **save_query_tables_last= thd->lex->query_tables_last;
@@ -2145,7 +2145,7 @@ process_view_routines:
     */
     if (tables->view && !thd->prelocked_mode &&
         !thd->lex->requires_prelocking() &&
-        tables->view->sroutines_list.elements)
+        tables->view->sroutines_list->elements)
     {
       /* We have at least one table in TL here. */
       if (!query_tables_last_own)

--- 1.180/sql/sql_lex.cc	Fri Mar 10 04:44:01 2006
+++ 1.181/sql/sql_lex.cc	Tue Apr 25 10:52:14 2006
@@ -180,8 +180,8 @@ void lex_start(THD *thd, uchar *buf,uint
 
   if (lex->sroutines.records)
     my_hash_reset(&lex->sroutines);
-  lex->sroutines_list.empty();
-  lex->sroutines_list_own_last= lex->sroutines_list.next;
+  lex->sroutines_list->empty();
+  lex->sroutines_list_own_last= lex->sroutines_list->next;
   lex->sroutines_list_own_elements= 0;
   lex->nest_level=0 ;
   lex->allow_sum_func= 0;
@@ -1629,8 +1629,9 @@ st_lex::st_lex()
   :result(0), sql_command(SQLCOM_END), query_tables_own_last(0)
 {
   hash_init(&sroutines, system_charset_info, 0, 0, 0, sp_sroutine_key, 0, 0);
-  sroutines_list.empty();
-  sroutines_list_own_last= sroutines_list.next;
+  sroutines_list= new SQL_LIST;
+  sroutines_list->empty();
+  sroutines_list_own_last= sroutines_list->next;
   sroutines_list_own_elements= 0;
 }
 
@@ -2043,8 +2044,8 @@ void st_lex::cleanup_after_one_table_ope
   time_zone_tables_used= 0;
   if (sroutines.records)
     my_hash_reset(&sroutines);
-  sroutines_list.empty();
-  sroutines_list_own_last= sroutines_list.next;
+  sroutines_list->empty();
+  sroutines_list_own_last= sroutines_list->next;
   sroutines_list_own_elements= 0;
 }
 

--- 1.214/sql/sql_lex.h	Fri Mar 10 04:44:01 2006
+++ 1.215/sql/sql_lex.h	Tue Apr 25 10:52:14 2006
@@ -886,7 +886,7 @@ typedef struct st_lex
     We use these two members for restoring of 'sroutines_list' to the state
     in which it was right after query parsing.
   */
-  SQL_LIST sroutines_list;
+  SQL_LIST *sroutines_list;
   byte     **sroutines_list_own_last;
   uint     sroutines_list_own_elements;
 
@@ -945,6 +945,7 @@ typedef struct st_lex
   virtual ~st_lex()
   {
     hash_free(&sroutines);
+    delete sroutines_list;
   }
 
   inline void uncacheable(uint8 cause)

--- 1.313/sql/sql_show.cc	Mon Mar 20 14:17:41 2006
+++ 1.314/sql/sql_show.cc	Tue Apr 25 10:52:14 2006
@@ -2048,8 +2048,11 @@ int get_all_tables(THD *thd, TABLE_LIST 
   SELECT_LEX *select_lex= &lex->select_lex;
   SELECT_LEX *old_all_select_lex= lex->all_selects_list;
   TABLE_LIST **save_query_tables_last= lex->query_tables_last;
+  TABLE_LIST **save_query_tables_own_last= lex->query_tables_own_last;
   enum_sql_command save_sql_command= lex->sql_command;
   SELECT_LEX *lsel= tables->schema_select_lex;
+  SQL_LIST local_sroutines_list;
+  SQL_LIST *save_sroutines_list= lex->sroutines_list;
   ST_SCHEMA_TABLE *schema_table= tables->schema_table;
   SELECT_LEX sel;
   INDEX_FIELD_VALUES idx_field_vals;
@@ -2067,6 +2070,7 @@ int get_all_tables(THD *thd, TABLE_LIST 
   Open_tables_state open_tables_state_backup;
   bool save_view_prepare_mode= lex->view_prepare_mode;
   lex->view_prepare_mode= TRUE;
+  lex->sroutines_list= &local_sroutines_list;
   DBUG_ENTER("get_all_tables");
 
   LINT_INIT(end);
@@ -2089,7 +2093,7 @@ int get_all_tables(THD *thd, TABLE_LIST 
   {
     TABLE_LIST *show_table_list= (TABLE_LIST*) lsel->table_list.first;
     bool res;
-
+    local_sroutines_list.empty();
     lex->all_selects_list= lsel;
     /*
       Restore thd->temporary_tables to be able to process
@@ -2118,7 +2122,7 @@ int get_all_tables(THD *thd, TABLE_LIST 
                                              show_table_list->db),
                                             show_table_list->alias));
     thd->temporary_tables= 0;
-    close_thread_tables(thd);
+    close_tables_for_reopen(thd, &show_table_list);
     show_table_list->table= 0;
     goto err;
   }
@@ -2220,6 +2224,8 @@ int get_all_tables(THD *thd, TABLE_LIST 
             TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
             lex->all_selects_list= &sel;
             lex->derived_tables= 0;
+	    lex->query_tables_own_last= 0;
+	    local_sroutines_list.empty();
             res= open_normal_and_derived_tables(thd, show_table_list,
                                                 MYSQL_LOCK_IGNORE_FLUSH);
             /*
@@ -2232,7 +2238,7 @@ int get_all_tables(THD *thd, TABLE_LIST 
             res= schema_table->process_table(thd, show_table_list, table,
                                             res, base_name,
                                             show_table_list->alias);
-            close_thread_tables(thd);
+            close_tables_for_reopen(thd, &show_table_list);
             if (res)
               goto err;
           }
@@ -2252,7 +2258,9 @@ err:
   lex->derived_tables= derived_tables;
   lex->all_selects_list= old_all_select_lex;
   lex->query_tables_last= save_query_tables_last;
+  lex->query_tables_own_last= save_query_tables_own_last;
   lex->view_prepare_mode= save_view_prepare_mode;
+  lex->sroutines_list= save_sroutines_list;
   *save_query_tables_last= 0;
   lex->sql_command= save_sql_command;
   DBUG_RETURN(error);

--- 1.6/mysql-test/r/information_schema_db.result	Mon Mar 20 13:41:56 2006
+++ 1.7/mysql-test/r/information_schema_db.result	Tue Apr 25 10:52:14 2006
@@ -24,10 +24,12 @@ TABLE_CONSTRAINTS
 TABLE_PRIVILEGES
 TRIGGERS
 create database `inf%`;
+create database mbase;
 use `inf%`;
 show tables;
 Tables_in_inf%
 grant all privileges on `inf%`.* to 'mysqltest_1'@'localhost';
+grant all privileges on `mbase`.* to 'mysqltest_1'@'localhost';
 create table t1 (f1 int);
 create function func1(curr_int int) returns int
 begin
@@ -36,9 +38,58 @@ select max(f1) from t1 into ret_val;
 return ret_val;
 end|
 create view v1 as select f1 from t1 where f1 = func1(f1);
+create function func2() returns int return 1;
+use mbase;
+create procedure p1 ()
+begin
+select table_name from information_schema.key_column_usage
+order by table_name;
+end|
+create table t1 
+(f1 int(10) unsigned not null,
+f2 varchar(100) not null,
+primary key (f1), unique key (f2));
 select * from information_schema.tables;
+call mbase.p1();
+call mbase.p1();
+call mbase.p1();
+use `inf%`;
 drop user mysqltest_1@localhost;
+drop table t1;
+select table_name, table_type, table_comment from information_schema.tables
+where table_schema='inf%' and func2();
+table_name	table_type	table_comment
+v1	VIEW	View 'inf%.v1' references invalid table(s) or column(s) or function(s) or define
+select table_name, table_type, table_comment from information_schema.tables
+where table_schema='inf%' and func2();
+table_name	table_type	table_comment
+v1	VIEW	View 'inf%.v1' references invalid table(s) or column(s) or function(s) or define
 drop view v1;
 drop function func1;
-drop table t1;
+drop function func2;
 drop database `inf%`;
+drop procedure mbase.p1;
+drop database mbase;
+use test;
+create table t1 (i int);
+create function f1 () returns int return (select max(i) from t1);
+create view v1 as select f1();
+create table t2 (id int);
+create function f2 () returns int return (select max(i) from t2);
+create view v2 as select f2();
+drop table t2;
+select table_name, table_type, table_comment from information_schema.tables
+where table_schema='test';
+table_name	table_type	table_comment
+t1	BASE TABLE	
+v1	VIEW	VIEW
+v2	VIEW	View 'test.v2' references invalid table(s) or column(s) or function(s) or define
+drop table t1;
+select table_name, table_type, table_comment from information_schema.tables
+where table_schema='test';
+table_name	table_type	table_comment
+v1	VIEW	View 'test.v1' references invalid table(s) or column(s) or function(s) or define
+v2	VIEW	View 'test.v2' references invalid table(s) or column(s) or function(s) or define
+drop function f1;
+drop function f2;
+drop view v1, v2;

--- 1.3/mysql-test/t/information_schema_db.test	Mon Mar 20 13:41:56 2006
+++ 1.4/mysql-test/t/information_schema_db.test	Tue Apr 25 10:52:14 2006
@@ -6,6 +6,7 @@ show tables;
 --replace_result 'Tables_in_INFORMATION_SCHEMA (T%)' 'Tables_in_information_schema (T%)'
 show tables from INFORMATION_SCHEMA like 'T%';
 create database `inf%`;
+create database mbase;
 use `inf%`;
 show tables;
 
@@ -18,6 +19,7 @@ show tables;
 # privileges at all).
 #
 grant all privileges on `inf%`.* to 'mysqltest_1'@'localhost';
+grant all privileges on `mbase`.* to 'mysqltest_1'@'localhost';
 create table t1 (f1 int);
 delimiter |;
 create function func1(curr_int int) returns int
@@ -28,15 +30,66 @@ begin
 end|
 delimiter ;|
 create view v1 as select f1 from t1 where f1 = func1(f1);
+create function func2() returns int return 1;
+#
+# Bug#17204 second CALL to procedure crashes Server
+#
+use mbase;
+delimiter |;
+create procedure p1 ()
+begin
+select table_name from information_schema.key_column_usage
+order by table_name;
+end|
+delimiter ;|
+
+create table t1 
+(f1 int(10) unsigned not null,
+ f2 varchar(100) not null,
+ primary key (f1), unique key (f2));
+
 connect (user1,localhost,mysqltest_1,,);
 connection user1;
 --disable_result_log
 select * from information_schema.tables;
+call mbase.p1();
+call mbase.p1();
+call mbase.p1();
 --enable_result_log
+
 connection default;
+use `inf%`;
 drop user mysqltest_1@localhost;
+drop table t1;
+select table_name, table_type, table_comment from information_schema.tables
+where table_schema='inf%' and func2();
+select table_name, table_type, table_comment from information_schema.tables
+where table_schema='inf%' and func2();
 drop view v1;
 drop function func1;
-drop table t1;
+drop function func2;
 
 drop database `inf%`;
+drop procedure mbase.p1;
+drop database mbase;
+#
+# Bug#18282 INFORMATION_SCHEMA.TABLES provides inconsistent info about invalid views
+#
+use test;
+create table t1 (i int);
+create function f1 () returns int return (select max(i) from t1);
+create view v1 as select f1();
+create table t2 (id int);
+create function f2 () returns int return (select max(i) from t2);
+create view v2 as select f2();
+
+drop table t2;
+select table_name, table_type, table_comment from information_schema.tables
+where table_schema='test';
+drop table t1;
+select table_name, table_type, table_comment from information_schema.tables
+where table_schema='test';
+drop function f1;
+drop function f2;
+drop view v1, v2;
+

--- 1.109/sql/sp.cc	Fri Mar 10 04:44:01 2006
+++ 1.110/sql/sp.cc	Tue Apr 25 10:52:14 2006
@@ -1320,7 +1320,7 @@ void sp_get_prelocking_info(THD *thd, bo
                             bool *first_no_prelocking)
 {
   Sroutine_hash_entry *routine;
-  routine= (Sroutine_hash_entry*)thd->lex->sroutines_list.first;
+  routine= (Sroutine_hash_entry*)thd->lex->sroutines_list->first;
 
   DBUG_ASSERT(routine);
   bool first_is_procedure= (routine->key.str[0] == TYPE_ENUM_PROCEDURE);
@@ -1377,7 +1377,7 @@ static bool add_used_routine(LEX *lex, Q
     rn->key.str= (char *)rn + sizeof(Sroutine_hash_entry);
     memcpy(rn->key.str, key->str, key->length);
     my_hash_insert(&lex->sroutines, (byte *)rn);
-    lex->sroutines_list.link_in_list((byte *)rn, (byte **)&rn->next);
+    lex->sroutines_list->link_in_list((byte *)rn, (byte **)&rn->next);
     rn->belong_to_view= belong_to_view;
     return TRUE;
   }
@@ -1410,8 +1410,8 @@ void sp_add_used_routine(LEX *lex, Query
 {
   rt->set_routine_type(rt_type);
   (void)add_used_routine(lex, arena, &rt->m_sroutines_key, 0);
-  lex->sroutines_list_own_last= lex->sroutines_list.next;
-  lex->sroutines_list_own_elements= lex->sroutines_list.elements;
+  lex->sroutines_list_own_last= lex->sroutines_list->next;
+  lex->sroutines_list_own_elements= lex->sroutines_list->elements;
 }
 
 
@@ -1439,8 +1439,8 @@ void sp_remove_not_own_routines(LEX *lex
   }
 
   *(Sroutine_hash_entry **)lex->sroutines_list_own_last= NULL;
-  lex->sroutines_list.next= lex->sroutines_list_own_last;
-  lex->sroutines_list.elements= lex->sroutines_list_own_elements;
+  lex->sroutines_list->next= lex->sroutines_list_own_last;
+  lex->sroutines_list->elements= lex->sroutines_list_own_elements;
 }
 
 
@@ -1663,7 +1663,7 @@ sp_cache_routines_and_add_tables(THD *th
                                  bool *tabs_changed)
 {
   return sp_cache_routines_and_add_tables_aux(thd, lex,
-           (Sroutine_hash_entry *)lex->sroutines_list.first,
+           (Sroutine_hash_entry *)lex->sroutines_list->first,
            first_no_prelock, tabs_changed);
 }
 
@@ -1688,8 +1688,8 @@ int
 sp_cache_routines_and_add_tables_for_view(THD *thd, LEX *lex, TABLE_LIST *view)
 {
   Sroutine_hash_entry **last_cached_routine_ptr=
-                          (Sroutine_hash_entry **)lex->sroutines_list.next;
-  sp_update_stmt_used_routines(thd, lex, &view->view->sroutines_list,
+                          (Sroutine_hash_entry **)lex->sroutines_list->next;
+  sp_update_stmt_used_routines(thd, lex, view->view->sroutines_list,
                                view->top_table());
   return sp_cache_routines_and_add_tables_aux(thd, lex, 
                                               *last_cached_routine_ptr, FALSE,
@@ -1723,7 +1723,7 @@ sp_cache_routines_and_add_tables_for_tri
                        table->belong_to_view))
   {
     Sroutine_hash_entry **last_cached_routine_ptr=
-                            (Sroutine_hash_entry **)lex->sroutines_list.next;
+                            (Sroutine_hash_entry **)lex->sroutines_list->next;
     for (int i= 0; i < (int)TRG_EVENT_MAX; i++)
     {
       for (int j= 0; j < (int)TRG_ACTION_MAX; j++)
Thread
bk commit into 5.0 tree (gluh:1.2097) BUG#18282gluh25 Apr