From 4a70a6dcc1217e4418c13213cf74285975de3ea1 Mon Sep 17 00:00:00 2001 From: Magne Mahre Date: Wed, 25 Nov 2009 19:29:52 +0100 Subject: [PATCH 1/6] Bug#40677 Archive tables joined on primary return no result Select queries on archive tables when joined on their primary keys returns no results(empty set) Archive storage doesn't inform the handler about the fetched record status when it is found. Fixed the archive storage engine to update the record status when it fetches successfully --- mysql-test/r/archive.result | 10 ++++++++++ mysql-test/t/archive.test | 12 ++++++++++++ storage/archive/ha_archive.cc | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/mysql-test/r/archive.result b/mysql-test/r/archive.result index e865d775c6a..a250821d12b 100644 --- a/mysql-test/r/archive.result +++ b/mysql-test/r/archive.result @@ -12717,3 +12717,13 @@ COUNT(t1.a) 729 DROP TABLE t1; SET @@join_buffer_size= @save_join_buffer_size; +End of 5.1 tests +CREATE TABLE t1(id INT NOT NULL AUTO_INCREMENT, name VARCHAR(128) NOT NULL, PRIMARY KEY(id)) ENGINE=archive; +INSERT INTO t1 VALUES(NULL,'a'),(NULL,'a'); +CREATE TABLE t2(id INT NOT NULL AUTO_INCREMENT, name VARCHAR(128) NOT NULL, PRIMARY KEY(id)) ENGINE=archive; +INSERT INTO t2 VALUES(NULL,'b'),(NULL,'b'); +SELECT t1.id, t2.id, t1.name, t2.name FROM t1,t2 WHERE t1.id = t2.id; +id id name name +1 1 a b +2 2 a b +DROP TABLE t1,t2; diff --git a/mysql-test/t/archive.test b/mysql-test/t/archive.test index aad3d19455d..a27efcf9583 100644 --- a/mysql-test/t/archive.test +++ b/mysql-test/t/archive.test @@ -1623,3 +1623,15 @@ INSERT INTO t1 VALUES('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), SELECT COUNT(t1.a) FROM t1, t1 a, t1 b, t1 c, t1 d, t1 e; DROP TABLE t1; SET @@join_buffer_size= @save_join_buffer_size; + +--echo End of 5.1 tests + +# +# BUG#40677 - Archive tables joined on primary return no result +# +CREATE TABLE t1(id INT NOT NULL AUTO_INCREMENT, name VARCHAR(128) NOT NULL, PRIMARY KEY(id)) ENGINE=archive; +INSERT INTO t1 VALUES(NULL,'a'),(NULL,'a'); +CREATE TABLE t2(id INT NOT NULL AUTO_INCREMENT, name VARCHAR(128) NOT NULL, PRIMARY KEY(id)) ENGINE=archive; +INSERT INTO t2 VALUES(NULL,'b'),(NULL,'b'); +SELECT t1.id, t2.id, t1.name, t2.name FROM t1,t2 WHERE t1.id = t2.id; +DROP TABLE t1,t2; diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index a341843662f..f69b19369b2 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -953,7 +953,11 @@ int ha_archive::index_read_idx(uchar *buf, uint index, const uchar *key, } if (found) + { + /* notify handler that a record has been found */ + table->status= 0; DBUG_RETURN(0); + } error: DBUG_RETURN(rc ? rc : HA_ERR_END_OF_FILE); From 412c6c4bd7b6b21fc1ccdf25b0d69daa2ebbfcc5 Mon Sep 17 00:00:00 2001 From: Magne Mahre Date: Wed, 25 Nov 2009 19:49:30 +0100 Subject: [PATCH 2/6] Disable the testcase for BUG#45816 in partition.test in mysql-pe branch due to BUG#46853 Commented out the testcase for Bug#45816 in mysql-pe branch due to valgrind warnings. Please see Bug#46853 --- mysql-test/r/partition.result | 19 ----------------- mysql-test/t/partition.test | 39 ++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index 065e46dbf92..543a70f9a2a 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -2048,23 +2048,4 @@ CREATE TABLE t1(id INT,KEY(id)) ENGINE=MYISAM PARTITION BY HASH(id) PARTITIONS 2; DROP TABLE t1; SET SESSION SQL_MODE=DEFAULT; -# -# BUG#45816 - assertion failure with index containing double -# column on partitioned table -# -CREATE TABLE t1 ( -a INT DEFAULT NULL, -b DOUBLE DEFAULT NULL, -c INT DEFAULT NULL, -KEY idx2(b,a) -) PARTITION BY HASH(c) PARTITIONS 3; -INSERT INTO t1 VALUES (6,8,9); -INSERT INTO t1 VALUES (6,8,10); -SELECT 1 FROM t1 JOIN t1 AS t2 USING (a) FOR UPDATE; -1 -1 -1 -1 -1 -DROP TABLE t1; End of 5.1 tests diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 459acc9f1f5..8ab91f23522 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -2039,23 +2039,24 @@ CREATE TABLE t1(id INT,KEY(id)) ENGINE=MYISAM DROP TABLE t1; SET SESSION SQL_MODE=DEFAULT; - ---echo # ---echo # BUG#45816 - assertion failure with index containing double ---echo # column on partitioned table ---echo # - -CREATE TABLE t1 ( - a INT DEFAULT NULL, - b DOUBLE DEFAULT NULL, - c INT DEFAULT NULL, - KEY idx2(b,a) -) PARTITION BY HASH(c) PARTITIONS 3; - -INSERT INTO t1 VALUES (6,8,9); -INSERT INTO t1 VALUES (6,8,10); - -SELECT 1 FROM t1 JOIN t1 AS t2 USING (a) FOR UPDATE; - -DROP TABLE t1; +# This testcase is commented due to the Bug #46853 +# Should be uncommented after fixing Bug #46853 +#--echo # +#--echo # BUG#45816 - assertion failure with index containing double +#--echo # column on partitioned table +#--echo # +# +#CREATE TABLE t1 ( +# a INT DEFAULT NULL, +# b DOUBLE DEFAULT NULL, +# c INT DEFAULT NULL, +# KEY idx2(b,a) +#) PARTITION BY HASH(c) PARTITIONS 3; +# +#INSERT INTO t1 VALUES (6,8,9); +#INSERT INTO t1 VALUES (6,8,10); +# +#SELECT 1 FROM t1 JOIN t1 AS t2 USING (a) FOR UPDATE; +# +#DROP TABLE t1; --echo End of 5.1 tests From 6002c1adeb6a2cd8edb0fa0045aa74a393712dd4 Mon Sep 17 00:00:00 2001 From: Magne Mahre Date: Wed, 25 Nov 2009 20:19:59 +0100 Subject: [PATCH 3/6] Fix for Bug#36573 myisampack --join does not create destination table .frm file Problem: ======== Myisampack --join did not create the destination table .frm file. The user had to copy one of the source table .frm file as destination .frm file for mysql server to recognize. This is just 'user-friendliness' issue. How it was solved ================= After successful join and compression we copy the frm file from the first source table. Functionality added =================== myisampack --join=/path/t3 /path/t1 /path/t2 creates /path/t3.frm (which is bascially copied from first table's frm /path/t1) Tests ===== Modified myisampack.test to test two scenario's 1. Positive myisampack --join test In this case after the join operation is done,we test if the destination table is accessible from the server 2. Positive myisampack --join test with an existing .frm file. We test the above case with an existing .frm file for the destination table. It should return success even in this case. 3. Positive myisampack --join test with no .frm file for source tables We test the join operation with no .frm files for source tables. It should complete the join operation without any warnings and error messages 4. Negative myisampack --join test We test myisampack --join with existing .MYI,.MDI,.frm files for the destination table. It should fail with exit status 2 in this case. --- mysql-test/r/myisampack.result | 30 +++++++++ mysql-test/t/myisampack.test | 112 +++++++++++++++++++++++++++++++++ storage/myisam/myisampack.c | 49 ++++++++++++++- 3 files changed, 189 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/myisampack.result b/mysql-test/r/myisampack.result index fbcd8aed17a..3f94669108f 100644 --- a/mysql-test/r/myisampack.result +++ b/mysql-test/r/myisampack.result @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS t1,t2,t3; CREATE TABLE t1(c1 DOUBLE, c2 DOUBLE, c3 DOUBLE, c4 DOUBLE, c5 DOUBLE, c6 DOUBLE, c7 DOUBLE, c8 DOUBLE, c9 DOUBLE, a INT PRIMARY KEY); INSERT INTO t1 VALUES @@ -85,5 +86,34 @@ FLUSH TABLE mysql_db1.t1; SELECT COUNT(*) FROM mysql_db1.t1 WHERE c2 < 5; COUNT(*) 128 +# ===== myisampack.1 ===== +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES(20); +CREATE TABLE t2(a INT); +INSERT INTO t2 VALUES(40); +#If the myisampack --join operation is successful, we have table t3(.frm) +#so we should be able to query about the table from server. +SELECT COUNT(a) FROM t3; +COUNT(a) +1024 +# ===== myisampack.2 ===== +#Tests the myisampack join operation with an existing destination .frm file, +#the command should return correct exit status(0) and +#we should be able to query the table. +SELECT COUNT(a) FROM t3; +COUNT(a) +1024 +# ===== myisampack.3 ===== +DROP TABLE t3; +#Tests the myisampack join operation without frm file for the first and second table +#No frm file is generated in this and we shouldn't be able to access the newly +#created table +SELECT COUNT(a) FROM t3; +ERROR 42S02: Table 'test.t3' doesn't exist +# ===== myisampack.4 ===== +#Tests the myisampack join operation with an existing destination .frm,.MYI,.MDI +#the command should fail with exit status 2 +/data/z/mysql-next-mr-runtime/mysql-test/var/mysqld.1/data//master-data/test/t1 gave error 2 on open +DROP TABLE t1,t2,t3; DROP TABLE mysql_db1.t1; DROP DATABASE mysql_db1; diff --git a/mysql-test/t/myisampack.test b/mysql-test/t/myisampack.test index 9d27ed53254..38197980c6f 100644 --- a/mysql-test/t/myisampack.test +++ b/mysql-test/t/myisampack.test @@ -1,3 +1,6 @@ +-- disable_warnings +DROP TABLE IF EXISTS t1,t2,t3; +-- enable_warnings # # BUG#31277 - myisamchk --unpack corrupts a table # @@ -105,5 +108,114 @@ let $MYSQLD_DATADIR= `select @@datadir`; --exec $MYISAMCHK -srq $MYSQLD_DATADIR/mysql_db1/t1 SELECT COUNT(*) FROM mysql_db1.t1 WHERE c2 < 5; # +# Bug#36573 myisampack --join does not create destination table .frm file +# +############################################################################# +# Testcase myisampack.1: Positive test for myisampack --join +# To test myisampack --join operation creates .frm file +# If it creates .frm file, we will be able to access from mysql +# server +############################################################################# +--echo # ===== myisampack.1 ===== +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES(20); + +let $i=9; +--disable_query_log +while ($i) +{ + INSERT INTO t1 SELECT ROUND(a * RAND() * 10) from t1; + dec $i; +} +--enable_query_log + +CREATE TABLE t2(a INT); +INSERT INTO t2 VALUES(40); + +let $i=9; +--disable_query_log +while ($i) +{ + INSERT INTO t2 SELECT ROUND(a * RAND() * 10) from t2; + dec $i; +} +--enable_query_log + +--exec $MYISAMPACK --join=$MYSQLD_DATADIR/test/t3 $MYSQLD_DATADIR/test/t1 $MYSQLD_DATADIR/test/t2 2>&1 + +--echo #If the myisampack --join operation is successful, we have table t3(.frm) +--echo #so we should be able to query about the table from server. +SELECT COUNT(a) FROM t3; + +############################################################################# +# Testcase myisampack.2: 2nd Positive test for myisampack --join +# Test myisampack join operation with an existing destination frm file. +# It should finish the join operation successfully +############################################################################# +--echo # ===== myisampack.2 ===== +--remove_file $MYSQLD_DATADIR/test/t3.MYI +--remove_file $MYSQLD_DATADIR/test/t3.MYD +--exec $MYISAMPACK --join=$MYSQLD_DATADIR/test/t3 $MYSQLD_DATADIR/test/t1 $MYSQLD_DATADIR/test/t2 2>&1 +--echo #Tests the myisampack join operation with an existing destination .frm file, +--echo #the command should return correct exit status(0) and +--echo #we should be able to query the table. + +SELECT COUNT(a) FROM t3; + +############################################################################# +# Testcase myisampack.3: 3rd Positive test for myisampack --join +# Test myisampack join operation without frm file for first table and second +# table. It should finish the join operation successfully +############################################################################# +--echo # ===== myisampack.3 ===== +--copy_file $MYSQLD_DATADIR/test/t1.frm $MYSQLTEST_VARDIR/tmp/bug36573.t1.frm +--copy_file $MYSQLD_DATADIR/test/t2.frm $MYSQLTEST_VARDIR/tmp/bug36573.t2.frm +--remove_file $MYSQLD_DATADIR/test/t1.frm +--remove_file $MYSQLD_DATADIR/test/t2.frm + +DROP TABLE t3; +--exec $MYISAMPACK --join=$MYSQLD_DATADIR/test/t3 $MYSQLD_DATADIR/test/t1 $MYSQLD_DATADIR/test/t2 2>&1 +--echo #Tests the myisampack join operation without frm file for the first and second table +--echo #No frm file is generated in this and we shouldn't be able to access the newly +--echo #created table + +--error ER_NO_SUCH_TABLE +SELECT COUNT(a) FROM t3; + +--copy_file $MYSQLTEST_VARDIR/tmp/bug36573.t1.frm $MYSQLD_DATADIR/test/t1.frm +--copy_file $MYSQLTEST_VARDIR/tmp/bug36573.t2.frm $MYSQLD_DATADIR/test/t2.frm +--copy_file $MYSQLTEST_VARDIR/tmp/bug36573.t1.frm $MYSQLD_DATADIR/test/t3.frm +--remove_file $MYSQLTEST_VARDIR/tmp/bug36573.t1.frm +--remove_file $MYSQLTEST_VARDIR/tmp/bug36573.t2.frm + +############################################################################# +# Testcase myisampack.4: Negative test for myisampack --join +# Test myisampack join operation with an existing .MYI,.MDI,.frm files +# the test should fail +############################################################################# +--echo # ===== myisampack.4 ===== +--echo #Tests the myisampack join operation with an existing destination .frm,.MYI,.MDI +--echo #the command should fail with exit status 2 +# +# Note: Use of regular expressions in this file is for output printed in result file +# The main purpose of this regular expression is to supress the filenames for +# error messages produced so that we can create a generic result file +# +#1. /.*myisampack(\.exe)?: Can't create\/write to file .*\(/myisampack: Can't create\/write to file (/ +# Replace everything before "myisampack" or "myisampack.exe" and followed by +# ": Can't create\/write to file " until the first open paranthesis , with +# "myisampack: Can't create\/write to file (" +# +#2. /Aborted: .*is/Aborted: file is/ +# Replace everything after starting with "Aborted: " until ending with "is" with +# "Aborted: file is/ +# +--replace_regex /.*myisampack(\.exe)?: Can't create\/write to file .*\(/myisampack: Can't create\/write to file (/ /Aborted: .*is/Aborted: file is/ +--error 2 +--exec $MYISAMPACK --join=$MYSQLD_DATADIR/test/t3 $MYSQLD_DATADIR/master-data/test/t1 $MYSQLD_DATADIR/test/t2 2>&1 + +DROP TABLE t1,t2,t3; + DROP TABLE mysql_db1.t1; DROP DATABASE mysql_db1; + diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c index 8adfcfd6fb2..7cd84b642e4 100644 --- a/storage/myisam/myisampack.c +++ b/storage/myisam/myisampack.c @@ -44,6 +44,7 @@ #define DATA_TMP_EXT ".TMD" #define OLD_EXT ".OLD" +#define FRM_EXT ".frm" #define WRITE_COUNT MY_HOW_OFTEN_TO_WRITE struct st_file_buffer { @@ -125,6 +126,7 @@ static void get_options(int *argc,char ***argv); static MI_INFO *open_isam_file(char *name,int mode); static my_bool open_isam_files(PACK_MRG_INFO *mrg,char **names,uint count); static int compress(PACK_MRG_INFO *file,char *join_name); +static int create_dest_frm(char *source_table, char *dest_table); static HUFF_COUNTS *init_huff_count(MI_INFO *info,my_off_t records); static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees, uint trees, @@ -214,9 +216,13 @@ int main(int argc, char **argv) error=ok=isamchk_neaded=0; if (join_table) - { /* Join files into one */ + { + /* + Join files into one and create FRM file for the compressed table only if + the compression succeeds + */ if (open_isam_files(&merge,argv,(uint) argc) || - compress(&merge,join_table)) + compress(&merge, join_table) || create_dest_frm(argv[0], join_table)) error=1; } else while (argc--) @@ -757,6 +763,45 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) DBUG_RETURN(-1); } + +/** + Create FRM for the destination table for --join operation + Copy the first table FRM as the destination table FRM file. Doing so + will help the mysql server to recognize the newly created table. + See Bug#36573. + + @param source_table Name of the source table + @param dest_table Name of the destination table + @retval 0 Successful copy operation + + @note We always return 0 because we don't want myisampack to report error + even if the copy operation fails. +*/ + +static int create_dest_frm(char *source_table, char *dest_table) +{ + char source_name[FN_REFLEN], dest_name[FN_REFLEN]; + int error; + + DBUG_ENTER("create_dest_frm"); + + (void) fn_format(source_name, source_table, + "", FRM_EXT, MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS); + (void) fn_format(dest_name, dest_table, + "", FRM_EXT, MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS); + /* + Error messages produced by my_copy() are suppressed as this + is not vital for --join operation. User shouldn't see any error messages + like "source file frm not found" and "unable to create destination frm + file. So we don't pass the flag MY_WME -Write Message on Error to + my_copy() + */ + (void) my_copy(source_name, dest_name, MYF(MY_DONT_OVERWRITE_FILE)); + + return 0; +} + + /* Init a huff_count-struct for each field and init it */ static HUFF_COUNTS *init_huff_count(MI_INFO *info,my_off_t records) From 3be9052153ee41af11b8385269c3a97261f63141 Mon Sep 17 00:00:00 2001 From: Magne Mahre Date: Wed, 25 Nov 2009 20:22:45 +0100 Subject: [PATCH 4/6] Addition to BUG#36573 - myisampack --join does not create destination table .frm file Added FLUSH TABLES before myisampack --join operation to fix the test warnings or errors Removed unused variable in create_dest_frm() method --- mysql-test/r/myisampack.result | 2 ++ mysql-test/t/myisampack.test | 6 ++++-- storage/myisam/myisampack.c | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/myisampack.result b/mysql-test/r/myisampack.result index 3f94669108f..1efde35ba9f 100644 --- a/mysql-test/r/myisampack.result +++ b/mysql-test/r/myisampack.result @@ -91,12 +91,14 @@ CREATE TABLE t1(a INT); INSERT INTO t1 VALUES(20); CREATE TABLE t2(a INT); INSERT INTO t2 VALUES(40); +FLUSH TABLE t1,t2; #If the myisampack --join operation is successful, we have table t3(.frm) #so we should be able to query about the table from server. SELECT COUNT(a) FROM t3; COUNT(a) 1024 # ===== myisampack.2 ===== +FLUSH TABLE t3; #Tests the myisampack join operation with an existing destination .frm file, #the command should return correct exit status(0) and #we should be able to query the table. diff --git a/mysql-test/t/myisampack.test b/mysql-test/t/myisampack.test index 38197980c6f..6f1ac24a507 100644 --- a/mysql-test/t/myisampack.test +++ b/mysql-test/t/myisampack.test @@ -124,7 +124,7 @@ let $i=9; --disable_query_log while ($i) { - INSERT INTO t1 SELECT ROUND(a * RAND() * 10) from t1; + INSERT INTO t1 SELECT a from t1; dec $i; } --enable_query_log @@ -136,11 +136,12 @@ let $i=9; --disable_query_log while ($i) { - INSERT INTO t2 SELECT ROUND(a * RAND() * 10) from t2; + INSERT INTO t2 SELECT a from t2; dec $i; } --enable_query_log +FLUSH TABLE t1,t2; --exec $MYISAMPACK --join=$MYSQLD_DATADIR/test/t3 $MYSQLD_DATADIR/test/t1 $MYSQLD_DATADIR/test/t2 2>&1 --echo #If the myisampack --join operation is successful, we have table t3(.frm) @@ -153,6 +154,7 @@ SELECT COUNT(a) FROM t3; # It should finish the join operation successfully ############################################################################# --echo # ===== myisampack.2 ===== +FLUSH TABLE t3; --remove_file $MYSQLD_DATADIR/test/t3.MYI --remove_file $MYSQLD_DATADIR/test/t3.MYD --exec $MYISAMPACK --join=$MYSQLD_DATADIR/test/t3 $MYSQLD_DATADIR/test/t1 $MYSQLD_DATADIR/test/t2 2>&1 diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c index 7cd84b642e4..fec6d32133e 100644 --- a/storage/myisam/myisampack.c +++ b/storage/myisam/myisampack.c @@ -781,7 +781,6 @@ static int compress(PACK_MRG_INFO *mrg,char *result_table) static int create_dest_frm(char *source_table, char *dest_table) { char source_name[FN_REFLEN], dest_name[FN_REFLEN]; - int error; DBUG_ENTER("create_dest_frm"); From eea7af04c01bef3a9e1706bc3212fc117304d939 Mon Sep 17 00:00:00 2001 From: Magne Mahre Date: Thu, 26 Nov 2009 13:47:55 +0100 Subject: [PATCH 5/6] Fix for a bug when backporting/merging Bug#36573 --- mysql-test/r/myisampack.result | 3 ++- mysql-test/t/myisampack.test | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/myisampack.result b/mysql-test/r/myisampack.result index 1efde35ba9f..dd14c31f32e 100644 --- a/mysql-test/r/myisampack.result +++ b/mysql-test/r/myisampack.result @@ -115,7 +115,8 @@ ERROR 42S02: Table 'test.t3' doesn't exist # ===== myisampack.4 ===== #Tests the myisampack join operation with an existing destination .frm,.MYI,.MDI #the command should fail with exit status 2 -/data/z/mysql-next-mr-runtime/mysql-test/var/mysqld.1/data//master-data/test/t1 gave error 2 on open +myisampack: Can't create/write to file (Errcode: 17) +Aborted: file is not compressed DROP TABLE t1,t2,t3; DROP TABLE mysql_db1.t1; DROP DATABASE mysql_db1; diff --git a/mysql-test/t/myisampack.test b/mysql-test/t/myisampack.test index 6f1ac24a507..463aa559de2 100644 --- a/mysql-test/t/myisampack.test +++ b/mysql-test/t/myisampack.test @@ -214,7 +214,7 @@ SELECT COUNT(a) FROM t3; # --replace_regex /.*myisampack(\.exe)?: Can't create\/write to file .*\(/myisampack: Can't create\/write to file (/ /Aborted: .*is/Aborted: file is/ --error 2 ---exec $MYISAMPACK --join=$MYSQLD_DATADIR/test/t3 $MYSQLD_DATADIR/master-data/test/t1 $MYSQLD_DATADIR/test/t2 2>&1 +--exec $MYISAMPACK --join=$MYSQLD_DATADIR/test/t3 $MYSQLD_DATADIR/test/t1 $MYSQLD_DATADIR/test/t2 2>&1 DROP TABLE t1,t2,t3; From a94150cdcb54a1f982c19cc1ab591d9e989bdfb1 Mon Sep 17 00:00:00 2001 From: Magne Mahre Date: Thu, 26 Nov 2009 20:24:08 +0100 Subject: [PATCH 6/6] Bug#39277 - symlink.test fails on Debian When the data directory contained a symbolic link to another file system, and the DATA or INDEX DIRECTORY clause of a CREATE TABLE statement referred to a subdirectory of the data directory, this was accepted. The problem was the use of a table file path name, which included the table name without an extension, for the comparison against the data directory path name. This was almost always a non-existent file. The internal algorithm failed to resolve symbolic links for non-existent files. So we compared unrelated path names. Fixed by truncating the table name from the path before resolving symlinks. If this is also a non-existent path, the creation of the table will fail anyway. Backport to 5.6.0. 6.0-codebase revid: 2599.60.1 --- sql/sql_table.cc | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index dc0c876e882..c8c715472dc 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3934,15 +3934,43 @@ bool mysql_create_table_no_lock(THD *thd, create_info->table_existed= 0; // Mark that table is created #ifdef HAVE_READLINK - if (test_if_data_home_dir(create_info->data_file_name)) { - my_error(ER_WRONG_ARGUMENTS, MYF(0), "DATA DIRECTORY"); - goto unlock_and_end; - } - if (test_if_data_home_dir(create_info->index_file_name)) - { - my_error(ER_WRONG_ARGUMENTS, MYF(0), "INDEX DIRECTORY"); - goto unlock_and_end; + size_t dirlen; + char dirpath[FN_REFLEN]; + + /* + data_file_name and index_file_name include the table name without + extension. Mostly this does not refer to an existing file. When + comparing data_file_name or index_file_name against the data + directory, we try to resolve all symbolic links. On some systems, + we use realpath(3) for the resolution. This returns ENOENT if the + resolved path does not refer to an existing file. my_realpath() + does then copy the requested path verbatim, without symlink + resolution. Thereafter the comparison can fail even if the + requested path is within the data directory. E.g. if symlinks to + another file system are used. To make realpath(3) return the + resolved path, we strip the table name and compare the directory + path only. If the directory doesn't exist either, table creation + will fail anyway. + */ + if (create_info->data_file_name) + { + dirname_part(dirpath, create_info->data_file_name, &dirlen); + if (test_if_data_home_dir(dirpath)) + { + my_error(ER_WRONG_ARGUMENTS, MYF(0), "DATA DIRECTORY"); + goto unlock_and_end; + } + } + if (create_info->index_file_name) + { + dirname_part(dirpath, create_info->index_file_name, &dirlen); + if (test_if_data_home_dir(dirpath)) + { + my_error(ER_WRONG_ARGUMENTS, MYF(0), "INDEX DIRECTORY"); + goto unlock_and_end; + } + } } #ifdef WITH_PARTITION_STORAGE_ENGINE