Bug #26782 Patch: myisamchk -rq creates .MYI.MYI file on packed MyISAM tables
Submitted: 2 Mar 2007 4:01 Modified: 13 Apr 2007 18:12
Reporter: David Shrewsbury Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.17-BK OS:Linux (Linux)
Assigned to: Ingo Strüwing CPU Architecture:Any
Tags: Contribution, qc, regression

[2 Mar 2007 4:01] David Shrewsbury
Description:
When running 'myisamchk -rq' for a MyISAM table that has been compressed with 'myisampack', the new index file that is created is named with a .MYI.MYI extension and the old .MYI file is not replaced. This behavior only happens when the table name given to the 'myisamchk' program contains the .MYI extension. If the table is named without the extension (which is allowed, too), then the index file is replaced correctly.

How to repeat:
bash> mysql test -e "CREATE TABLE t (col1 CHAR(255), INDEX(col1))"
bash> mysqladmin -u root shutdown
bash> myisampack t.MYI
bash> myisamchk -rq t.MYI

bash> ls -l
-rw-rw---- 1 shrews shrews 8560 2007-03-01 21:41 t.frm
-rw-rw---- 1 shrews shrews   48 2007-03-01 21:41 t.MYD
-rw-rw---- 1 shrews shrews 2048 2007-03-01 21:41 t.MYI
-rw-r----- 1 shrews shrews 2048 2007-03-01 21:43 t.MYI.MYI

The expected result is to have t.MYI replaced with a file of the same name.

NOTE: Workaround is to name the table WITHOUT the .MYI extension.
Example:  myisamchk -rq t

Suggested fix:
See patch
[2 Mar 2007 4:01] David Shrewsbury
Patch for the mi_create.c file.

Attachment: mi_create.patch (application/octet-stream, text), 640 bytes.

[2 Mar 2007 6:30] Valeriy Kravchuk
Thank you for a bug report. Verified just as described with 5.1.17-BK on Linux:

openxs@suse:~/dbs/5.1> bin/mysql -uroot test -e "CREATE TABLE tt(c1 int, index(c1))"
openxs@suse:~/dbs/5.1> bin/mysqladmin -uroot shutdown
STOPPING server from pid file /home/openxs/dbs/5.1/var/suse.pid
070302 07:32:58  mysqld ended

[1]+  Done                    bin/mysqld_safe
openxs@suse:~/dbs/5.1> cd var/test
openxs@suse:~/dbs/5.1/var/test> ls -l tt*
-rw-rw----  1 openxs users 8556 2007-03-02 07:32 tt.frm
-rw-rw----  1 openxs users    0 2007-03-02 07:32 tt.MYD
-rw-rw----  1 openxs users 1024 2007-03-02 07:32 tt.MYI
-rw-rw----  1 openxs users 8582 2006-09-18 11:14 ttt.frm
-rw-rw----  1 openxs users    0 2006-09-18 11:14 ttt.MYD
-rw-rw----  1 openxs users 1024 2006-09-18 11:14 ttt.MYI
openxs@suse:~/dbs/5.1/var/test> ../../bin/myisampack tt.MYI
Compressing tt.MYD: (0 records)
- Calculating statistics
- Compressing file
Empty file saved in compressed format
Remember to run myisamchk -rq on compressed tables
openxs@suse:~/dbs/5.1/var/test> ../../bin/myisamchk -rq tt.MYI
- check record delete-chain
- recovering (with sort) MyISAM-table 'tt.MYI'
Data records: 0
- Fixing index 1
openxs@suse:~/dbs/5.1/var/test> ls -l tt*
-rw-rw----  1 openxs users 8556 2007-03-02 07:32 tt.frm
-rw-rw----  1 openxs users   48 2007-03-02 07:32 tt.MYD
-rw-rw----  1 openxs users 1024 2007-03-02 07:33 tt.MYI
-rw-r-----  1 openxs users 1024 2007-03-02 07:33 tt.MYI.MYI
-rw-rw----  1 openxs users 8582 2006-09-18 11:14 ttt.frm
-rw-rw----  1 openxs users    0 2006-09-18 11:14 ttt.MYD
-rw-rw----  1 openxs users 1024 2006-09-18 11:14 ttt.MYI
[2 Mar 2007 8:06] Ingo Strüwing
Regarding the patch which was also suggested in internals@lists.mysql.com:

Wouldn't it be sufficient to always use MY_REPLACE_EXT? Doesn't it append the extension anyway if none exists?

And shouldn't it be fixed in 5.0 too?
[2 Mar 2007 13:27] David Shrewsbury
Bug does not exist in 5.0.27.
[6 Mar 2007 10:16] Lenz Grimmer
See http://lists.mysql.com/internals/34349 for further discussion related to this patch
[6 Mar 2007 18:59] Ingo Strüwing
The patch from David Shrewsbury is ok. I will bring it on its way.
[7 Mar 2007 15:31] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/21367

ChangeSet@1.2468, 2007-03-07 16:30:13+01:00, istruewing@chilla.local +1 -0
  Bug#26782 - Patch: myisamchk -rq creates .MYI.MYI file
              on packed MyISAM tables
  
  When fixing the indexes with "myisamchk -rq" after compressing
  the table with "myisampack", an optionally supplied extension
  ".MYI" of the index file was not detected. The extension was
  appended unconditionally. The result was ".MYI.MYI".
  
  Now an extension is no longer appended if present already.
  Thanks to David Shrewsbury for providing this patch.
  
  Another problem was a misplaced parenthesis. We did never unpack
  the file name ("~/..") and always returned a real path.
  
  No test case. This is manually tested with the utilities
  "myisampack" and "myisamchk".
[7 Mar 2007 16:21] Sergey Vojtovich
Approved.
[16 Mar 2007 12:01] Alexander Barkov
The patch looks ok.
[23 Mar 2007 9:26] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/22736

ChangeSet@1.2496, 2007-03-23 10:26:14+01:00, istruewing@chilla.local +1 -0
  Bug#26782 - Patch: myisamchk -rq creates .MYI.MYI file on packed MyISAM tables
  After merge fix
  In conjunction with the newest 5.1 we always need to
  create a real path name to be able to detect already
  open tables.
[23 Mar 2007 13:28] Ingo Strüwing
Queued to 5.1-engines.
[30 Mar 2007 17:28] Bugs System
Pushed into 5.1.18-beta
[13 Apr 2007 18:12] Paul DuBois
Noted in 5.1.18 changelog.

If the name of a table given to myisamchk -rq was a packed table and
the name included the .MYI extension, myisamchk incorrectly created a
file with a .MYI.MYI extension.