#At file:///home/satya/WORK/mysql-6.0-bug-36573/
2902 Satya B 2008-11-07
Fix for Bug#36573 myisampack --join does not create destination table .frm file
Problem:
========
Myisampack --join doesn't create the destination table .frm file. The user has 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
=================
added create_dest_frm(source table, dest table) which copies the "FIRST" tables frm file
as the destination frm file.
It is invoked only after the compression succeeds.(after compress(...) )
Note to maintain the existing behaviour of myisampack, the create_dest_frm returns always
true, which means after the compression,while creating .frm file, if it finds an existing
.frm file , it doesn't overwrite it and we return command status as success.
Functionality added
===================
./myisampack --join=/home/satya/WORK/mysql-bin-5.1-bug-36573/var/test/t3 /home/satya/WORK
/mysql-bin-5.1-bug-36573/var/test/t2 /home/satya/WORK/mysql-bin-5.1-bug-36573/var/test/t1
creates /home/satya/WORK/mysql-bin-5.1-bug-36573/var/test/t3.frm (which is bascially
copied from first table's frm /home/satya/WORK/mysql-bin-5.1-bug-36573/var/test/t2)
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. Negative myisampack --join test
We test myisampack --join existing .MYI,.MDI,.frm files for the destination table.It
should fail with exit status 2 in this case.
modified:
mysql-test/r/myisampack.result
mysql-test/t/myisampack.test
storage/myisam/myisampack.c
per-file messages:
mysql-test/r/myisampack.result
Modified result file for myisampack --join operation
Added result for positive and negative myisampack --join tests
mysql-test/t/myisampack.test
added positive and negative tests for myisampack --join operation
storage/myisam/myisampack.c
added create_dest_frm(..) to create .frm file for destination table for myisampack --join
operation
=== modified file 'mysql-test/r/myisampack.result'
--- a/mysql-test/r/myisampack.result 2007-11-07 08:55:28 +0000
+++ b/mysql-test/r/myisampack.result 2008-11-07 14:48:28 +0000
@@ -27,3 +27,44 @@ CHECK TABLE t1 EXTENDED;
Table Op Msg_type Msg_text
test.t1 check status OK
DROP TABLE t1;
+# ===== myisampack.1 =====
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1(a int);
+INSERT INTO t1 VALUES(20);
+INSERT INTO t1 SELECT ROUND(a*RAND()*10) from t1;
+INSERT INTO t1 SELECT ROUND(a*RAND()*10) from t1;
+INSERT INTO t1 SELECT ROUND(a*RAND()*10) from t1;
+INSERT INTO t1 SELECT ROUND(a*RAND()*10) from t1;
+INSERT INTO t1 SELECT ROUND(a*RAND()*10) from t1;
+INSERT INTO t1 SELECT ROUND(a*RAND()*10) from t1;
+INSERT INTO t1 SELECT ROUND(a*RAND()*10) from t1;
+INSERT INTO t1 SELECT ROUND(a*RAND()*10) from t1;
+INSERT INTO t1 SELECT ROUND(a*RAND()*10) from t1;
+DROP TABLE IF EXISTS t2;
+CREATE TABLE t2(a int);
+INSERT INTO t2 VALUES(40);
+INSERT INTO t2 SELECT ROUND(a*RAND()*10) from t2;
+INSERT INTO t2 SELECT ROUND(a*RAND()*10) from t2;
+INSERT INTO t2 SELECT ROUND(a*RAND()*10) from t2;
+INSERT INTO t2 SELECT ROUND(a*RAND()*10) from t2;
+INSERT INTO t2 SELECT ROUND(a*RAND()*10) from t2;
+INSERT INTO t2 SELECT ROUND(a*RAND()*10) from t2;
+INSERT INTO t2 SELECT ROUND(a*RAND()*10) from t2;
+INSERT INTO t2 SELECT ROUND(a*RAND()*10) from t2;
+INSERT INTO t2 SELECT ROUND(a*RAND()*10) from 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 =====
+#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 =====
+#Tests the myisampack join operation with an existing destination .frm,.MYI,.MDI
+#the command should fail with exit status 2
+DROP TABLE t1,t2,t3;
=== modified file 'mysql-test/t/myisampack.test'
--- a/mysql-test/t/myisampack.test 2007-11-07 08:55:28 +0000
+++ b/mysql-test/t/myisampack.test 2008-11-07 14:48:28 +0000
@@ -31,3 +31,85 @@ FLUSH TABLES;
--exec $MYISAMCHK -s --unpack $MYSQLTEST_VARDIR/master-data/test/t1
CHECK TABLE t1 EXTENDED;
DROP TABLE t1;
+#
+# 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 =====
+
+-- disable_warnings
+DROP TABLE IF EXISTS t1;
+-- enable_warnings
+
+CREATE TABLE t1(a int);
+
+INSERT INTO t1 VALUES(20);
+
+let $i=9;
+while ($i)
+{
+ INSERT INTO t1 SELECT ROUND(a*RAND()*10) from t1;
+ dec $i;
+}
+
+-- disable_warnings
+DROP TABLE IF EXISTS t2;
+-- enable_warnings
+
+CREATE TABLE t2(a int);
+
+INSERT INTO t2 VALUES(40);
+
+let $i=9;
+while ($i)
+{
+ INSERT INTO t2 SELECT ROUND(a*RAND()*10) from t2;
+ dec $i;
+}
+
+--exec $MYISAMPACK --join=$MYSQLTEST_VARDIR/master-data/test/t3 $MYSQLTEST_VARDIR/master-data/test/t1 $MYSQLTEST_VARDIR/master-data/test/t2
+
+--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 $MYSQLTEST_VARDIR/master-data/test/t3.MYI
+--remove_file $MYSQLTEST_VARDIR/master-data/test/t3.MYD
+--exec $MYISAMPACK --join=$MYSQLTEST_VARDIR/master-data/test/t3 $MYSQLTEST_VARDIR/master-data/test/t1 $MYSQLTEST_VARDIR/master-data/test/t2
+--error 0
+
+--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: Negative test for myisampack --join
+# Test myisampack join operation with an existing .MYI,.MDI,.frm files
+# the test should fail
+#############################################################################
+-- echo # ===== myisampack.3 =====
+
+--echo #Tests the myisampack join operation with an existing destination .frm,.MYI,.MDI
+--echo #the command should fail with exit status 2
+
+--error 2
+--exec $MYISAMPACK --join=$MYSQLTEST_VARDIR/master-data/test/t3 $MYSQLTEST_VARDIR/master-data/test/t1 $MYSQLTEST_VARDIR/master-data/test/t2
+
+DROP TABLE t1,t2,t3;
=== modified file 'storage/myisam/myisampack.c'
--- a/storage/myisam/myisampack.c 2008-07-09 07:12:43 +0000
+++ b/storage/myisam/myisampack.c 2008-11-07 14:48:28 +0000
@@ -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 *
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--)
@@ -762,6 +768,30 @@ static int compress(PACK_MRG_INFO *mrg,c
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
+*/
+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);
+
+ (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)