Bug #24519 Alter Table crashes
Submitted: 22 Nov 2006 20:03 Modified: 22 Mar 2007 10:40
Reporter: Olaf van der Spek (Basic Quality Contributor) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S2 (Serious)
Version:5.1.12, 5.0BK OS:Linux (Linux, Windows)
Assigned to: Assigned Account CPU Architecture:Any

[22 Nov 2006 20:03] Olaf van der Spek
Description:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.12-beta-community-nt MySQL Community Server (GPL)

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

mysql> use mysql
Database changed
mysql> ALTER TABLE user MODIFY ssl_type enum('','ANY','X509', 'SPECIFIED') NOT N
ULL;
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql>

How to repeat:
use mysql
ALTER TABLE user MODIFY ssl_type enum('','ANY','X509', 'SPECIFIED') NOT NULL;

CREATE TABLE `user` (
  `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
  `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '',
  `Password` char(41) COLLATE utf8_bin NOT NULL DEFAULT '',
  `Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Insert_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Update_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Delete_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Create_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Drop_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Reload_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Shutdown_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Process_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `File_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Grant_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `References_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Index_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Alter_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Show_db_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Super_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Create_tmp_table_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Lock_tables_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Execute_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Repl_slave_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Repl_client_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Create_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Show_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Create_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Alter_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `Create_user_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
  `ssl_type` enum('','ANY','X509','SPECIFIED') CHARACTER SET utf8 NOT NULL DEFAULT '',
  `ssl_cipher` blob NOT NULL,
  `x509_issuer` blob NOT NULL,
  `x509_subject` blob NOT NULL,
  `max_questions` int(11) unsigned NOT NULL DEFAULT '0',
  `max_updates` int(11) unsigned NOT NULL DEFAULT '0',
  `max_connections` int(11) unsigned NOT NULL DEFAULT '0',
  `max_user_connections` int(11) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`Host`,`User`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Users and global privileges';

Suggested fix:
de
[22 Nov 2006 20:35] Sveta Smirnova
Thank you for the report.

I can not repeat it using last BK sources.

Do you use SSL connection?
[22 Nov 2006 20:53] Olaf van der Spek
No. And a truncate before the alter doesn't cause the error.
[22 Nov 2006 20:55] Sveta Smirnova
Please, provide sample data causes error.
[22 Nov 2006 21:04] Olaf van der Spek
Data

Attachment: test.zip (application/zip, text), 2.05 KiB.

[24 Nov 2006 19:50] Sveta Smirnova
Thank you for the data.

Verified as described on Windows using BK sources.

VS Studio dialog:

Unhandled exception at 0x0087a04c in mysqld.exe: 0xC0000005: Access violation reading location 0x00000000.

Call stack:

 	mysqld.exe!memcpy(unsigned char * dst=0x01eef3e7, unsigned char * src=0x00000000, unsigned long count=1)  Line 348	Asm
>	mysqld.exe!_mi_rec_pack(st_myisam_info * info=0x01ef8668, unsigned char * to=0x01eef3e5, const unsigned char * from=0x01ef69ea)  Line 899 + 0x17 bytes	C
 	mysqld.exe!_mi_write_blob_record(st_myisam_info * info=0x01ef8668, const unsigned char * record=0x01ef6870)  Line 262 + 0x14 bytes	C
 	mysqld.exe!mi_write(st_myisam_info * info=0x01ef8668, unsigned char * record=0x01ef6870)  Line 147 + 0x15 bytes	C
 	mysqld.exe!ha_myisam::write_row(unsigned char * buf=0x01ef6870)  Line 353 + 0x13 bytes	C++
 	mysqld.exe!handler::ha_write_row(unsigned char * buf=0x01ef6870)  Line 3650 + 0x16 bytes	C++
 	mysqld.exe!copy_data_between_tables(st_table * from=0x01eef8b0, st_table * to=0x01eed778, List<create_field> & create={...}, int ignore=0, unsigned int order_num=0, st_order * order=0x00000000, unsigned long * copied=0x09f6dd80, unsigned long * deleted=0x09f6dd74)  Line 6654 + 0x12 bytes	C++
 	mysqld.exe!mysql_alter_table(THD * thd=0x01ed0e10, char * new_db=0x01ee6818, char * new_name=0x01ee6620, st_ha_create_information * lex_create_info=0x01ed14a0, st_table_list * table_list=0x01ee6648, List<create_field> & fields={...}, List<Key> & keys={...}, unsigned int order_num=0, st_order * order=0x00000000, int ignore=0, st_alter_info * alter_info=0x01ed1650, int do_send_ok=1)  Line 6115 + 0x2e bytes	C++
 	mysqld.exe!mysql_execute_command(THD * thd=0x01ed0e10)  Line 3166 + 0x64 bytes	C++
 	mysqld.exe!mysql_parse(THD * thd=0x01ed0e10, char * inBuf=0x01ee6598, unsigned int length=76)  Line 6052 + 0x9 bytes	C++
 	mysqld.exe!dispatch_command(enum_server_command command=COM_QUERY, THD * thd=0x01ed0e10, char * packet=0x01ede089, unsigned int packet_length=77)  Line 1835 + 0x1d bytes	C++
 	mysqld.exe!do_command(THD * thd=0x01ed0e10)  Line 1619 + 0x31 bytes	C++
 	mysqld.exe!handle_one_connection(void * arg=0x01ed0e10)  Line 1234 + 0x9 bytes	C++
 	mysqld.exe!pthread_start(void * param=0x01edd738)  Line 63 + 0x9 bytes	C
 	mysqld.exe!_callthreadstart()  Line 293 + 0xf bytes	C
 	mysqld.exe!_threadstart(void * ptd=0x01ee20d0)  Line 277	C
 	kernel32.dll!_BaseThreadStart@8()  + 0x37 bytes
[24 Nov 2006 20:01] Sveta Smirnova
Linux 5.0 error log

Attachment: bug24519.err (application/octet-stream, text), 2.23 KiB.

[24 Nov 2006 20:01] Sveta Smirnova
Also repeatable on today 5.0 BK sources.

See attached error log.
[24 Nov 2006 20:05] Sveta Smirnova
5.1 BK on Linux affected too.
[7 Dec 2006 16:36] Sergey Vojtovich
Even INSERT or UPDATE statement will crash the server. The problem here is actually that table definition described in .frm file differs from table definition described in .MYI. According to .MYI definition we have 31 fields, but according to .frm definition we have 37 fields. Modification time for .MYI and .frm is also diffrent:
2006-11-22 22:02 user.MYI
2006-11-22 21:59 user.MYD
2005-08-27 21:56 user.frm

The only fix is that on my mind is to compare these definitions and probably refuse to open such table. This problem is very close to one described in bug#23750, bug#23751, bug#23752, bug#23753.
[7 Dec 2006 17:15] Calvin Sun
Adding consistency check for every open will impose big impact on performance, while the check for merge tables (as described by Sergey) is needed since the "inconsistency" can easily happen simply using DDL statements. It is not the case for MyISAM. My recommendation is to have a tool that will conduct the consistency check for .MYI and .FRM files.
[7 Dec 2006 17:23] Olaf van der Spek
> Adding consistency check for every open will impose big impact on performance,

But a check to prevent the crash should be much less expensive.

> while the check for merge tables (as described by Sergey) is needed since the
> "inconsistency" can easily happen simply using DDL statements. It is not the
> case for MyISAM. My recommendation is to have a tool that will conduct the
> consistency check for .MYI and .FRM files.

It should probably be added to the normal check tools/commands.
[7 Dec 2006 19:46] Sveta Smirnova
Your table is corrupted and should be repaired using myisamchk utility.

So I mark it as "Not a bug"
[7 Dec 2006 19:54] Olaf van der Spek
C:\IS\MySQL\bin>myisamchk.exe ..\data\mysql\user
Checking MyISAM file: ..\data\mysql\user
Data records:      21   Deleted blocks:       0
myisamchk.exe: warning: 1 client is using or hasn't closed the table properly
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check record links
MyISAM-table '..\data\mysql\user' is usable but should be fixed

C:\IS\MySQL\bin>myisamchk.exe ..\data\mysql\user
Checking MyISAM file: ..\data\mysql\user
Data records:      21   Deleted blocks:       0
myisamchk.exe: warning: 1 client is using or hasn't closed the table properly
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check record links
MyISAM-table '..\data\mysql\user' is usable but should be fixed

C:\IS\MySQL\bin>myisamchk.exe ..\data\mysql\user
Checking MyISAM file: ..\data\mysql\user
Data records:      21   Deleted blocks:       0
myisamchk.exe: warning: 1 client is using or hasn't closed the table properly
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check record links
MyISAM-table '..\data\mysql\user' is usable but should be fixed

C:\IS\MySQL\bin>myisamchk.exe -e ..\data\mysql\user
Checking MyISAM file: ..\data\mysql\user
Data records:      21   Deleted blocks:       0
myisamchk.exe: warning: 1 client is using or hasn't closed the table properly
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check records and index references
MyISAM-table '..\data\mysql\user' is usable but should be fixed

C:\IS\MySQL\bin>myisamchk.exe -r ..\data\mysql\user
- recovering (with sort) MyISAM-table '..\data\mysql\user'
Data records: 21
- Fixing index 1

C:\IS\MySQL\bin>myisamchk.exe -r ..\data\mysql\user
- recovering (with sort) MyISAM-table '..\data\mysql\user'
Data records: 21
- Fixing index 1

C:\IS\MySQL\bin>myisamchk.exe  ..\data\mysql\user
Checking MyISAM file: ..\data\mysql\user
Data records:      21   Deleted blocks:       0
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check record links

C:\IS\MySQL\bin>mysql
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: N
O)

C:\IS\MySQL\bin>mysql -pS68ijFmb
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: Y
ES)

C:\IS\MySQL\bin>mysql -u root -pS68ijFmb
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.12-beta-community-nt MySQL Community Server (GPL)

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

mysql> ALTER TABLE user MODIFY ssl_type enum('','ANY','X509', 'SPECIFIED') NOT N
ULL;
ERROR 1046 (3D000): No database selected
mysql> use mysql;
Database changed
mysql> ALTER TABLE user MODIFY ssl_type enum('','ANY','X509', 'SPECIFIED') NOT N
ULL;
ERROR 2013 (HY000): Lost connection to MySQL server during query
[8 Dec 2006 12:20] Sergey Vojtovich
This table can be repaired only using REPAIR TABLE user USE_FRM. myisamchk will not be helpful here, since it does not open .frm at all.
[22 Mar 2007 10:40] Sergey Vojtovich
Will be fixed by patch for BUG#25908. Closing as duplicate.