Bug #6447 set GLOBAL key_cache_block_size=2048; crashes fulltext indices
Submitted: 5 Nov 2004 2:58 Modified: 17 Nov 2004 1:34
Reporter: Mark Maunder Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S2 (Serious)
Version:4.1.7-standard OS:Linux (Linux 2.6)
Assigned to: Igor Babaev CPU Architecture:Any
Tags: key_cache_block_size

[5 Nov 2004 2:58] Mark Maunder
Description:
I've duplcated this on Mandrake 10 with kernel 2.6.3 and Red Hat 2.4.21-20.ELsmp. Set your index blocksize to 2048, create a table with blocks of text in a 'text' column. Add a fulltext index to it, and viola!

How to repeat:
create table fttest ( id int(11) NOT NULL, mytext text ) ENGINE=MyISAM;

############Run this on the table to populate it:
#!/usr/bin/perl
use strict;
use DBI;
$|=1;
my $dbh = DBI->connect("DBI:mysql:database=mydbname;host=localhost;port=3306", 'root' ,'mypasswd', { AutoCommit => 1 });

open(FH, "</usr/share/dict/words") || die "Could not open words\n";
my @words;
foreach my $word (<FH>)
{
        chomp $word;
        push(@words, $word) if($word =~ m/[a-z]+/i);
        print 'w';
}
close(FH);
print "\nDone loading words\n";
my $sth = $dbh->prepare("insert into fttest (id, mytext) values (?, ?)");
my $count = 1;
for(1..1000)
{
        my $str;
        for(1..100)
        {
                $str .= ' ' . $words[int(rand($#words))];
        }
        $sth->execute($count, $str);
        $count++;
}
$sth->finish();
$dbh->disconnect();
print "\nDone.\n";
########END of script

alter table fttest add FULLTEXT KEY ft(mytext);
check table fttest;
+----------------+-------+----------+--------------------------------------------+
| Table          | Op    | Msg_type | Msg_text                                   |
+----------------+-------+----------+--------------------------------------------+
| workzoo.fttest | check | warning  | Table is marked as crashed                 |
| workzoo.fttest | check | error    | Can't read indexpage from filepos: 1141760 |
| workzoo.fttest | check | error    | Corrupt                                    |
+----------------+-------+----------+--------------------------------------------+

Suggested fix:
Temporary workaround is to not set your index bocksize to anything other than the default.
[5 Nov 2004 3:03] Mark Maunder
Sorry, forgot to mention, the first step when recreating this is:
set GLOBAL key_cache_block_size=2048;
[5 Nov 2004 8:43] MySQL Verification Team
Verified with 4.1.8-debug-log
[17 Nov 2004 1:34] Igor Babaev
The bug could be reproduce with much simpler test (thanks to Sergei G). This test now is added to mysql-test/t/key_cache.test.

ChangeSet
  1.2108 04/11/16 13:58:49 igor@rurik.mysql.com +3 -0
  key_cache.result, key_cache.test:
    Added a test case for bug #6447.
  mf_keycache.c:
    Fixed bug #6447. Erronious code in the key_cache_read function
    caused problems when reading key blocks with offset>0 into
    key cache. The code of key_cache_insert and key_cache_write
    was modified similarly.