Loading mysql-test/r/handler.result +18 −0 Original line number Diff line number Diff line Loading @@ -447,3 +447,21 @@ drop table t2; drop table t3; drop table t4; drop table t5; create table t1 (c1 int); insert into t1 values (1); handler t1 open; handler t1 read first; c1 1 send the below to another connection, do not wait for the result optimize table t1; proceed with the normal connection handler t1 read next; c1 1 handler t1 close; read the result from the other connection Table Op Msg_type Msg_text test.t1 optimize status OK proceed with the normal connection drop table t1; mysql-test/t/handler.test +29 −0 Original line number Diff line number Diff line Loading @@ -339,3 +339,32 @@ drop table t2; drop table t3; drop table t4; drop table t5; # # Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash # create table t1 (c1 int); insert into t1 values (1); # client 1 handler t1 open; handler t1 read first; # client 2 connect (con2,localhost,root,,); connection con2; --exec echo send the below to another connection, do not wait for the result send optimize table t1; --sleep 1 # client 1 --exec echo proceed with the normal connection connection default; handler t1 read next; handler t1 close; # client 2 --exec echo read the result from the other connection connection con2; reap; # client 1 --exec echo proceed with the normal connection connection default; drop table t1; sql/mysql_priv.h +2 −1 Original line number Diff line number Diff line Loading @@ -547,7 +547,8 @@ int mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen= 0); int mysql_ha_close(THD *thd, TABLE_LIST *tables); int mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *, List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows); int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags); int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags, bool is_locked); /* mysql_ha_flush mode_flags bits */ #define MYSQL_HA_CLOSE_FINAL 0x00 #define MYSQL_HA_REOPEN_ON_USAGE 0x01 Loading sql/sql_base.cc +4 −3 Original line number Diff line number Diff line Loading @@ -390,7 +390,8 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh, thd->proc_info="Flushing tables"; close_old_data_files(thd,thd->open_tables,1,1); mysql_ha_flush(thd, tables, MYSQL_HA_REOPEN_ON_USAGE | MYSQL_HA_FLUSH_ALL); mysql_ha_flush(thd, tables, MYSQL_HA_REOPEN_ON_USAGE | MYSQL_HA_FLUSH_ALL, TRUE); bool found=1; /* Wait until all threads has closed all the tables we had locked */ DBUG_PRINT("info", ("Waiting for others threads to close their open tables")); Loading Loading @@ -863,7 +864,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, } /* close handler tables which are marked for flush */ mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE); mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE, TRUE); for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ; table && table->in_use ; Loading Loading @@ -1262,7 +1263,7 @@ bool wait_for_tables(THD *thd) { thd->some_tables_deleted=0; close_old_data_files(thd,thd->open_tables,0,dropping_tables != 0); mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE); mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE, TRUE); if (!table_is_used(thd->open_tables,1)) break; (void) pthread_cond_wait(&COND_refresh,&LOCK_open); Loading sql/sql_class.cc +1 −1 Original line number Diff line number Diff line Loading @@ -217,7 +217,7 @@ void THD::cleanup(void) close_thread_tables(this); } mysql_ha_flush(this, (TABLE_LIST*) 0, MYSQL_HA_CLOSE_FINAL | MYSQL_HA_FLUSH_ALL); MYSQL_HA_CLOSE_FINAL | MYSQL_HA_FLUSH_ALL, FALSE); hash_free(&handler_tables_hash); close_temporary_tables(this); hash_free(&user_vars); Loading Loading
mysql-test/r/handler.result +18 −0 Original line number Diff line number Diff line Loading @@ -447,3 +447,21 @@ drop table t2; drop table t3; drop table t4; drop table t5; create table t1 (c1 int); insert into t1 values (1); handler t1 open; handler t1 read first; c1 1 send the below to another connection, do not wait for the result optimize table t1; proceed with the normal connection handler t1 read next; c1 1 handler t1 close; read the result from the other connection Table Op Msg_type Msg_text test.t1 optimize status OK proceed with the normal connection drop table t1;
mysql-test/t/handler.test +29 −0 Original line number Diff line number Diff line Loading @@ -339,3 +339,32 @@ drop table t2; drop table t3; drop table t4; drop table t5; # # Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash # create table t1 (c1 int); insert into t1 values (1); # client 1 handler t1 open; handler t1 read first; # client 2 connect (con2,localhost,root,,); connection con2; --exec echo send the below to another connection, do not wait for the result send optimize table t1; --sleep 1 # client 1 --exec echo proceed with the normal connection connection default; handler t1 read next; handler t1 close; # client 2 --exec echo read the result from the other connection connection con2; reap; # client 1 --exec echo proceed with the normal connection connection default; drop table t1;
sql/mysql_priv.h +2 −1 Original line number Diff line number Diff line Loading @@ -547,7 +547,8 @@ int mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen= 0); int mysql_ha_close(THD *thd, TABLE_LIST *tables); int mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *, List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows); int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags); int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags, bool is_locked); /* mysql_ha_flush mode_flags bits */ #define MYSQL_HA_CLOSE_FINAL 0x00 #define MYSQL_HA_REOPEN_ON_USAGE 0x01 Loading
sql/sql_base.cc +4 −3 Original line number Diff line number Diff line Loading @@ -390,7 +390,8 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh, thd->proc_info="Flushing tables"; close_old_data_files(thd,thd->open_tables,1,1); mysql_ha_flush(thd, tables, MYSQL_HA_REOPEN_ON_USAGE | MYSQL_HA_FLUSH_ALL); mysql_ha_flush(thd, tables, MYSQL_HA_REOPEN_ON_USAGE | MYSQL_HA_FLUSH_ALL, TRUE); bool found=1; /* Wait until all threads has closed all the tables we had locked */ DBUG_PRINT("info", ("Waiting for others threads to close their open tables")); Loading Loading @@ -863,7 +864,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, } /* close handler tables which are marked for flush */ mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE); mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE, TRUE); for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ; table && table->in_use ; Loading Loading @@ -1262,7 +1263,7 @@ bool wait_for_tables(THD *thd) { thd->some_tables_deleted=0; close_old_data_files(thd,thd->open_tables,0,dropping_tables != 0); mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE); mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE, TRUE); if (!table_is_used(thd->open_tables,1)) break; (void) pthread_cond_wait(&COND_refresh,&LOCK_open); Loading
sql/sql_class.cc +1 −1 Original line number Diff line number Diff line Loading @@ -217,7 +217,7 @@ void THD::cleanup(void) close_thread_tables(this); } mysql_ha_flush(this, (TABLE_LIST*) 0, MYSQL_HA_CLOSE_FINAL | MYSQL_HA_FLUSH_ALL); MYSQL_HA_CLOSE_FINAL | MYSQL_HA_FLUSH_ALL, FALSE); hash_free(&handler_tables_hash); close_temporary_tables(this); hash_free(&user_vars); Loading