From 537e120648ab0b1e50fbcefcf0a17f6803135857 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 30 Jun 2003 17:00:11 +0200 Subject: REPAIR/OPTIMIZE/CHECK/RESTORE/etc commands close relevant open HANDLERs --- sql/sql_table.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index f3620b860a7..5a53ba30631 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1198,6 +1198,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, if (send_fields(thd, field_list, 1)) DBUG_RETURN(-1); + mysql_ha_closeall(thd, tables); for (table = tables; table; table = table->next) { char table_name[NAME_LEN*2+2]; -- cgit v1.2.1 From e13e857cae1ecaa322a0b4dec76e5b5dfb4f53a0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 8 Jul 2003 23:58:04 +0300 Subject: Fixed bug in ALTER TABLE ... DISABLE/ENABLE KEYS Removed double my_thread_end() which caused fatal error on windows if mysqld died on startup myisam/mi_extra.c: Fixed bug in ALTER TABLE ... DISABLE/ENABLE KEYS mysql-test/r/alter_table.result: Fixed bug in ALTER TABLE ... DISABLE/ENABLE KEYS mysql-test/t/alter_table.test: Test DISABLE/ENABLE KEY sql/ha_myisam.cc: Fixed bug in ALTER TABLE ... DISABLE/ENABLE KEYS sql/mysqld.cc: Removed double my_thread_end() which caused fatal error on windows if mysqld died on startup sql/sql_table.cc: Fixed bug in ALTER TABLE ... DISABLE/ENABLE KEYS sql/table.cc: Fixed bug in ALTER TABLE ... DISABLE/ENABLE KEYS sql/table.h: Fixed bug in ALTER TABLE ... DISABLE/ENABLE KEYS --- sql/sql_table.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 5a53ba30631..cf430aec35d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -918,7 +918,8 @@ mysql_rename_table(enum db_type base, wait_while_table_is_used() thd Thread handler table Table to remove from cache - + function HA_EXTRA_PREPARE_FOR_DELETE if table is to be deleted + HA_EXTRA_FORCE_REOPEN if table is not be used NOTES When returning, the table will be unusable for other threads until the table is closed. @@ -928,13 +929,14 @@ mysql_rename_table(enum db_type base, Win32 clients must also have a WRITE LOCK on the table ! */ -static void wait_while_table_is_used(THD *thd,TABLE *table) +static void wait_while_table_is_used(THD *thd,TABLE *table, + enum ha_extra_function function) { DBUG_PRINT("enter",("table: %s", table->real_name)); DBUG_ENTER("wait_while_table_is_used"); safe_mutex_assert_owner(&LOCK_open); - VOID(table->file->extra(HA_EXTRA_FORCE_REOPEN)); // Close all data files + VOID(table->file->extra(function)); /* Mark all tables that are in use as 'old' */ mysql_lock_abort(thd, table); // end threads waiting on lock @@ -970,7 +972,7 @@ static bool close_cached_table(THD *thd, TABLE *table) { DBUG_ENTER("close_cached_table"); - wait_while_table_is_used(thd,table); + wait_while_table_is_used(thd, table, HA_EXTRA_PREPARE_FOR_DELETE); /* Close lock if this is not got with LOCK TABLES */ if (thd->lock) { @@ -1529,14 +1531,14 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, break; case ENABLE: VOID(pthread_mutex_lock(&LOCK_open)); - wait_while_table_is_used(thd, table); + wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN); VOID(pthread_mutex_unlock(&LOCK_open)); error= table->file->activate_all_index(thd); /* COND_refresh will be signaled in close_thread_tables() */ break; case DISABLE: VOID(pthread_mutex_lock(&LOCK_open)); - wait_while_table_is_used(thd, table); + wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN); VOID(pthread_mutex_unlock(&LOCK_open)); table->file->deactivate_non_unique_index(HA_POS_ERROR); /* COND_refresh will be signaled in close_thread_tables() */ -- cgit v1.2.1 From d974959b4f5a965d217597c4d979fee4a7a70506 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 11 Jul 2003 14:26:44 +0200 Subject: Fix for BUG#791: a safer way of initing the mutexes in MYSQL_LOG. is_open() is now always thread-safe. See each file for details. sql/handler.cc: is_open() with locks sql/item_func.cc: is_open() with locks sql/log.cc: No more 'inited'. We now always use is_open() in a thread-safe manner. This simplifies some functions (no more need to test is_open() twice). sql/log_event.cc: is_open() with locks sql/mysqld.cc: Init mutexes for the global MYSQL_LOG objects. We care about no_rotate, because we can't do it in open() anymore (because we don't have 'inited' anymore). sql/repl_failsafe.cc: is_open() with locks sql/slave.cc: init pthread objects (mutexes, conds) in the constructor of st_relay_log_info. Some better locking in rotate_relay_log(). sql/sql_base.cc: is_open() with locks sql/sql_class.h: Before, we inited LOCK_log in MYSQL_LOG::open(), so in other places of the code when we were never 100% sure that it had been inited. For example, if the server was running without --log-bin, ::open() was not called so the mutex was not inited. We could detect it with !inited, but not safely as 'inited' was not protected by any mutex. So now: we *always* init the LOCK_log mutex, even if the log is not used. We can't init the mutex in MYSQL_LOG's constructor, because for global objects like mysql_bin_log, mysql_log etc, the constructor is called before MY_INIT(), but safe_mutex depends on MY_INIT(). So we have a new function MYSQL_LOG::init_pthread_objects which we call in main(), after MY_INIT(). For the relay log, we call this function in the constructor of st_relay_log_info, which is called before any function tries to use the relay log (the relay log is always invoked as rli.relay_log). So now we should be safe in all cases and we don't need 'inited'. sql/sql_db.cc: is_open() with locks sql/sql_delete.cc: is_open() with locks sql/sql_insert.cc: is_open() with locks sql/sql_load.cc: is_open() with locks sql/sql_parse.cc: is_open() with locks sql/sql_rename.cc: is_open() with locks sql/sql_repl.cc: is_open() with locks sql/sql_table.cc: is_open() with locks sql/sql_update.cc: is_open() with locks --- sql/sql_table.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index cf430aec35d..2d024ded5db 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -235,7 +235,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, if (!dont_log_query) { mysql_update_log.write(thd, thd->query,thd->query_length); - if (mysql_bin_log.is_open()) + if (mysql_bin_log.is_open(1)) { Query_log_event qinfo(thd, thd->query, thd->query_length, tmp_table_deleted && !some_tables_deleted); @@ -766,7 +766,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, { // Must be written before unlock mysql_update_log.write(thd,thd->query, thd->query_length); - if (mysql_bin_log.is_open()) + if (mysql_bin_log.is_open(1)) { Query_log_event qinfo(thd, thd->query, thd->query_length, test(create_info->options & @@ -1548,7 +1548,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, if (!error) { mysql_update_log.write(thd, thd->query, thd->query_length); - if (mysql_bin_log.is_open()) + if (mysql_bin_log.is_open(1)) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0); mysql_bin_log.write(&qinfo); @@ -1918,7 +1918,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, goto err; } mysql_update_log.write(thd, thd->query,thd->query_length); - if (mysql_bin_log.is_open()) + if (mysql_bin_log.is_open(1)) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0); mysql_bin_log.write(&qinfo); @@ -2050,7 +2050,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, } thd->proc_info="end"; mysql_update_log.write(thd, thd->query,thd->query_length); - if (mysql_bin_log.is_open()) + if (mysql_bin_log.is_open(1)) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0); mysql_bin_log.write(&qinfo); -- cgit v1.2.1 From e1a30696034b70e3bf78036aa75a6e8389ebb2c4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 Jul 2003 10:12:05 +0300 Subject: Safety and speedup fixes: Changed is_open() to work as before. Added back inited argument to LOG mysql-test/r/rpl_flush_log_loop.result: Fixed results (probably bug in previous rpatch) sql/handler.cc: Changed is_open() to work as before sql/item_func.cc: Changed is_open() to work as before sql/log.cc: Part revert of previous patch. The reason for adding back 'inited' is that is that we can't be 100 % sure that init_pthread_objects() is called before mysqld dies (for example on windows) I removed mutex lock handling in is_open() as the new code didn't have ANY affect except beeing slower. Added back checking of is_open() to some functions as we don't want to do a mutex lock when we are not using logging. Indentation/comment fixes sql/log_event.cc: Changed is_open() to work as before sql/repl_failsafe.cc: Changed is_open() to work as before sql/sql_base.cc: Changed is_open() to work as before sql/sql_class.h: Changed is_open() to work as before. Added back 'inited' variable sql/sql_db.cc: Changed is_open() to work as before sql/sql_delete.cc: Changed is_open() to work as before sql/sql_insert.cc: Changed is_open() to work as before sql/sql_load.cc: Changed is_open() to work as before sql/sql_parse.cc: Changed is_open() to work as before sql/sql_rename.cc: Changed is_open() to work as before sql/sql_repl.cc: Changed is_open() to work as before sql/sql_table.cc: Changed is_open() to work as before sql/sql_update.cc: Changed is_open() to work as before --- sql/sql_table.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 2d024ded5db..cf430aec35d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -235,7 +235,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, if (!dont_log_query) { mysql_update_log.write(thd, thd->query,thd->query_length); - if (mysql_bin_log.is_open(1)) + if (mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query, thd->query_length, tmp_table_deleted && !some_tables_deleted); @@ -766,7 +766,7 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, { // Must be written before unlock mysql_update_log.write(thd,thd->query, thd->query_length); - if (mysql_bin_log.is_open(1)) + if (mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query, thd->query_length, test(create_info->options & @@ -1548,7 +1548,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, if (!error) { mysql_update_log.write(thd, thd->query, thd->query_length); - if (mysql_bin_log.is_open(1)) + if (mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0); mysql_bin_log.write(&qinfo); @@ -1918,7 +1918,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, goto err; } mysql_update_log.write(thd, thd->query,thd->query_length); - if (mysql_bin_log.is_open(1)) + if (mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0); mysql_bin_log.write(&qinfo); @@ -2050,7 +2050,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, } thd->proc_info="end"; mysql_update_log.write(thd, thd->query,thd->query_length); - if (mysql_bin_log.is_open(1)) + if (mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0); mysql_bin_log.write(&qinfo); -- cgit v1.2.1 From 2b29fc927102c0b46d39fb302fcc2966390430b6 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Aug 2003 13:39:53 +0200 Subject: PRIMARY KEY can erroneously have HA_NULL_PART_KEY flag that breaks correct key sorting --- sql/sql_table.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index cf430aec35d..c55015f7aa5 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -602,13 +602,14 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, sql_field->flags|= NOT_NULL_FLAG; sql_field->pack_flag&= ~FIELDFLAG_MAYBE_NULL; } + else + key_info->flags|= HA_NULL_PART_KEY; if (!(file->table_flags() & HA_NULL_KEY)) { my_printf_error(ER_NULL_COLUMN_IN_INDEX,ER(ER_NULL_COLUMN_IN_INDEX), MYF(0),column->field_name); DBUG_RETURN(-1); } - key_info->flags|= HA_NULL_PART_KEY; } if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER) { -- cgit v1.2.1