query with derived table and GROUP BY on I_S crash when derived_with_keys=on
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
Fix Released
|
Critical
|
Igor Babaev |
Bug Description
drop table if exists test.t1;
create table test.t1 (c1 int primary key, c2 char(5));
set optimizer_
SELECT 1
FROM INFORMATION_
INNER JOIN ( SELECT TABLE_SCHEMA,
ON ( COLUMNS.
drop table t1;
This crashes mariadb-5.5.20 with null-pointer exception in
ha_maria:
I did a rough trace of how the crash is reached by examing the mysqld.1.trace
file from mysql-test-run --debug:
mysql_select
JOIN::prepare
st_select_
TABLE_
mysql_
# Note, it doesn't call mysql_derived_
create_
create_
get_
JOIN:
JOIN::optimize
JOIN::
convert_
simplify_joins
build_
optimize_cond
get_sort_by_table
make_join_
get_
make_select
reset_nj_counters
make_outerjoin
make_join_select
add_
SQL_
-> CRASH due to not opened handler
So inside mysql_select(), we first call JOIN::prepare, which ends up in
mysql_handle_
allocates the new handler object for the Aria tmp table. Note that this
handler object is never open()'ed.
After, mysql_select() calls JOIN::optimize(). This goes through a number of
calls until it does make_join_select(). And inside make_join_select() we end
up in ha_maria:
NULL pointer access.
I will have to leave to the optimiser people to investigate further why the
handler is accessed without being opened first and what the fix may be.
Stack trace:
#0 0x00007f1e65fdd4ec in __pthread_kill (threadid=
#1 0x0000000000cd6c06 in my_write_core (sig=11) at /home/knielsen/
#2 0x00000000007d5301 in handle_fatal_signal (sig=11) at /home/knielsen/
#3 <signal handler called>
#4 0x0000000000b41c6d in ha_maria::scan_time (this=0x2906b18) at /home/knielsen/
#5 0x00000000008d34b5 in SQL_SELECT:
ordered_
#6 0x000000000066d223 in make_join_select (join=0x28f6838, select=0x2908748, cond=0x2908930) at /home/knielsen/
#7 0x0000000000659dfe in JOIN::optimize (this=0x28f6838) at /home/knielsen/
#8 0x000000000065f83d in mysql_select (thd=0x2779240, rref_pointer_
select_
#9 0x0000000000656a5c in handle_select (thd=0x2779240, lex=0x277b500, result=0x28a2718, setup_tables_
#10 0x0000000000630710 in execute_
#11 0x00000000006299d0 in mysql_execute_
#12 0x0000000000632e9f in mysql_parse (thd=0x2779240,
rawbuf=
#13 0x00000000006270aa in dispatch_command (command=COM_QUERY, thd=0x2779240,
packet=
#14 0x000000000062639a in do_command (thd=0x2779240) at /home/knielsen/
#15 0x0000000000721422 in do_handle_
#16 0x0000000000720e0d in handle_
#17 0x0000000000c812c3 in pfs_spawn_thread (arg=0x28f1170) at /home/knielsen/
#18 0x00007f1e65fd7b50 in start_thread (arg=<optimized out>) at pthread_
#19 0x00007f1e64d2c90d in clone () at ../sysdeps/
#20 0x0000000000000000 in ?? ()
This was originally reported on IRC #maria by user Dev0n, with the following
query generated by the openark online alter table tool:
drop table if exists test.t1;
create table test.t1 (c1 int primary key, c2 char(5));
set optimizer_
SELECT COLUMNS.
If we set optimizer_
summary: |
- query with derived table and GROUP BY on I_S crash - whenderived_with_keys=on + query with derived table and GROUP BY on I_S crash when + derived_with_keys=on |
Changed in maria: | |
importance: | Undecided → High |
Changed in maria: | |
importance: | High → Critical |
status: | Confirmed → In Progress |
Changed in maria: | |
milestone: | 5.5 → 5.3 |
Changed in maria: | |
status: | In Progress → Fix Committed |
The crash is caused by a bug in the function JOIN::drop_ unused_ derived_ keys of the mariadb 5.3 code line.
The fix was pushed into the 5.3 tree.