Bug #1503 Cannot repair MyISAM table
Submitted: 8 Oct 2003 8:40 Modified: 14 Nov 2003 13:08
Reporter: Martin Mokrejs Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S3 (Non-critical)
Version:bk-1.1603 OS:Linux (Linux 2.4.19)
Assigned to: Sergei Golubchik CPU Architecture:Any

[8 Oct 2003 8:40] Martin Mokrejs
Description:
I'm checking if one of my bugs reported were fixed. I cannot find any report with word Drosophila, so I'm firing a new one. :(

The original report must have been pointing to
http://jerboas.gsf.de/Drosophila_melanogaster.tar.gz
which contains crashed table, which was not possible to repair.

The original tables have been lying on the disc(in databases directory). I tried now to fix the table with latest mysql version, and what I got you can see below.
I store the tables again in http://jerboas.gsf.de/Dmelanogaster.tar.bz2.

Therefore, download both files, check with diff what has been screwed up by mysql bk-1.1603 and if the original table (I believe the one with .MYD-), the current .MYD can be fixed. I beleive you might be able to find fewm more changes which were done by mysql bk-1.1603 and did not lead to anything good.

How to repeat:
root@kulan:/data/mysql# ls -la /data/mysql/Drosophila_melanogaster/contig_data.*
-rw-rw----    1 mysql    mysql    32017741 Sep 15 19:01 /data/mysql/Drosophila_melanogaster/contig_data.MYD
-rw-------    1 root     root     32199438 Sep 15 19:01 /data/mysql/Drosophila_melanogaster/contig_data.MYD-
-rw-rw----    1 mysql    mysql        1024 Oct  8 16:40 /data/mysql/Drosophila_melanogaster/contig_data.MYI
-rw-rw----    1 mysql    mysql    115223436 Sep 15 19:01 /data/mysql/Drosophila_melanogaster/contig_data.OLD
-rw-rw----    1 mysql    mysql        8744 Sep 15 19:01 /data/mysql/Drosophila_melanogaster/contig_data.frm
root@kulan:/data/mysql# /usr/local/mysql/bin/myisamchk /data/mysql/Drosophila_melanogaster/contig_data.MYI
Checking MyISAM file: /data/mysql/Drosophila_melanogaster/contig_data.MYI
Data records:      12   Deleted blocks:       0
myisamchk: warning: Table is marked as crashed and last repair failed
- check file-size
- check key delete-chain
- check record delete-chain
- check index reference
- check data record references index: 1
myisamchk: error: Can't read indexpage from filepos: -1
- check record links
myisamchk: error: Found wrong record at 20441646
MyISAM-table '/data/mysql/Drosophila_melanogaster/contig_data.MYI' is corrupted
Fix it using switch "-r" or "-o"
root@kulan:/data/mysql# /usr/local/mysql/bin/myisamchk -o /data/mysql/Drosophila_melanogaster/contig_data.MYI
- recovering (with keycache) MyISAM-table '/data/mysql/Drosophila_melanogaster/contig_data.MYI'
Data records: 12
Found wrong record at 20441646
Data records: 18
root@kulan:/data/mysql# /usr/local/mysql/bin/myisamchk /data/mysql/Drosophila_melanogaster/contig_data.MYI
Checking MyISAM file: /data/mysql/Drosophila_melanogaster/contig_data.MYI
Data records:      18   Deleted blocks:       0
- check file-size
- check key delete-chain
- check record delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check data record references index: 4
- check data record references index: 5
- check record links
myisamchk: warning: Record checksum is not the same as checksum stored in the index file

MyISAM-table '/data/mysql/Drosophila_melanogaster/contig_data.MYI' is usable but should be fixed
root@kulan:/data/mysql# /usr/local/mysql/bin/myisamchk -r /data/mysql/Drosophila_melanogaster/contig_data.MYI
- recovering (with sort) MyISAM-table '/data/mysql/Drosophila_melanogaster/contig_data.MYI'
Data records: 18
- Fixing index 1
- Fixing index 2
- Fixing index 3
- Fixing index 4
- Fixing index 5
root@kulan:/data/mysql# /usr/local/mysql/bin/myisamchk /data/mysql/Drosophila_melanogaster/contig_data.MYI
Checking MyISAM file: /data/mysql/Drosophila_melanogaster/contig_data.MYI
Data records:      18   Deleted blocks:       0
- check file-size
- check key delete-chain
- check record delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check data record references index: 4
- check data record references index: 5
- check record links
myisamchk: warning: Record checksum is not the same as checksum stored in the index file

MyISAM-table '/data/mysql/Drosophila_melanogaster/contig_data.MYI' is usable but should be fixed
root@kulan:/data/mysql# /usr/local/mysql/bin/myisamchk -r /data/mysql/Drosophila_melanogaster/contig_data.MYI
- recovering (with sort) MyISAM-table '/data/mysql/Drosophila_melanogaster/contig_data.MYI'
Data records: 18
- Fixing index 1
- Fixing index 2
- Fixing index 3
- Fixing index 4
- Fixing index 5
root@kulan:/data/mysql# /usr/local/mysql/bin/myisamchk /data/mysql/Drosophila_melanogaster/contig_data.MYI
Checking MyISAM file: /data/mysql/Drosophila_melanogaster/contig_data.MYI
Data records:      18   Deleted blocks:       0
- check file-size
- check key delete-chain
- check record delete-chain

- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check data record references index: 4
- check data record references index: 5
- check record links
myisamchk: warning: Record checksum is not the same as checksum stored in the index file

MyISAM-table '/data/mysql/Drosophila_melanogaster/contig_data.MYI' is usable but should be fixed
root@kulan:/data/mysql#
root@kulan:/data/mysql# ls -la /data/mysql/Drosophila_melanogaster/contig_data.*
-rw-rw----    1 mysql    mysql    25280087 Oct  8 17:22 /data/mysql/Drosophila_melanogaster/contig_data.MYD
-rw-------    1 root     root     32199438 Sep 15 19:01 /data/mysql/Drosophila_melanogaster/contig_data.MYD-
-rw-rw----    1 mysql    mysql        7168 Oct  8 17:22 /data/mysql/Drosophila_melanogaster/contig_data.MYI
-rw-rw----    1 mysql    mysql    115223436 Sep 15 19:01 /data/mysql/Drosophila_melanogaster/contig_data.OLD
-rw-rw----    1 mysql    mysql        8744 Sep 15 19:01 /data/mysql/Drosophila_melanogaster/contig_data.frm
root@kulan:/data/mysql#
[8 Oct 2003 9:26] Martin Mokrejs
One more old bug not fixed. Freshly fixes table is recognized to have wrong checksum.

download http://jerboas.gsf.de/Caenorhabditis_elegans_WS75.tar.gz
and repeat commands as below. You should get same results in every step.

root@kulan:/data/mysql/test# /usr/local/mysql/bin/myisamchk -dvv contig_data.MYI

MyISAM file:         contig_data.MYI
Record format:       Compressed
Character set:       latin1 (8)
File-version:        1
Creation time:       2003-03-18 12:07:56
Recover time:        2003-03-18 12:10:22
Status:              crashed
Checksum:                        0
Data records:                    0  Deleted blocks:                 0
Datafile parts:                  0  Deleted data:                   0
Datafile pointer (bytes):        4  Keyfile pointer (bytes):        4
Datafile length:                53  Keyfile length:              1024
Max datafile length:    4294967294  Max keyfile length: 4398046510079
Recordlength:              5691679

table description:
Key Start Len Index   Type                     Rec/key         Root  Blocksize
1   2     4   unique  long                           0                    1024
2   6     4   multip. long                           0                    1024
3   10    100 multip. char packed stripped           0                    1024
4   110   100 multip. char packed stripped           0                    1024
5   210   255 multip. char packed stripped NULL          0                    2048

Field Start Length Nullpos Nullbit Type                         Huff tree  Bits
1     1     1                                                           1     9
2     2     4                      no zeros, zerofill(3)                1     9
3     6     4                      no zeros, zerofill(3)                1     9
4     10    100                    no endspace                          1     9
5     110   100                    no endspace                          1     9
6     210   255    1       1       no endspace                          1     9
7     465   12     1       2       blob                                 1     9
8     477   100                    no endspace, no empty                1     9
root@kulan:/data/mysql/test# cp contig_data.MYD contig_data.MYD-
root@kulan:/data/mysql/test# ls -la
total 26752
drwx------    2 mysql    mysql        4096 Oct  8 17:44 .
drwx------  463 mysql    mysql       16384 Oct  7 19:22 ..
-rw-rw----    1 mysql    mysql           0 Oct  8 17:44 contig_data.MYD
-rw-r-----    1 root     root     27303889 Oct  8 17:44 contig_data.MYD-
-rw-rw----    1 mysql    mysql        1024 Oct  8 17:44 contig_data.MYI
-rw-rw----    1 mysql    mysql        8744 Oct  8 17:43 contig_data.frm
-rw-rw----    1 mysql    mysql          20 Oct  7 19:04 testac.MYD
-rw-rw----    1 mysql    mysql        1024 Oct  7 19:11 testac.MYI
-rw-rw----    1 mysql    mysql        8604 Oct  7 19:04 testac.frm
root@kulan:/data/mysql/test# /usr/local/mysql/bin/myisampack contig_data.MYI
Compressing contig_data.MYD: (0 records)
- Calculating statistics
- Compressing file
Empty file saved in compressed format
Remember to run myisamchk -rq on compressed tables
root@kulan:/data/mysql/test# cp  contig_data.MYD- contig_data.MYD
root@kulan:/data/mysql/test# /usr/local/mysql/bin/myisamchk -rq contig_data.MYI
- check key delete-chain
- check record delete-chain
- recovering (with keycache) MyISAM-table 'contig_data.MYI'
Data records: 0
Found wrong record at 12017949
MyISAM-table 'contig_data.MYI' is not fixed because of errors
Try fixing it by using the --safe-recover (-o) or the --force (-f) option
root@kulan:/data/mysql/test# /usr/local/mysql/bin/myisamchk -r contig_data.MYI
- recovering (with sort) MyISAM-table 'contig_data.MYI'
Data records: 3
- Fixing index 1
Found wrong record at 12017949
- Fixing index 2
- Fixing index 3
- Fixing index 4
- Fixing index 5
root@kulan:/data/mysql/test# 
root@kulan:/data/mysql/test# /usr/local/mysql/bin/myisamchk -dvv contig_data.MYI

MyISAM file:         contig_data.MYI
Record format:       Compressed
Character set:       latin1 (8)
File-version:        1
Creation time:       2003-10-08 17:44:37
Recover time:        2003-10-08 18:22:47
Status:              checked,optimized keys
Checksum:                        0
Data records:                    3  Deleted blocks:                 0
Datafile parts:                  3  Deleted data:                   0
Datafile pointer (bytes):        4  Keyfile pointer (bytes):        4
Datafile length:          12017949  Keyfile length:              7168
Max datafile length:    4294967294  Max keyfile length: 4398046510079
Recordlength:              5691679

table description:
Key Start Len Index   Type                     Rec/key         Root  Blocksize
1   2     4   unique  long                           0         1024       1024
2   6     4   multip. long                           0         2048       1024
3   10    100 multip. char packed stripped           0         3072       1024
4   110   100 multip. char packed stripped           0         4096       1024
5   210   255 multip. char packed stripped NULL          0         5120       2048

Field Start Length Nullpos Nullbit Type                         Huff tree  Bits
1     1     1                                                           1     9
2     2     4                      no zeros, zerofill(3)                1     9
3     6     4                      no zeros, zerofill(3)                1     9
4     10    100                    no endspace                          1     9
5     110   100                    no endspace                          1     9
6     210   255    1       1       no endspace                          1     9
7     465   12     1       2       blob                                 1     9
8     477   100                    no endspace, no empty                1     9
root@kulan:/data/mysql/test# /usr/local/mysql/bin/myisamchk contig_data.MYI
Checking MyISAM file: contig_data.MYI
Data records:       3   Deleted blocks:       0
- check file-size
- check key delete-chain
- check record delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check data record references index: 4
- check data record references index: 5
- check record links
myisamchk: warning: Record checksum is not the same as checksum stored in the index file

MyISAM-table 'contig_data.MYI' is usable but should be fixed
root@kulan:/data/mysql/test#
[12 Oct 2003 10:43] Sergei Golubchik
One question - changeset 1.1603 in what tree ? 4.0 or 4.1 ?
[17 Oct 2003 8:17] Martin Mokrejs
4.0 tree.
[14 Nov 2003 13:08] Sergei Golubchik
It's not really a bug. myisamchk does not update table's checksum automatically. 
You need to use --correct-checksum switch for this (in repair mode, that is with -r or -o).

But I fixed myisamchk (in 4.0.17) to always imply this flag for compressed tables.