Bug #23189 Falcon: crash if create index for long varchar
Submitted: 11 Oct 2006 21:30 Modified: 11 Nov 2006 20:23
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Falcon storage engine Severity:S3 (Non-critical)
Version:5.1.12-beta-debug OS:Linux (SUSE 10.0 / 64-bit)
Assigned to: Kevin Lewis CPU Architecture:Any

[11 Oct 2006 21:30] Peter Gulutzan
Description:
I create a table with a long VARCHAR column.
I insert one row.
I try to create an index on the column.
Crash.

How to repeat:
mysql> create table th (s1 varchar(2400)) engine=falcon;
Query OK, 0 rows affected (0.49 sec)

mysql> insert into th values (repeat('r',2400));
Query OK, 1 row affected (0.01 sec)

mysql> create index i on th (s1);
ERROR 2013 (HY000): Lost connection to MySQL server during query

bk changes says:
ChangeSet@1.2384, 2006-10-10 17:57:15-04:00 ...
[12 Oct 2006 14:48] Hakan Küçükyılmaz
Verified on Linux 32-bit, change set 1.2388, 2006-10-12. Added test case falcon_bug_23189.test.

TEST                           RESULT         TIME (ms)
-------------------------------------------------------

falcon_bug_23189               [ fail ]

Errors are (from /media/usbdisk/mysql/var/log/mysqltest-time) :
mysqltest: At line 13: query 'CREATE INDEX i ON t1 (a)' failed: 2013: Lost connection to MySQL server during query
(the last lines may be the most important ones)

Regards, Hakan
[12 Oct 2006 17:20] Hakan Küçükyılmaz
Works now on Linux 32-bit, change set 1.2390, 2006-10-12.

Regards, Hakan
[12 Oct 2006 18:45] Peter Gulutzan
Now it fails with a slightly different test:

mysql> create table th (s1 varchar(20000)) engine=falcon;
Query OK, 0 rows affected (0.01 sec)

mysql> insert into th values (repeat('r',20000));
Query OK, 1 row affected (0.01 sec)

mysql> create index i on th (s1);
ERROR 1022 (23000): Can't write; duplicate key in table '#sql-6d0c_1'

With MyISAM, there would be a warning not an error. There's no duplicate key.
[12 Oct 2006 19:15] Jim Starkey
The index violates the maximim index length as defined by handler::max_supported_key_length.  The server should have bounced the create index command as illegal.

Falcon is generous about index creation -- it doesn't reject indexes that can potentially overflow the internal, but it draws a line at attempting to insert a record with a value that won't fit in the index.

I concede that the error diagnostic is misleading -- there was a problem during index update, but it wasn't a duplicate value.  The exception, however, gets thrown and a low level as a string overflow, and making it more specific will take some work, so I'd like to address this post-alpha.  Accordingly, I'm dropping the priority to "low".
[13 Oct 2006 22:13] Hakan Küçükyılmaz
Added Peter Gulutzan's additional test to falcon_bug_23189.test.

Regards, Hakan
[19 Oct 2006 20:07] Calvin Sun
Suggest to close this bug since the crash has been fixed, and the engine now returns "data truncation" error when creating index. Should the engine give a warning instead?
[19 Oct 2006 21:46] Peter Gulutzan
Here is another test case, with ChangeSet@1.2332.

mysql> create table th (s1 varchar(3400)) engine=myisam;
Query OK, 0 rows affected (0.06 sec)

mysql> create index ith on th (s1(10));
Query OK, 0 rows affected (0.10 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> insert into th values (repeat('a',3400));
Query OK, 1 row affected (0.00 sec)

mysql> alter table th engine=falcon;
ERROR 2013 (HY000): Lost connection to MySQL server during query
[21 Oct 2006 4:26] Calvin Sun
Please review and close this bug. But#23517 is created for the new test case.
[23 Oct 2006 21:11] Hakan Küçükyılmaz
Now we have a good error message

[23:14] root@test>create index i on th (s1);
ERROR 1296 (HY000): Got error 139 'string truncation of 20000 bytes into 2500 bytes from "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr' from Falcon
[10 Nov 2006 21:35] Hakan Küçükyılmaz
Crashes on Linux 32-bit, change set 1.2349, 2006-11-10.

CREATE TABLE t2 (a varchar(20000)) Engine Falcon;
INSERT INTO t2 VALUES (repeat('r',20000));
CREATE INDEX i ON t2 (a);
--> crash

Backtrace is:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1096141744 (LWP 26130)]
0x083fd4d9 in falcon_strnxfrmlen (cs=0x0, srclen=3000) at ha_falcon.cpp:111
111             return charset->coll->strnxfrmlen(charset, srclen);
(gdb) bt  
#0  0x083fd4d9 in falcon_strnxfrmlen (cs=0x0, srclen=3000) at ha_falcon.cpp:111
#1  0x0845f729 in MySQLCollation::makeKey (this=0x72727272, value=0x72727272, key=0x72727272,
    partialKey=1920103026) at MySQLCollation.cpp:51
#2  0x72727272 in ?? ()

Regards, Hakan
[11 Nov 2006 20:23] Hakan Küçükyılmaz
Successfully tested fix on Linux 32-bit, change set 1.2357, 2006-11-11.

=======================================================
Starting Tests in the 'main' suite

TEST                           RESULT         TIME (ms)
-------------------------------------------------------

falcon_bug_185                 [ pass ]            926
falcon_bug_23189               [ pass ]            244
falcon_bug_23517               [ pass ]            136
-------------------------------------------------------
Stopping All Servers
All 3 tests were successful.
The servers were restarted 1 times
Spent 1.306 seconds actually executing testcases

Regards, Hakan