Bug #31160 MAKETIME() crashes server when returning NULL in ORDER BY using filesort
Submitted: 23 Sep 2007 17:14 Modified: 5 Nov 2007 2:59
Reporter: Martin Hansson Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:5.1, 5.2, 5.0 (no crash but incorrect inside) OS:Any
Assigned to: Martin Hansson CPU Architecture:Any

[23 Sep 2007 17:14] Martin Hansson
Description:
if MAKETIME() is used certain ways which makes it return NULL in an ORDER BY, the server crashes.

This bug has been forked off Bug#30889.

How to repeat:
CREATE TABLE t1 (
  a TIMESTAMP
);

INSERT INTO t1 VALUES (now()), (now());

SELECT * FROM t1 ORDER BY MAKETIME(1, 1, a);

Suggested fix:
Let maybe_null be true in Item_func_maketime.
[23 Sep 2007 18:50] MySQL Verification Team
Thank you for the bug report. Verified as described.

070923 15:47:33 [Note] /home/miguel/dbs/5.1/libexec/mysqld: ready for connections.
Version: '5.1.23-beta-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
[New Thread -1304544368 (LWP 2494)]
mysqld: filesort.cc:737: void make_sortkey(SORTPARAM*, uchar*, uchar*): Assertion `0' failed.

Program received signal SIGABRT, Aborted.
[Switching to Thread -1304544368 (LWP 2494)]
0x00110402 in __kernel_vsyscall ()
(gdb) bt full
#0  0x00110402 in __kernel_vsyscall ()
No symbol table info available.
#1  0x00b59d40 in raise () from /lib/libc.so.6
No symbol table info available.
#2  0x00b5b591 in abort () from /lib/libc.so.6
No symbol table info available.
#3  0x00b5338b in __assert_fail () from /lib/libc.so.6
No symbol table info available.
#4  0x08390ce2 in make_sortkey (param=0xb23e1bd4, t

<cut>
[24 Sep 2007 15:30] 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/34530

ChangeSet@1.2572, 2007-09-24 17:32:21+02:00, mhansson@linux-st28.site +4 -0
  Bug#31160: MAKETIME() crashes server when returning NULL in ORDER BY using filesort
  
  Even though it returns NULL, the MAKETIME function did not have this property set,
  causing a failed assertion (designed to catch exactly this).
  Fixed by setting the nullability property of MAKETIME().
[4 Oct 2007 20:46] Sergey Petrunya
The bug is actually present in 5.0, too. The only reason we don't see a crash is that 5.0 does not have DBUG_ASSERT() statement.
[5 Oct 2007 12:56] 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/34971

ChangeSet@1.2530, 2007-10-05 14:59:38+02:00, mhansson@linux-st28.site +4 -0
  Bug#31160: MAKETIME() crashes server when returning NULL in ORDER BY using filesort
  
  Even though it returns NULL, the MAKETIME function did not have this property set,
  causing a failed assertion (designed to catch exactly this).
  Fixed by setting the nullability property of MAKETIME().
[9 Oct 2007 11:51] 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/35191

ChangeSet@1.2530, 2007-10-09 13:54:53+02:00, mhansson@linux-st28.site +4 -0
  Bug#31160: MAKETIME() crashes server when returning NULL in ORDER BY using filesort
  
  Even though it returns NULL, the MAKETIME function did not have this property set,
  causing a failed assertion (designed to catch exactly this).
  Fixed by setting the nullability property of MAKETIME().
[9 Oct 2007 12:54] 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/35195

ChangeSet@1.2530, 2007-10-09 14:58:09+02:00, mhansson@linux-st28.site +4 -0
  Bug#31160: MAKETIME() crashes server when returning NULL in ORDER BY using filesort
  
  Even though it returns NULL, the MAKETIME function did not have this property set,
  causing a failed assertion (designed to catch exactly this).
  Fixed by setting the nullability property of MAKETIME().
[29 Oct 2007 8:42] Bugs System
Pushed into 5.0.52
[29 Oct 2007 8:45] Bugs System
Pushed into 5.1.23-beta
[29 Oct 2007 8:49] Bugs System
Pushed into 6.0.4-alpha
[5 Nov 2007 2:59] Paul DuBois
Noted in 5.0.52, 5.1.23, 6.0.4 changelogs.

If MAKETIME() returned NULL when used in an ORDER BY that was
evaluated using filesort, a server crash could result.