Bug #46583 Crash when non-NULL index for ORDER BY replaces cost-based optimizer's index
Submitted: 6 Aug 2009 10:55 Modified: 10 Aug 2009 15:30
Reporter: Martin Hansson Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[6 Aug 2009 10:55] Martin Hansson
Description:
If the cost-based optimizer finds an index i to be the best for reading the key, the decision may still be overridden by ORDER BY optimization (skip using temporary table if possible as this is always cheaper). If so happens, and i is replaced with another index, and the first keypart's column is non-NULLable, there is a crash when initializing the use of the new index.

How to repeat:
see attached test file.
[6 Aug 2009 10:59] Martin Hansson
Test case

Attachment: bug46583.test (application/octet-stream, text), 865 bytes.

[6 Aug 2009 11:32] MySQL Verification Team
c:\dbs>c:\dbs\5.1\bin\mysqld --defaults-file=c:\dbs\5.1\my.ini --standalone --console
090806  8:29:33 [Note] Plugin 'FEDERATED' is disabled.
090806  8:29:34  InnoDB: Started; log sequence number 0 396668
090806  8:29:35 [Note] Event Scheduler: Loaded 1 event
090806  8:29:35 [Note] c:\dbs\5.1\bin\mysqld: ready for connections.
Version: '5.1.37-Win X64-log'  socket: ''  port: 3510  Source distribution
090806  8:31:16 - mysqld got exception 0xc0000005 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=8384512
read_buffer_size=131072
max_used_connections=1
max_threads=151
threads_connected=1
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 338112 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x7796230
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
00000001400E45DC    mysqld.exe!SQL_SELECT::test_quick_select()[opt_range.cc:2214]
0000000140196647    mysqld.exe!test_if_skip_sort_order()[sql_select.cc:13255]
00000001401A2B2D    mysqld.exe!JOIN::optimize()[sql_select.cc:1156]
00000001401A5319    mysqld.exe!mysql_select()[sql_select.cc:2372]
00000001401A561F    mysqld.exe!mysql_explain_union()[sql_select.cc:16418]
0000000140163ADA    mysqld.exe!execute_sqlcom_select()[sql_parse.cc:4992]
0000000140165637    mysqld.exe!mysql_execute_command()[sql_parse.cc:2209]
000000014016ACE9    mysqld.exe!mysql_parse()[sql_parse.cc:5937]
000000014016B88A    mysqld.exe!dispatch_command()[sql_parse.cc:1215]
000000014016C657    mysqld.exe!do_command()[sql_parse.cc:854]
00000001401FE7B7    mysqld.exe!handle_one_connection()[sql_connect.cc:1127]
0000000140272C85    mysqld.exe!pthread_start()
00000001403B8E57    mysqld.exe!_callthreadstart()[thread.c:295]
00000001403B8F25    mysqld.exe!_threadstart()[thread.c:275]
000000007775C3BD    kernel32.dll!BaseThreadInitThunk()
0000000077CD4581    ntdll.dll!RtlUserThreadStart()
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 00000000077EF6E0=EXPLAIN
SELECT DISTINCT a FROM t1 WHERE b = 1 ORDER BY c DESC LIMIT 0, 9
thd->thread_id=1
thd->killed=NOT_KILLED
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
[6 Aug 2009 11:43] MySQL Verification Team
5.0 and 6.0 weren't affected by this bug against the same test case.
[10 Aug 2009 15:30] Martin Hansson
Pushed along with Bug#46454