Bug #807 Crash using CASE INTERVAL(...) ... GROUP BY
Submitted: 7 Jul 2003 19:10 Modified: 9 Jul 2003 6:22
Reporter: Melt van Schoor Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.0.12 OS:pc-linux (i686)
Assigned to: MySQL Verification Team CPU Architecture:Any

[7 Jul 2003 19:10] Melt van Schoor
Description:
Using the query results in the server crashing:

mysql> SELECT COUNT(*), CASE INTERVAL(BirthYear, 30, 40, 50, 60) WHEN -1 THEN "NULL" WHEN 0 THEN "Under 30" WHEN 1 THEN "From 30 to 39" WHEN 2 THEN "From 40 to 49" WHEN 3 THEN "From 50 to 59" WHEN 4 THEN "60 and over" END AS AgeCategory
    -> FROM test5
    -> GROUP BY AgeCategory;
ERROR 2013: Lost connection to MySQL server during query

I was working with a more complicated query, but it essentially started crashing on the query when I added "AS AgeCategory" and "GROUP BY AgeCategory". Also, I suspect it has something to do with the fact that the BirthYear column contains NULLs. 

I've noted before that INTERVAL(NULL, ...) returns -1 (I reported this separately as bug #803).

How to repeat:
CREATE TABLE test5 (BirthYear SMALLINT);

INSERT INTO test5 VALUES (3);
INSERT INTO test5 VALUES (NULL);

SELECT COUNT(*), CASE INTERVAL(BirthYear, 30, 40, 50, 60) WHEN -1 THEN "NULL" WHEN 0 THEN "Under 30" WHEN 1 THEN "From 30 to 39" WHEN 2 THEN "From 40 to 49" WHEN 3 THEN "From 50 to 59" WHEN 4 THEN "60 and over" END AS AgeCategory
FROM test5 GROUP BY AgeCategory;
[7 Jul 2003 21:49] MySQL Verification Team
Backtrace

Attachment: backtrace-bug#807.txt (text/plain), 13.45 KiB.

[7 Jul 2003 21:51] MySQL Verification Team
Thank you for the bug report. I was able to repeat:

usr/local/mysql/libexec/mysqld: ready for connections.
Version: '4.0.14-debug-log'  socket: '/tmp/mysql.sock'  port: 3306
[New Thread 163851 (LWP 2492)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 163851 (LWP 2492)]
Field::offset() (this=0x0) at field.cc:194
194       return (uint) (ptr - (char*) table->record[0]);
(gdb) backtrace full
#0  Field::offset() (this=0x0) at field.cc:194

For to see the complete backtrace please use the tab Files
and open the file backtrace-bug#807.txt.
[9 Jul 2003 6:22] MySQL Verification Team
Thank you for your bug report. This issue has been fixed in the latest
development tree for that product. You can find more information about
accessing our development trees at 
    http://www.mysql.com/doc/en/Installing_source_tree.html

A fix will dome in 4.0.14