#At file:///home/svoj/devel/bzr-mysql/mysql-5.1-bugteam-bug48265/ based on revid:luis.soares@stripped
3372 Sergey Vojtovich 2010-02-08
BUG#48265 - MRG_MYISAM problem (works in 5.0.85, does't
work in 5.1.40)
MERGE engine fails to open child table from a different
database if child table/database name contains characters
that are subject for table name to filename encoding
(WL1324).
Another problem is that MERGE engine didn't properly open
child table from the same database if child table name
contains characters like '/', '#'.
The problem was that table name to file name encoding was
applied inconsistently:
* On CREATE: encode table name + database name if child
table is in different database; do not encode table
name if child table is in the same database;
* No decoding on open.
With this fix child table/database names are always
encoded on CREATE and decoded on open.
Along with this patch comes fix for SHOW CREATE TABLE,
which used to show child table/database path instead
of child table/database names.
@ mysql-test/r/merge.result
A test case for BUG#48265.
@ mysql-test/t/merge.test
A test case for BUG#48265.
@ storage/myisammrg/ha_myisammrg.cc
On CREATE always write child table/database name encoded
by table name to filename encoding to dot-MRG file.
On open decode child table/database name.
Fixed ::append_create_info() to return child
table/database name instead of path.
modified:
mysql-test/r/merge.result
mysql-test/t/merge.test
storage/myisammrg/ha_myisammrg.cc
=== modified file 'mysql-test/r/merge.result'
--- a/mysql-test/r/merge.result 2009-10-13 18:21:42 +0000
+++ b/mysql-test/r/merge.result 2010-02-08 13:07:48 +0000
@@ -2219,4 +2219,49 @@ Trigger sql_mode SQL Original Statement
tr1 CREATE DEFINER=`root`@`localhost` TRIGGER tr1 AFTER INSERT ON t3 FOR EACH ROW CALL foo() latin1 latin1_swedish_ci latin1_swedish_ci
DROP TRIGGER tr1;
DROP TABLE t1, t2, t3;
+#
+# BUG#48265 - MRG_MYISAM problem (works in 5.0.85, does't work in 5.1.40)
+#
+CREATE DATABASE `test/1`;
+CREATE TABLE `test/1`.`t/1`(a INT);
+CREATE TABLE m1(a INT) ENGINE=MERGE UNION=(`test/1`.`t/1`);
+SELECT * FROM m1;
+a
+SHOW CREATE TABLE m1;
+Table Create Table
+m1 CREATE TABLE `m1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`test/1`.`t/1`)
+DROP TABLE m1;
+CREATE TABLE `test/1`.m1(a INT) ENGINE=MERGE UNION=(`test/1`.`t/1`);
+SELECT * FROM `test/1`.m1;
+a
+SHOW CREATE TABLE `test/1`.m1;
+Table Create Table
+m1 CREATE TABLE `m1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t/1`)
+DROP TABLE `test/1`.m1;
+DROP TABLE `test/1`.`t/1`;
+CREATE TEMPORARY TABLE `test/1`.`t/1`(a INT);
+CREATE TEMPORARY TABLE m1(a INT) ENGINE=MERGE UNION=(`test/1`.`t/1`);
+SELECT * FROM m1;
+a
+SHOW CREATE TABLE m1;
+Table Create Table
+m1 CREATE TEMPORARY TABLE `m1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`test/1`.`t/1`)
+DROP TABLE m1;
+CREATE TEMPORARY TABLE `test/1`.m1(a INT) ENGINE=MERGE UNION=(`test/1`.`t/1`);
+SELECT * FROM `test/1`.m1;
+a
+SHOW CREATE TABLE `test/1`.m1;
+Table Create Table
+m1 CREATE TEMPORARY TABLE `m1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t/1`)
+DROP TABLE `test/1`.m1;
+DROP TABLE `test/1`.`t/1`;
+DROP DATABASE `test/1`;
End of 5.1 tests
=== modified file 'mysql-test/t/merge.test'
--- a/mysql-test/t/merge.test 2009-10-13 18:21:42 +0000
+++ b/mysql-test/t/merge.test 2010-02-08 13:07:48 +0000
@@ -1633,4 +1633,35 @@ SHOW CREATE TRIGGER tr1;
DROP TRIGGER tr1;
DROP TABLE t1, t2, t3;
+--echo #
+--echo # BUG#48265 - MRG_MYISAM problem (works in 5.0.85, does't work in 5.1.40)
+--echo #
+CREATE DATABASE `test/1`;
+
+CREATE TABLE `test/1`.`t/1`(a INT);
+CREATE TABLE m1(a INT) ENGINE=MERGE UNION=(`test/1`.`t/1`);
+SELECT * FROM m1;
+SHOW CREATE TABLE m1;
+DROP TABLE m1;
+
+CREATE TABLE `test/1`.m1(a INT) ENGINE=MERGE UNION=(`test/1`.`t/1`);
+SELECT * FROM `test/1`.m1;
+SHOW CREATE TABLE `test/1`.m1;
+DROP TABLE `test/1`.m1;
+DROP TABLE `test/1`.`t/1`;
+
+CREATE TEMPORARY TABLE `test/1`.`t/1`(a INT);
+CREATE TEMPORARY TABLE m1(a INT) ENGINE=MERGE UNION=(`test/1`.`t/1`);
+SELECT * FROM m1;
+SHOW CREATE TABLE m1;
+DROP TABLE m1;
+
+CREATE TEMPORARY TABLE `test/1`.m1(a INT) ENGINE=MERGE UNION=(`test/1`.`t/1`);
+SELECT * FROM `test/1`.m1;
+SHOW CREATE TABLE `test/1`.m1;
+DROP TABLE `test/1`.m1;
+DROP TABLE `test/1`.`t/1`;
+
+DROP DATABASE `test/1`;
+
--echo End of 5.1 tests
=== modified file 'storage/myisammrg/ha_myisammrg.cc'
--- a/storage/myisammrg/ha_myisammrg.cc 2010-02-02 13:17:58 +0000
+++ b/storage/myisammrg/ha_myisammrg.cc 2010-02-08 13:07:48 +0000
@@ -217,9 +217,12 @@ static int myisammrg_parent_open_callbac
ha_myisammrg *ha_myrg;
TABLE *parent;
TABLE_LIST *child_l;
- const char *db;
- const char *table_name;
+ const char *dir;
+ char table_name[NAME_LEN];
+ char db_name[NAME_LEN];
size_t dirlen;
+ size_t table_name_len;
+ size_t db_name_len;
char dir_path[FN_REFLEN];
DBUG_ENTER("myisammrg_parent_open_callback");
@@ -233,13 +236,16 @@ static int myisammrg_parent_open_callbac
DBUG_RETURN(1);
/* purecov: end */
}
- table_name= filename + dirlen;
+ table_name_len= filename_to_tablename(filename + dirlen, table_name,
+ sizeof(table_name));
dirlen--; /* Strip off trailing '/'. */
memcpy(dir_path, filename, dirlen);
dir_path[dirlen]= '\0';
- db= base_name(dir_path);
- dirlen-= db - dir_path; /* This is now the length of 'db'. */
- DBUG_PRINT("myrg", ("open: '%s'.'%s'", db, table_name));
+ dir= base_name(dir_path);
+ dirlen-= dir - dir_path; /* This is now the length of 'db'. */
+ db_name_len= filename_to_tablename(dir, db_name, sizeof(db_name));
+ DBUG_PRINT("myrg", ("open: '%.*s'.'%.*s'", db_name_len, db_name,
+ table_name_len, table_name));
ha_myrg= (ha_myisammrg*) callback_param;
parent= ha_myrg->table_ptr();
@@ -256,10 +262,10 @@ static int myisammrg_parent_open_callbac
bzero((char*) child_l, sizeof(TABLE_LIST));
/* Set database (schema) name. */
- child_l->db_length= dirlen;
- child_l->db= strmake_root(&parent->mem_root, db, dirlen);
+ child_l->db_length= db_name_len;
+ child_l->db= strmake_root(&parent->mem_root, db_name, db_name_len);
/* Set table name. */
- child_l->table_name_length= strlen(table_name);
+ child_l->table_name_length= table_name_len;
child_l->table_name= strmake_root(&parent->mem_root, table_name,
child_l->table_name_length);
/* Convert to lowercase if required. */
@@ -1132,7 +1138,7 @@ int ha_myisammrg::create(const char *nam
/* Create child path names. */
for (pos= table_names; tables; tables= tables->next_local)
{
- const char *table_name;
+ const char *table_name= buff;
/*
Construct the path to the MyISAM table. Try to meet two conditions:
@@ -1158,10 +1164,12 @@ int ha_myisammrg::create(const char *nam
as the MyISAM tables are from the same database as the MERGE table.
*/
if ((dirname_length(buff) == dirlgt) && ! memcmp(buff, name, dirlgt))
- table_name= tables->table_name;
- else
- if (! (table_name= thd->strmake(buff, length)))
- DBUG_RETURN(HA_ERR_OUT_OF_MEM); /* purecov: inspected */
+ {
+ table_name+= dirlgt;
+ length-= dirlgt;
+ }
+ if (! (table_name= thd->strmake(table_name, length)))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM); /* purecov: inspected */
*pos++= table_name;
}
@@ -1182,7 +1190,7 @@ void ha_myisammrg::append_create_info(St
const char *current_db;
size_t db_length;
THD *thd= current_thd;
- MYRG_TABLE *open_table, *first;
+ TABLE_LIST *open_table, *first;
if (file->merge_insert_method != MERGE_INSERT_DISABLED)
{
@@ -1200,14 +1208,11 @@ void ha_myisammrg::append_create_info(St
current_db= table->s->db.str;
db_length= table->s->db.length;
- for (first=open_table=file->open_tables ;
- open_table != file->end_table ;
- open_table++)
+ for (first= open_table= table->child_l;;
+ open_table= open_table->next_global)
{
- LEX_STRING db, name;
- LINT_INIT(db.str);
+ LEX_STRING db= { open_table->db, open_table->db_length };
- split_file_name(open_table->table->filename, &db, &name);
if (open_table != first)
packet->append(',');
/* Report database for mapped table if it isn't in current database */
@@ -1218,7 +1223,10 @@ void ha_myisammrg::append_create_info(St
append_identifier(thd, packet, db.str, db.length);
packet->append('.');
}
- append_identifier(thd, packet, name.str, name.length);
+ append_identifier(thd, packet, open_table->table_name,
+ open_table->table_name_length);
+ if (&open_table->next_global == table->child_last_l)
+ break;
}
packet->append(')');
}
Attachment: [text/bzr-bundle] bzr/svoj@sun.com-20100208130748-e2thrynxeu2sglqk.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-bugteam branch (svoj:3372) Bug#48265 | Sergey Vojtovich | 8 Feb |