mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Fixed bug in ALTER TABLE DISABLE KEYS and INSERT DELAYED. Bug #478
mysql-test/r/alter_table.result: new results mysql-test/r/lowercase_table.result: new results mysql-test/t/alter_table.test: Test of ALTER TABLE DISABLE KEYS + INSERT DELAYED mysql-test/t/lowercase_table.test: Added test of alias name comparison sql/mysql_priv.h: Made closed_cached_table local sql/sql_table.cc: Fixed bug in ALTER TABLE DISABLE KEYS and INSERT DELAYED
This commit is contained in:
@ -276,3 +276,8 @@ t1 0 a 1 a A 3 NULL NULL YES BTREE
|
||||
t1 0 a 2 b A 300 NULL NULL YES BTREE
|
||||
t1 1 b 1 b A 100 NULL NULL YES BTREE
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (i int(10), index(i) );
|
||||
ALTER TABLE t1 DISABLE KEYS;
|
||||
INSERT DELAYED INTO t1 VALUES(1),(2),(3);
|
||||
ALTER TABLE t1 ENABLE KEYS;
|
||||
drop table t1;
|
||||
|
@ -13,3 +13,15 @@ show tables like 't_';
|
||||
Tables_in_test (t_)
|
||||
t3
|
||||
drop table t3;
|
||||
create table t1 (a int);
|
||||
select count(*) from T1;
|
||||
count(*)
|
||||
0
|
||||
select count(*) from t1;
|
||||
count(*)
|
||||
0
|
||||
select count(T1.a) from t1;
|
||||
Unknown table 'T1' in field list
|
||||
select count(bags.a) from t1 as Bags;
|
||||
Unknown table 'bags' in field list
|
||||
drop table t1;
|
||||
|
@ -133,3 +133,12 @@ analyze table t1;
|
||||
show keys from t1;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Test of ALTER TABLE DELAYED
|
||||
#
|
||||
|
||||
CREATE TABLE t1 (i int(10), index(i) );
|
||||
ALTER TABLE t1 DISABLE KEYS;
|
||||
INSERT DELAYED INTO t1 VALUES(1),(2),(3);
|
||||
ALTER TABLE t1 ENABLE KEYS;
|
||||
drop table t1;
|
||||
|
@ -12,3 +12,14 @@ ALTER TABLE T2 RENAME T3;
|
||||
show tables like 't_';
|
||||
drop table t3;
|
||||
|
||||
#
|
||||
# Test alias
|
||||
#
|
||||
create table t1 (a int);
|
||||
select count(*) from T1;
|
||||
select count(*) from t1;
|
||||
--error 1109
|
||||
select count(T1.a) from t1;
|
||||
--error 1109
|
||||
select count(bags.a) from t1 as Bags;
|
||||
drop table t1;
|
||||
|
@ -422,7 +422,6 @@ bool mysql_rename_table(enum db_type base,
|
||||
const char * old_name,
|
||||
const char *new_db,
|
||||
const char * new_name);
|
||||
bool close_cached_table(THD *thd,TABLE *table);
|
||||
int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys);
|
||||
int mysql_drop_index(THD *thd, TABLE_LIST *table_list,
|
||||
List<Alter_drop> &drop_list);
|
||||
|
@ -912,22 +912,32 @@ mysql_rename_table(enum db_type base,
|
||||
}
|
||||
|
||||
/*
|
||||
close table in this thread and force close + reopen in other threads
|
||||
This assumes that the calling thread has lock on LOCK_open
|
||||
Force all other threads to stop using the table
|
||||
|
||||
SYNOPSIS
|
||||
wait_while_table_is_used()
|
||||
thd Thread handler
|
||||
table Table to remove from cache
|
||||
|
||||
NOTES
|
||||
When returning, the table will be unusable for other threads until
|
||||
the table is closed.
|
||||
|
||||
PREREQUISITES
|
||||
Lock on LOCK_open
|
||||
Win32 clients must also have a WRITE LOCK on the table !
|
||||
*/
|
||||
|
||||
static void safe_remove_from_cache(THD *thd,TABLE *table)
|
||||
{
|
||||
DBUG_ENTER("safe_remove_from_cache");
|
||||
if (table)
|
||||
static void wait_while_table_is_used(THD *thd,TABLE *table)
|
||||
{
|
||||
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
|
||||
/* Mark all tables that are in use as 'old' */
|
||||
mysql_lock_abort(thd, table); // end threads waiting on lock
|
||||
|
||||
#if defined(USING_TRANSACTIONS) || defined( __WIN__) || defined( __EMX__) || !defined(OS2)
|
||||
/* Wait until all there are no other threads that has this table open */
|
||||
while (remove_table_from_cache(thd,table->table_cache_key,
|
||||
table->real_name))
|
||||
@ -936,25 +946,31 @@ static void safe_remove_from_cache(THD *thd,TABLE *table)
|
||||
(void) pthread_cond_wait(&COND_refresh,&LOCK_open);
|
||||
dropping_tables--;
|
||||
}
|
||||
#else
|
||||
(void) remove_table_from_cache(thd,table->table_cache_key,
|
||||
table->real_name);
|
||||
#endif
|
||||
/* When lock on LOCK_open is freed other threads can continue */
|
||||
pthread_cond_broadcast(&COND_refresh);
|
||||
}
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
/*
|
||||
Close a cached table
|
||||
|
||||
bool close_cached_table(THD *thd,TABLE *table)
|
||||
SYNOPSIS
|
||||
clsoe_cached_table()
|
||||
thd Thread handler
|
||||
table Table to remove from cache
|
||||
|
||||
NOTES
|
||||
Function ends by signaling threads waiting for the table to try to
|
||||
reopen the table.
|
||||
|
||||
PREREQUISITES
|
||||
Lock on LOCK_open
|
||||
Win32 clients must also have a WRITE LOCK on the table !
|
||||
*/
|
||||
|
||||
static bool close_cached_table(THD *thd, TABLE *table)
|
||||
{
|
||||
DBUG_ENTER("close_cached_table");
|
||||
safe_mutex_assert_owner(&LOCK_open);
|
||||
|
||||
if (table)
|
||||
{
|
||||
safe_remove_from_cache(thd,table);
|
||||
wait_while_table_is_used(thd,table);
|
||||
/* Close lock if this is not got with LOCK TABLES */
|
||||
if (thd->lock)
|
||||
{
|
||||
@ -963,7 +979,9 @@ bool close_cached_table(THD *thd,TABLE *table)
|
||||
}
|
||||
/* Close all copies of 'table'. This also frees all LOCK TABLES lock */
|
||||
thd->open_tables=unlink_open_table(thd,thd->open_tables,table);
|
||||
}
|
||||
|
||||
/* When lock on LOCK_open is freed other threads can continue */
|
||||
pthread_cond_broadcast(&COND_refresh);
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
@ -1094,10 +1112,13 @@ static int prepare_for_repair(THD* thd, TABLE_LIST *table_list,
|
||||
|
||||
sprintf(tmp,"%s-%lx_%lx", from, current_pid, thd->thread_id);
|
||||
|
||||
/* If we could open the table, close it */
|
||||
if (table_list->table)
|
||||
{
|
||||
pthread_mutex_lock(&LOCK_open);
|
||||
close_cached_table(thd,table_list->table);
|
||||
close_cached_table(thd, table);
|
||||
pthread_mutex_unlock(&LOCK_open);
|
||||
|
||||
}
|
||||
if (lock_and_wait_for_table_name(thd,table_list))
|
||||
{
|
||||
error= -1;
|
||||
@ -1498,7 +1519,6 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
if (mysql_rename_table(old_db_type,db,table_name,new_db,new_name))
|
||||
error= -1;
|
||||
}
|
||||
VOID(pthread_cond_broadcast(&COND_refresh));
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
}
|
||||
if (!error)
|
||||
@ -1507,12 +1527,18 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
case LEAVE_AS_IS:
|
||||
break;
|
||||
case ENABLE:
|
||||
safe_remove_from_cache(thd,table);
|
||||
VOID(pthread_mutex_lock(&LOCK_open));
|
||||
wait_while_table_is_used(thd, table);
|
||||
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:
|
||||
safe_remove_from_cache(thd,table);
|
||||
VOID(pthread_mutex_lock(&LOCK_open));
|
||||
wait_while_table_is_used(thd, table);
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
table->file->deactivate_non_unique_index(HA_POS_ERROR);
|
||||
/* COND_refresh will be signaled in close_thread_tables() */
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1970,6 +1996,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
This shouldn't happen. We solve this the safe way by
|
||||
closing the locked table.
|
||||
*/
|
||||
if (table)
|
||||
close_cached_table(thd,table);
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
goto err;
|
||||
@ -1980,6 +2007,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
Not table locking or alter table with rename
|
||||
free locks and remove old table
|
||||
*/
|
||||
if (table)
|
||||
close_cached_table(thd,table);
|
||||
VOID(quick_rm_table(old_db_type,db,old_name));
|
||||
}
|
||||
@ -2000,6 +2028,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
if (close_data_tables(thd,db,table_name) ||
|
||||
reopen_tables(thd,1,0))
|
||||
{ // This shouldn't happen
|
||||
if (table)
|
||||
close_cached_table(thd,table); // Remove lock for table
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
goto err;
|
||||
|
Reference in New Issue
Block a user