Commit 49285e96 authored by gkodinov/kgeorge@magare.gmz's avatar gkodinov/kgeorge@magare.gmz

Merge magare.gmz:/home/kgeorge/mysql/work/B29325-5.0-opt

into  magare.gmz:/home/kgeorge/mysql/work/B29325-5.1-opt
parents c5025571 015e1290
...@@ -299,6 +299,7 @@ enum ha_base_keytype { ...@@ -299,6 +299,7 @@ enum ha_base_keytype {
#define HA_PACK_RECORD 2 /* Request packed record format */ #define HA_PACK_RECORD 2 /* Request packed record format */
#define HA_CREATE_TMP_TABLE 4 #define HA_CREATE_TMP_TABLE 4
#define HA_CREATE_CHECKSUM 8 #define HA_CREATE_CHECKSUM 8
#define HA_CREATE_KEEP_FILES 16 /* don't overwrite .MYD and MYI */
#define HA_CREATE_DELAY_KEY_WRITE 64 #define HA_CREATE_DELAY_KEY_WRITE 64
#define HA_CREATE_RELIES_ON_SQL_LAYER 128 #define HA_CREATE_RELIES_ON_SQL_LAYER 128
......
...@@ -1516,6 +1516,23 @@ t1 CREATE TABLE `t1` ( ...@@ -1516,6 +1516,23 @@ t1 CREATE TABLE `t1` (
`c17` int(11) DEFAULT NULL `c17` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1; drop table t1;
CREATE DATABASE db1;
CREATE DATABASE db2;
USE db2;
INSERT INTO db2.t1 VALUES (1);
SELECT * FROM db2.t1;
b
1
RESET QUERY CACHE;
USE db1;
SET SESSION keep_files_on_create = TRUE;
CREATE TABLE t1 (a INT) ENGINE MYISAM;
ERROR HY000: Can't create/write to file './db1/t1.MYD' (Errcode: 17)
SET SESSION keep_files_on_create = DEFAULT;
DROP TABLE db2.t1;
DROP DATABASE db1;
DROP DATABASE db2;
USE test;
End of 5.0 tests End of 5.0 tests
CREATE TABLE t1 (a int, b int); CREATE TABLE t1 (a int, b int);
insert into t1 values (1,1),(1,2); insert into t1 values (1,1),(1,2);
......
...@@ -1122,6 +1122,37 @@ show create table t1; ...@@ -1122,6 +1122,37 @@ show create table t1;
drop table t1; drop table t1;
#
# Bug #29325: create table overwrites .MYD file of other table (datadir)
#
CREATE DATABASE db1;
CREATE DATABASE db2;
USE db2;
--disable_query_log
eval CREATE TABLE t1 (b INT) ENGINE MYISAM
DATA DIRECTORY = '$MYSQLTEST_VARDIR/master-data/db1/';
--enable_query_log
INSERT INTO db2.t1 VALUES (1);
SELECT * FROM db2.t1;
RESET QUERY CACHE;
USE db1;
#no warning from create table
SET SESSION keep_files_on_create = TRUE;
--disable_abort_on_error
CREATE TABLE t1 (a INT) ENGINE MYISAM;
--enable_abort_on_error
SET SESSION keep_files_on_create = DEFAULT;
DROP TABLE db2.t1;
DROP DATABASE db1;
DROP DATABASE db2;
USE test;
--echo End of 5.0 tests --echo End of 5.0 tests
......
...@@ -616,6 +616,8 @@ sys_var_thd_time_zone sys_time_zone(&vars, "time_zone"); ...@@ -616,6 +616,8 @@ sys_var_thd_time_zone sys_time_zone(&vars, "time_zone");
/* Global read-only variable containing hostname */ /* Global read-only variable containing hostname */
static sys_var_const_str sys_hostname(&vars, "hostname", glob_hostname); static sys_var_const_str sys_hostname(&vars, "hostname", glob_hostname);
sys_var_thd_bool sys_keep_files_on_create(&vars, "keep_files_on_create",
&SV::keep_files_on_create);
/* Read only variables */ /* Read only variables */
static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress); static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
......
...@@ -305,6 +305,7 @@ struct system_variables ...@@ -305,6 +305,7 @@ struct system_variables
my_bool old_mode; my_bool old_mode;
my_bool query_cache_wlock_invalidate; my_bool query_cache_wlock_invalidate;
my_bool engine_condition_pushdown; my_bool engine_condition_pushdown;
my_bool keep_files_on_create;
my_bool ndb_force_send; my_bool ndb_force_send;
my_bool ndb_use_copying_alter_table; my_bool ndb_use_copying_alter_table;
my_bool ndb_use_exact_count; my_bool ndb_use_exact_count;
......
...@@ -4697,8 +4697,11 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table, ...@@ -4697,8 +4697,11 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
DBUG_EXECUTE_IF("sleep_create_like_before_ha_create", my_sleep(6000000);); DBUG_EXECUTE_IF("sleep_create_like_before_ha_create", my_sleep(6000000););
dst_path[dst_path_length - reg_ext_length]= '\0'; // Remove .frm dst_path[dst_path_length - reg_ext_length]= '\0'; // Remove .frm
if (thd->variables.keep_files_on_create)
create_info->options|= HA_CREATE_KEEP_FILES;
err= ha_create_table(thd, dst_path, db, table_name, create_info, 1); err= ha_create_table(thd, dst_path, db, table_name, create_info, 1);
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
if (create_info->options & HA_LEX_CREATE_TMP_TABLE) if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
{ {
if (err || !open_temporary_table(thd, dst_path, db, table_name, 1)) if (err || !open_temporary_table(thd, dst_path, db, table_name, 1))
......
...@@ -355,6 +355,8 @@ int rea_create_table(THD *thd, const char *path, ...@@ -355,6 +355,8 @@ int rea_create_table(THD *thd, const char *path,
// Make sure mysql_create_frm din't remove extension // Make sure mysql_create_frm din't remove extension
DBUG_ASSERT(*fn_rext(frm_name)); DBUG_ASSERT(*fn_rext(frm_name));
if (thd->variables.keep_files_on_create)
create_info->options|= HA_CREATE_KEEP_FILES;
if (file->create_handler_files(path, NULL, CHF_CREATE_FLAG, create_info)) if (file->create_handler_files(path, NULL, CHF_CREATE_FLAG, create_info))
goto err_handler; goto err_handler;
if (!create_info->frm_only && ha_create_table(thd, path, db, table_name, if (!create_info->frm_only && ha_create_table(thd, path, db, table_name,
......
...@@ -1889,6 +1889,8 @@ int ha_myisam::create(const char *name, register TABLE *table_arg, ...@@ -1889,6 +1889,8 @@ int ha_myisam::create(const char *name, register TABLE *table_arg,
if (ha_create_info->options & HA_LEX_CREATE_TMP_TABLE) if (ha_create_info->options & HA_LEX_CREATE_TMP_TABLE)
create_flags|= HA_CREATE_TMP_TABLE; create_flags|= HA_CREATE_TMP_TABLE;
if (ha_create_info->options & HA_CREATE_KEEP_FILES)
create_flags|= HA_CREATE_KEEP_FILES;
if (options & HA_OPTION_PACK_RECORD) if (options & HA_OPTION_PACK_RECORD)
create_flags|= HA_PACK_RECORD; create_flags|= HA_PACK_RECORD;
if (options & HA_OPTION_CHECKSUM) if (options & HA_OPTION_CHECKSUM)
......
...@@ -615,7 +615,8 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, ...@@ -615,7 +615,8 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
(have_iext ? MY_REPLACE_EXT : MY_APPEND_EXT)); (have_iext ? MY_REPLACE_EXT : MY_APPEND_EXT));
linkname_ptr=0; linkname_ptr=0;
/* Replace the current file */ /* Replace the current file */
create_flag=MY_DELETE_OLD; if (!(flags & HA_CREATE_KEEP_FILES))
create_flag=MY_DELETE_OLD;
} }
/* /*
...@@ -689,7 +690,8 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, ...@@ -689,7 +690,8 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
fn_format(filename,name,"", MI_NAME_DEXT, fn_format(filename,name,"", MI_NAME_DEXT,
MY_UNPACK_FILENAME | MY_APPEND_EXT); MY_UNPACK_FILENAME | MY_APPEND_EXT);
linkname_ptr=0; linkname_ptr=0;
create_flag=MY_DELETE_OLD; if (!(flags & HA_CREATE_KEEP_FILES))
create_flag=MY_DELETE_OLD;
} }
if ((dfile= if ((dfile=
my_create_with_symlink(linkname_ptr, filename, 0, create_mode, my_create_with_symlink(linkname_ptr, filename, 0, create_mode,
......
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