Commit e229fe98 authored by unknown's avatar unknown

Added support for DROP TEMPORARY TABLE

Removed mysql_warnings() API function.
Post merge fixes.


client/mysqltest.c:
  Don't use mysql_warnings().
include/mysql.h:
  Removed mysql_warnings() API function
libmysql/libmysql.c:
  Removed mysql_warnings() API function
mysql-test/r/rpl_log_pos.result:
  Updated results
mysql-test/t/connect.test:
  Removed empty lines
mysql-test/t/rpl_log_pos.test:
  Update to new syntax
sql/item.h:
  Fix after merge
sql/item_create.cc:
  Fix after merge
sql/mysql_priv.h:
  Added support for DROP TEMPORARY TABLE
sql/sql_db.cc:
  Added support for DROP TEMPORARY TABLE
sql/sql_parse.cc:
  SHOW WARNINGS now shows notes, warnings and errors.
  Support for DROP TEMPORARY TABLE
  Post merge fixes
sql/sql_repl.cc:
  Post merge fixes
sql/sql_table.cc:
  Added support for DROP TEMPORARY TABLE
parent eebc67f6
...@@ -2207,10 +2207,15 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags) ...@@ -2207,10 +2207,15 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
/* Add all warnings to the result */ /* Add all warnings to the result */
if (!disable_result_log && mysql_warning_count(mysql)) if (!disable_result_log && mysql_warning_count(mysql))
{ {
MYSQL_RES *warn_res= mysql_warnings(mysql); MYSQL_RES *warn_res=0;
uint count= mysql_warning_count(mysql);
if (!mysql_real_query(mysql, "SHOW WARNINGS", 13))
{
warn_res=mysql_store_result(mysql);
}
if (!warn_res) if (!warn_res)
verbose_msg("Warning count is %d but didn't get any warnings\n", verbose_msg("Warning count is %u but didn't get any warnings\n",
mysql_warning_count(mysql)); count);
else else
{ {
dynstr_append_mem(ds, "Warnings:\n", 10); dynstr_append_mem(ds, "Warnings:\n", 10);
......
...@@ -381,7 +381,6 @@ MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table, ...@@ -381,7 +381,6 @@ MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql); MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql); MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql); MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
MYSQL_RES * STDCALL mysql_warnings(MYSQL *mysql);
int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
const char *arg); const char *arg);
void STDCALL mysql_free_result(MYSQL_RES *result); void STDCALL mysql_free_result(MYSQL_RES *result);
......
...@@ -3515,18 +3515,6 @@ uint STDCALL mysql_thread_safe(void) ...@@ -3515,18 +3515,6 @@ uint STDCALL mysql_thread_safe(void)
#endif #endif
} }
MYSQL_RES *STDCALL mysql_warnings(MYSQL *mysql)
{
uint warning_count;
DBUG_ENTER("mysql_warnings");
/* Save warning count as mysql_real_query may change this */
warning_count= mysql->warning_count;
if (mysql_real_query(mysql, "SHOW WARNINGS", 13))
DBUG_RETURN(0);
mysql->warning_count= warning_count;
DBUG_RETURN(mysql_store_result(mysql));
}
/**************************************************************************** /****************************************************************************
Some support functions Some support functions
****************************************************************************/ ****************************************************************************/
......
...@@ -10,9 +10,9 @@ master-bin.000001 79 ...@@ -10,9 +10,9 @@ master-bin.000001 79
show slave status; show slave status;
Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space
127.0.0.1 root MASTER_PORT 1 master-bin.000001 79 slave-relay-bin.000002 123 master-bin.000001 Yes Yes 0 0 79 127 127.0.0.1 root MASTER_PORT 1 master-bin.000001 79 slave-relay-bin.000002 123 master-bin.000001 Yes Yes 0 0 79 127
slave stop; stop slave;
change master to master_log_pos=73; change master to master_log_pos=73;
slave start; start slave;
stop slave; stop slave;
change master to master_log_pos=73; change master to master_log_pos=73;
show slave status; show slave status;
...@@ -35,7 +35,7 @@ create table if not exists t1 (n int); ...@@ -35,7 +35,7 @@ create table if not exists t1 (n int);
drop table if exists t1; drop table if exists t1;
create table t1 (n int); create table t1 (n int);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
slave stop; stop slave;
change master to master_log_pos=79; change master to master_log_pos=79;
start slave; start slave;
select * from t1; select * from t1;
......
...@@ -63,5 +63,3 @@ show tables; ...@@ -63,5 +63,3 @@ show tables;
#--error 1045 #--error 1045
#connect (con1,localhost,test,zorro,); #connect (con1,localhost,test,zorro,);
#--error 1045 #--error 1045
...@@ -6,9 +6,9 @@ show master status; ...@@ -6,9 +6,9 @@ show master status;
sync_slave_with_master; sync_slave_with_master;
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT --replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
show slave status; show slave status;
slave stop; stop slave;
change master to master_log_pos=73; change master to master_log_pos=73;
slave start; start slave;
sleep 5; sleep 5;
stop slave; stop slave;
...@@ -19,7 +19,7 @@ start slave; ...@@ -19,7 +19,7 @@ start slave;
sleep 5; sleep 5;
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT --replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
show slave status; show slave status;
slave stop; stop slave;
change master to master_log_pos=173; change master to master_log_pos=173;
--replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT --replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT
start slave; start slave;
...@@ -34,7 +34,7 @@ create table t1 (n int); ...@@ -34,7 +34,7 @@ create table t1 (n int);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
save_master_pos; save_master_pos;
connection slave; connection slave;
slave stop; stop slave;
change master to master_log_pos=79; change master to master_log_pos=79;
start slave; start slave;
sync_with_master; sync_with_master;
......
...@@ -381,7 +381,8 @@ public: ...@@ -381,7 +381,8 @@ public:
name=(char*) str_value.ptr(); name=(char*) str_value.ptr();
decimals=NOT_FIXED_DEC; decimals=NOT_FIXED_DEC;
} }
Item_string(const char *name_par,const char *str,uint length,CHARSET_INFO *cs) Item_string(const char *name_par,const char *str,uint length,
CHARSET_INFO *cs)
{ {
str_value.set(str,length,cs); str_value.set(str,length,cs);
max_length=length; max_length=length;
......
...@@ -311,7 +311,8 @@ Item *create_func_current_user() ...@@ -311,7 +311,8 @@ Item *create_func_current_user()
length= (uint) (strxmov(buff, thd->priv_user, "@", thd->host_or_ip, NullS) - length= (uint) (strxmov(buff, thd->priv_user, "@", thd->host_or_ip, NullS) -
buff); buff);
return new Item_string("CURRENT_USER()", thd->memdup(buff, length), length); return new Item_string("CURRENT_USER()", thd->memdup(buff, length), length,
default_charset_info);
} }
Item *create_func_quarter(Item* a) Item *create_func_quarter(Item* a)
......
...@@ -323,11 +323,12 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent); ...@@ -323,11 +323,12 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create); int mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent); int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags); void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists); int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
my_bool drop_temporary);
int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
bool log_query); bool drop_temporary, bool log_query);
int mysql_rm_table_part2_with_lock(THD *thd, TABLE_LIST *tables, int mysql_rm_table_part2_with_lock(THD *thd, TABLE_LIST *tables,
bool if_exists, bool if_exists, bool drop_temporary,
bool log_query); bool log_query);
int quick_rm_table(enum db_type base,const char *db, int quick_rm_table(enum db_type base,const char *db,
const char *table_name); const char *table_name);
......
...@@ -468,7 +468,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, ...@@ -468,7 +468,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
my_dirend(dirp); my_dirend(dirp);
if (thd->killed || if (thd->killed ||
(tot_list && mysql_rm_table_part2_with_lock(thd, tot_list, 1, 1))) (tot_list && mysql_rm_table_part2_with_lock(thd, tot_list, 1, 0, 1)))
DBUG_RETURN(-1); DBUG_RETURN(-1);
/* /*
......
...@@ -963,7 +963,7 @@ bool do_command(THD *thd) ...@@ -963,7 +963,7 @@ bool do_command(THD *thd)
} }
else if (!packet_length) else if (!packet_length)
{ {
send_error(net,net->last_errno,NullS); send_error(thd,net->last_errno,NullS);
net->error=0; net->error=0;
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
} }
...@@ -1629,7 +1629,9 @@ mysql_execute_command(THD *thd) ...@@ -1629,7 +1629,9 @@ mysql_execute_command(THD *thd)
{ {
res= mysqld_show_warnings(thd, (ulong) res= mysqld_show_warnings(thd, (ulong)
((1L << (uint) MYSQL_ERROR::WARN_LEVEL_NOTE) | ((1L << (uint) MYSQL_ERROR::WARN_LEVEL_NOTE) |
(1L << (uint) MYSQL_ERROR::WARN_LEVEL_WARN))); (1L << (uint) MYSQL_ERROR::WARN_LEVEL_WARN) |
(1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR)
));
break; break;
} }
case SQLCOM_SHOW_ERRORS: case SQLCOM_SHOW_ERRORS:
...@@ -1883,7 +1885,7 @@ mysql_execute_command(THD *thd) ...@@ -1883,7 +1885,7 @@ mysql_execute_command(THD *thd)
*/ */
if (thd->locked_tables || thd->active_transaction()) if (thd->locked_tables || thd->active_transaction())
{ {
send_error(&thd->net,ER_LOCK_OR_ACTIVE_TRANSACTION); send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION);
break; break;
} }
{ {
...@@ -2293,12 +2295,17 @@ mysql_execute_command(THD *thd) ...@@ -2293,12 +2295,17 @@ mysql_execute_command(THD *thd)
} }
case SQLCOM_DROP_TABLE: case SQLCOM_DROP_TABLE:
{ {
if (check_table_access(thd,DROP_ACL,tables)) if (!lex->drop_temporary)
goto error; /* purecov: inspected */ {
if (end_active_trans(thd)) if (check_table_access(thd,DROP_ACL,tables))
res= -1; goto error; /* purecov: inspected */
else if (end_active_trans(thd))
res = mysql_rm_table(thd,tables,lex->drop_if_exists); {
res= -1;
break;
}
}
res= mysql_rm_table(thd,tables,lex->drop_if_exists, lex->drop_temporary);
} }
break; break;
case SQLCOM_DROP_INDEX: case SQLCOM_DROP_INDEX:
...@@ -3777,9 +3784,9 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables) ...@@ -3777,9 +3784,9 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables)
if (thd && !error_already_sent) if (thd && !error_already_sent)
{ {
if (result) if (result)
send_error(&thd->net,0); send_error(thd,0);
else else
send_ok(&thd->net); send_ok(thd);
} }
return result; return result;
......
...@@ -757,7 +757,7 @@ int reset_slave(THD *thd, MASTER_INFO* mi) ...@@ -757,7 +757,7 @@ int reset_slave(THD *thd, MASTER_INFO* mi)
err: err:
unlock_slave_threads(mi); unlock_slave_threads(mi);
if (thd && error) if (thd && error)
send_error(&thd->net, sql_errno, errmsg); send_error(thd, sql_errno, errmsg);
DBUG_RETURN(error); DBUG_RETURN(error);
} }
...@@ -802,7 +802,7 @@ int change_master(THD* thd, MASTER_INFO* mi) ...@@ -802,7 +802,7 @@ int change_master(THD* thd, MASTER_INFO* mi)
init_thread_mask(&thread_mask,mi,0 /*not inverse*/); init_thread_mask(&thread_mask,mi,0 /*not inverse*/);
if (thread_mask) // We refuse if any slave thread is running if (thread_mask) // We refuse if any slave thread is running
{ {
net_printf(&thd,ER_SLAVE_MUST_STOP); net_printf(thd,ER_SLAVE_MUST_STOP);
unlock_slave_threads(mi); unlock_slave_threads(mi);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -874,7 +874,7 @@ int change_master(THD* thd, MASTER_INFO* mi) ...@@ -874,7 +874,7 @@ int change_master(THD* thd, MASTER_INFO* mi)
0 /* not only reset, but also reinit */, 0 /* not only reset, but also reinit */,
&errmsg)) &errmsg))
{ {
net_printf(&thd, 0, "Failed purging old relay logs: %s",errmsg); net_printf(thd, 0, "Failed purging old relay logs: %s",errmsg);
unlock_slave_threads(mi); unlock_slave_threads(mi);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
...@@ -908,7 +908,7 @@ int change_master(THD* thd, MASTER_INFO* mi) ...@@ -908,7 +908,7 @@ int change_master(THD* thd, MASTER_INFO* mi)
unlock_slave_threads(mi); unlock_slave_threads(mi);
thd->proc_info = 0; thd->proc_info = 0;
send_ok(&thd); send_ok(thd);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -46,7 +46,8 @@ static int copy_data_between_tables(TABLE *from,TABLE *to, ...@@ -46,7 +46,8 @@ static int copy_data_between_tables(TABLE *from,TABLE *to,
** This will wait for all users to free the table before dropping it ** This will wait for all users to free the table before dropping it
*****************************************************************************/ *****************************************************************************/
int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists) int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
my_bool drop_temporary)
{ {
int error; int error;
DBUG_ENTER("mysql_rm_table"); DBUG_ENTER("mysql_rm_table");
...@@ -57,7 +58,7 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists) ...@@ -57,7 +58,7 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists)
thd->mysys_var->current_cond= &COND_refresh; thd->mysys_var->current_cond= &COND_refresh;
VOID(pthread_mutex_lock(&LOCK_open)); VOID(pthread_mutex_lock(&LOCK_open));
if (global_read_lock) if (!drop_temporary && global_read_lock)
{ {
if (thd->global_read_lock) if (thd->global_read_lock)
{ {
...@@ -72,7 +73,7 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists) ...@@ -72,7 +73,7 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists)
} }
} }
error=mysql_rm_table_part2(thd,tables,if_exists,0); error=mysql_rm_table_part2(thd,tables, if_exists, drop_temporary, 0);
err: err:
pthread_mutex_unlock(&LOCK_open); pthread_mutex_unlock(&LOCK_open);
...@@ -91,14 +92,15 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists) ...@@ -91,14 +92,15 @@ int mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists)
int mysql_rm_table_part2_with_lock(THD *thd, int mysql_rm_table_part2_with_lock(THD *thd,
TABLE_LIST *tables, bool if_exists, TABLE_LIST *tables, bool if_exists,
bool dont_log_query) bool drop_temporary, bool dont_log_query)
{ {
int error; int error;
thd->mysys_var->current_mutex= &LOCK_open; thd->mysys_var->current_mutex= &LOCK_open;
thd->mysys_var->current_cond= &COND_refresh; thd->mysys_var->current_cond= &COND_refresh;
VOID(pthread_mutex_lock(&LOCK_open)); VOID(pthread_mutex_lock(&LOCK_open));
error=mysql_rm_table_part2(thd,tables, if_exists, dont_log_query); error=mysql_rm_table_part2(thd,tables, if_exists, drop_temporary,
dont_log_query);
pthread_mutex_unlock(&LOCK_open); pthread_mutex_unlock(&LOCK_open);
VOID(pthread_cond_broadcast(&COND_refresh)); // Signal to refresh VOID(pthread_cond_broadcast(&COND_refresh)); // Signal to refresh
...@@ -111,6 +113,17 @@ int mysql_rm_table_part2_with_lock(THD *thd, ...@@ -111,6 +113,17 @@ int mysql_rm_table_part2_with_lock(THD *thd,
} }
/* /*
Execute the drop of a normal or temporary table
SYNOPSIS
mysql_rm_table_part2()
thd Thread handler
tables Tables to drop
if_exists If set, don't give an error if table doesn't exists.
In this case we give an warning of level 'NOTE'
drop_temporary Only drop temporary tables
dont_log_query Don't log the query
TODO: TODO:
When logging to the binary log, we should log When logging to the binary log, we should log
tmp_tables and transactional tables as separate statements if we tmp_tables and transactional tables as separate statements if we
...@@ -120,10 +133,15 @@ int mysql_rm_table_part2_with_lock(THD *thd, ...@@ -120,10 +133,15 @@ int mysql_rm_table_part2_with_lock(THD *thd,
The current code only writes DROP statements that only uses temporary The current code only writes DROP statements that only uses temporary
tables to the cache binary log. This should be ok on most cases, but tables to the cache binary log. This should be ok on most cases, but
not all. not all.
RETURN
0 ok
1 Error
-1 Thread was killed
*/ */
int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
bool dont_log_query) bool drop_temporary, bool dont_log_query)
{ {
TABLE_LIST *table; TABLE_LIST *table;
char path[FN_REFLEN]; char path[FN_REFLEN];
...@@ -142,26 +160,28 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -142,26 +160,28 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
continue; // removed temporary table continue; // removed temporary table
} }
abort_locked_tables(thd,db,table->real_name);
while (remove_table_from_cache(thd,db,table->real_name) && !thd->killed)
{
dropping_tables++;
(void) pthread_cond_wait(&COND_refresh,&LOCK_open);
dropping_tables--;
}
drop_locked_tables(thd,db,table->real_name);
if (thd->killed)
DBUG_RETURN(-1);
/* remove form file and isam files */
strxmov(path, mysql_data_home, "/", db, "/", table->real_name, reg_ext,
NullS);
(void) unpack_filename(path,path);
error=0; error=0;
if (!drop_temporary)
{
abort_locked_tables(thd,db,table->real_name);
while (remove_table_from_cache(thd,db,table->real_name) && !thd->killed)
{
dropping_tables++;
(void) pthread_cond_wait(&COND_refresh,&LOCK_open);
dropping_tables--;
}
drop_locked_tables(thd,db,table->real_name);
if (thd->killed)
DBUG_RETURN(-1);
table_type=get_table_type(path); /* remove form file and isam files */
strxmov(path, mysql_data_home, "/", db, "/", table->real_name, reg_ext,
NullS);
(void) unpack_filename(path,path);
if (access(path,F_OK)) table_type=get_table_type(path);
}
if (drop_temporary || access(path,F_OK))
{ {
if (if_exists) if (if_exists)
store_warning(thd, ER_BAD_TABLE_ERROR, table->real_name); store_warning(thd, ER_BAD_TABLE_ERROR, table->real_name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment