Bug #15205 Select from CSV table without the datafile causes crash
Submitted: 23 Nov 2005 21:36 Modified: 30 Aug 2006 20:16
Reporter: Petr Chardin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: CSV Severity:S3 (Non-critical)
Version:4.1.16 and up OS:Linux (Suse 9.3)
Assigned to: Petr Chardin CPU Architecture:Any

[23 Nov 2005 21:36] Petr Chardin
Description:
Server crashes on a select from a CSV table which has no datafile

How to repeat:
Create a csv table:

CREATE TABLE csv_bug (val int(11) default NULL) ENGINE=CSV;

then remove *.CSV file from the datadir (csv_bug.CSV). Restart
the server. Then attempt to do a select:

SELECT * FROM csv_bug;

The server will crash. My backtrace below

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1114692528 (LWP 19655)]
0x0846bb2a in my_utf8_uni (cs=0x8607be0, pwc=0x427098f0, 
    s=0x32 <Address 0x32 out of bounds>, e=0x747365a6 "") at ctype-utf8.c:1770
1770      c= s[0];
(gdb) bt
#0  0x0846bb2a in my_utf8_uni (cs=0x8607be0, pwc=0x427098f0,
    s=0x32 <Address 0x32 out of bounds>, e=0x747365a6 "") at ctype-utf8.c:1770
#1  0x0846be2f in my_hash_sort_utf8 (cs=0x8607be0,
    s=0x32 <Address 0x32 out of bounds>, slen=1953719668, n1=0x42709924,
    n2=0x42709920) at ctype-utf8.c:1934
#2  0x08443a6d in calc_hash (hash=0x8639c00,
    key=0x32 <Address 0x32 out of bounds>, length=1953719668) at hash.c:44
#3  0x08444cad in rec_hashnr (hash=0x8639c00, record=0x8cd1ac8 "2")
    at hash.c:185
#4  0x08444085 in my_hash_insert (info=0x8639c00, record=0x8cd5290 "��b")
    at hash.c:321
#5  0x08292d60 in get_share (table_name=0x4270ac50 "./mytest/test_update",
    table=0x8cd1af8) at ha_tina.cc:164
#6  0x08293821 in ha_tina::open (this=0x8cd2048,
    name=0x4270ac50 "./mytest/test_update", mode=2, test_if_locked=2)
    at ha_tina.cc:404
#7  0x08220c02 in handler::ha_open (this=0x8cd2048,
    name=0x4270ac50 "./mytest/test_update", mode=2, test_if_locked=2)
    at handler.cc:937
#8  0x081c582c in openfrm (name=0x4270bd50 "./mytest/test_update",
    alias=0x8cd1ad0 "test_update", db_stat=39, prgflag=44, ha_open_flags=0,
    outparam=0x8cd1af8) at table.cc:771
#9  0x081bf877 in open_unireg_entry (thd=0x8c78e60, entry=0x8cd1af8,
    db=0x8c8b070 "mytest", name=0x8cd1ad0 "test_update",
    alias=0x8cd1ad0 "test_update") at sql_base.cc:1372
#10 0x081be64b in open_table (thd=0x8c78e60, db=0x8c8b070 "mytest",
    table_name=0x8cd1ad0 "test_update", alias=0x8cd1ad0 "test_update",
    refresh=0x4270d00f) at sql_base.cc:916
#11 0x081c00e6 in open_ltable (thd=0x8c78e60, table_list=0x4270d210,
    lock_type=TL_UNLOCK) at sql_base.cc:1641
#12 0x08259cf1 in mysqld_list_fields (thd=0x8c78e60, table_list=0x4270d210,
    wild=0x8c7a450 "") at sql_show.cc:1071
#13 0x0819ed3b in dispatch_command (command=COM_FIELD_LIST, thd=0x8c78e60,
    packet=0x8caf1d5 "", packet_length=13) at sql_parse.cc:1592
#14 0x0819e2db in do_command (thd=0x8c78e60) at sql_parse.cc:1312
#15 0x0819d78c in handle_one_connection (arg=0x8c78e60) at sql_parse.cc:1044
#16 0x4017a927 in start_thread (arg=0x4270dbb0) at pthread_create.c:261
#17 0x402aae8e in clone () from /lib/tls/libc.so.6

Suggested fix:
In the same sutuation MyISAM gives an error. E.g:
ERROR 1105 (HY000): File './mytest/table.MYD' not found (Errcode: 2)
The same should be done for CSV
[23 Nov 2005 21:46] MySQL Verification Team
I was unable to repeat with 5.0.17 debug:

miguel@hegel:~/dbs/5.0> bin/mysql -uroot db3
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.17-debug

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

mysql> SELECT * FROM csv_bug;
ERROR 1030 (HY000): Got error 1 from storage engine
mysql> select version();
+--------------+
| version()    |
+--------------+
| 5.0.17-debug |
+--------------+
1 row in set (0.00 sec)

mysql> 

I will test 4.1.XX
[23 Nov 2005 22:39] MySQL Verification Team
I was able to repeat with 4.1.16:

miguel@hegel:~/dbs/4.1> bin/mysqladmin shutdown -uroot
miguel@hegel:~/dbs/4.1> bin/mysql -uroot db3
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.16-log

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

mysql> SELECT * FROM csv_bug;
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> 

miguel@hegel:~/dbs/4.1> libexec/mysqld
051123 20:37:41  InnoDB: Started; log sequence number 0 43786
libexec/mysqld: ready for connections.
Version: '4.1.16-log'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
051123 20:37:57 [ERROR] libexec/mysqld: Can't open file: 'csv_bug.CSV' (errno: 1)
mysqld got signal 11;
[26 Apr 2006 7:01] Oli Sennhauser
It seems to be NOT fixed. I was able to reproduce in 5.0.20a!
Seems to be fixed in 5.1.9

create table csv_test (id int, data varchar(255)) engine=csv;
insert into csv_test values (1, 'Bla'), (2, 'Blabla');
select * from csv_test;
flush tables;
exit

rm test.CSV
stop server
start server

mysql -u root test
mysql> select * from test;
No connection. Trying to reconnect...
Connection id:    1
Current database: test

ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/u00/app/mysql/tmp/mysql-5.0.20.sock' (111)
ERROR:
Can't connect to the server
[11 Jul 2006 12:14] 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/9038
[17 Aug 2006 14:13] Petr Chardin
The 5.0 version of the fix is pushed into 5.0 runtime.
The merge will soon follow
[18 Aug 2006 15:03] Petr Chardin
merged the patch into 5.0.25. Can't merge to 5.1, as 5.1 is currently broken.
Will do as soon, it is fixed.
[24 Aug 2006 19:22] Iggy Galarza
Available in 5.1.12
[30 Aug 2006 20:16] Paul DuBois
Noted in 5.0.25, 5.1.12 changelogs.

The server crashed if it tried to access a CSV table for which the
data file had been removed.