Bug #12783 Incorrect key file for table (MyISAM) after SELECT
Submitted: 24 Aug 2005 13:50 Modified: 10 Sep 2005 21:07
Reporter: Felix Geerinckx (Basic Quality Contributor) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version: 5.0.11-beta/BK Source OS:Linux (Linux)
Assigned to: CPU Architecture:Any

[24 Aug 2005 13:50] Felix Geerinckx
Description:
SELECT
f1.id,
f2.id
FROM foo f1
JOIN foo AS f2 ON f2.dt < f1.dt AND f2.d LIKE 'B%'
WHERE
f1.d LIKE 'B%';

Results in: 
ERROR 126 (HY000): Incorrect key file for table './test/foo.MYI'; try to repair it 

REPAIR TABLE foo;

Result:
+----------+--------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+----------+--------+----------+----------+
| test.foo | repair | status | OK |
+----------+--------+----------+----------+
1 row in set (0.49 sec)

After running query again, the same error message appears.

When run on MySQL 5.0.3-beta-nt, the error is
ERROR 1030 (HY000): Got error 124 from storage engine 

The problem does not occur with InnoDB

How to repeat:
USE test;
DROP TABLE IF EXISTS foo;
CREATE TABLE foo (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
d CHAR(10) NOT NULL,
dt DATETIME NOT NULL,
KEY (d),
KEY (dt)
) ENGINE = MyISAM;

## Fill with 100 random records:

INSERT INTO foo (d,dt) VALUES ('XXHLSVJQWE', '2005-01-31 08:32:09');
## ...
INSERT INTO foo (d,dt) VALUES ('TLMXIQUAHY', '2005-04-08 09:11:48');
[24 Aug 2005 17:06] MySQL Verification Team
Yes please provide the dump file at:

ftp://ftp.mysql.com/pub/mysql/upload/

I was unable to reproduce on my own.

Thanks in advance.
[24 Aug 2005 17:13] Felix Geerinckx
file uploaded as bug12783.sql
[24 Aug 2005 18:47] MySQL Verification Team
Thank you for the bug report. With today BK server I got an assertion:

miguel@hegel:~/dbs/5.0> bin/mysql -uroot test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.13-beta-debug

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE TABLE foo (
    -> id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    -> d CHAR(10) NOT NULL,
    -> dt DATETIME NOT NULL,
    -> KEY (d),
    -> KEY (dt)
    -> ) ENGINE = MyISAM;
Query OK, 0 rows affected (0.04 sec)

mysql> source /home/miguel/bug12783.sql
Query OK, 1 row affected (0.00 sec)

<cut>

Query OK, 1 row affected (0.00 sec)

mysql> SELECT
    -> f1.id,
    -> f2.id
    -> FROM foo f1
    -> JOIN foo AS f2 ON f2.dt < f1.dt AND f2.d LIKE 'B%'
    -> WHERE
    -> f1.d LIKE 'B%';
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> 

050824 15:45:21 [Note] /home/miguel/dbs/5.0/libexec/mysqld: ready for connections.
Version: '5.0.13-beta-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
[New Thread 1129593776 (LWP 15735)]
mysqld: ha_myisam.cc:1202: virtual int ha_myisam::index_first(byte*): Assertion `inited==INDEX' failed.

Program received signal SIGABRT, Aborted.
[Switching to Thread 1129593776 (LWP 15735)]
0xffffe410 in ?? ()
(gdb)
[10 Sep 2005 21:07] MySQL Verification Team
Hi Ingo,

You are right the backtrace I got, shows the same source like bug:

http://bugs.mysql.com/bug.php?id=12291

No symbol table info available.
#1  0x437fd5bc in ?? ()
No symbol table info available.
#2  0x00000006 in ?? ()
No symbol table info available.
#3  0x40214b75 in abort () from /lib/tls/libc.so.6
No symbol table info available.
#4  0x4020c903 in __assert_fail () from /lib/tls/libc.so.6
No symbol table info available.
#5  0x082a6b87 in ha_myisam::index_first (this=0x8e74838, buf=0x8e74928 "ÿd") at ha_myisam.cc:1202
        error = 140650524
#6  0x082a176d in handler::read_range_first (this=0x8e74838, start_key=0x0, end_key=0x8e53144, eq_range_arg=false, sorted=false)
    at handler.cc:2304
        result = 136011296
        _db_func_ = 0x437fd7d8 "D1å\b$Hb\b"
        _db_file_ = 0x8e29f04 "\210+Z\b"
        _db_level_ = 149380496
        _db_framep_ = (char **) 0x8b7
#7  0x082a142d in handler::read_multi_range_first (this=0x8e74838, found_range_p=0x437fd868, ranges=0x8e53138, range_count=1, sorted=false, 
    buffer=0x0) at handler.cc:2178
        result = 137
        _db_func_ = 0x0
        _db_file_ = 0x8e51ee8 "Bÿÿÿÿÿÿÿÿÿh¥¥¥¥¥"
        _db_level_ = 149381920
        _db_framep_ = (char **) 0x0
#8  0x082901ed in QUICK_RANGE_SELECT::get_next (this=0x8e53020) at opt_range.cc:6173
        count = 1
        mrange_slot = (KEY_MULTI_RANGE *) 0x8e53158
        mrange_end = (KEY_MULTI_RANGE *) 0x8e53158
        result = 0
        mrange = (KEY_MULTI_RANGE *) 0x4
        start_key = (key_range *) 0x8e53138
        end_key = (key_range *) 0x8e53144
        _db_func_ = 0x8e53020 "(\033b\b"
        _db_file_ = 0x1 <Address 0x1 out of bounds>
        _db_level_ = 256
        _db_framep_ = (char **) 0x3
#9  0x0829931d in rr_quick (info=0x8e75dcc) at records.cc:165
---Type <return> to continue, or q <return> to quit---