Crash in JOIN::get_partial_cost_and_fanout with semijoin+materialization
| Affects | Status | Importance | Assigned to | Milestone | |
|---|---|---|---|---|---|
| MariaDB |
Fix Released
|
Critical
|
Sergey Petrunia | ||
Bug Description
The following query:
SELECT t1.a
FROM t1
WHERE t1.a IN (
SELECT t5.a
FROM t5, t6
)
HAVING a IN (
SELECT a
FROM t7
);
crashes as follows:
#3 <signal handler called>
#4 0x000000000071d9ed in JOIN::get_
record_
#5 0x00000000008029b0 in JOIN::choose_
#6 0x000000000074a253 in make_join_
#7 0x000000000074ca82 in JOIN::optimize (this=0xb7e6bd0) at sql_select.cc:1113
#8 0x000000000057ab4e in st_select_
#9 0x00000000008038c0 in JOIN::optimize_
#10 0x000000000074eac1 in JOIN::optimize (this=0xb7da790) at sql_select.cc:1622
#11 0x00000000007505bb in mysql_select (thd=0xb6ce2c8, rref_pointer_
order=0x0, group=0x0, having=0xb78e5c0, proc_param=0x0, select_
at sql_select.cc:2887
#12 0x0000000000756a7a in handle_select (thd=0xb6ce2c8, lex=0xb6d06d0, result=0xb78e810, setup_tables_
#13 0x00000000006a33de in execute_
#14 0x00000000006a50bc in mysql_execute_
#15 0x00000000006ade55 in mysql_parse (thd=0xb6ce2c8,
rawbuf=
found_
#16 0x00000000006aed25 in dispatch_command (command=COM_QUERY, thd=0xb6ce2c8,
packet=
at sql_parse.cc:1211
#17 0x00000000006b0333 in do_command (thd=0xb6ce2c8) at sql_parse.cc:906
#18 0x000000000069ac67 in handle_
#19 0x00000033b600673d in start_thread () from /lib64/
#20 0x00000033b58d40cd in clone () from /lib64/libc.so.6
It appears it is important for table t5 to have zero rows.
explain:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
3 SUBQUERY t7 ALL NULL NULL NULL NULL 2
minimal optimizer switch: semijoin=
full optimizer_switch:
index_merge=
bzr version-info:
revision-id: <email address hidden>
date: 2011-08-27 00:40:29 +0300
build-date: 2011-08-29 11:50:40 +0300
revno: 3167
branch-nick: maria-5.3
test case:
CREATE TABLE t1 (a varchar(1));
INSERT INTO t1 VALUES ('a'),('a');
CREATE TABLE t5 (a varchar(1));
CREATE TABLE t6 (a int);
INSERT INTO t6 VALUES (1),(2);
CREATE TABLE t7 (a varchar(1));
INSERT INTO t7 VALUES ('a'),('a');
SET SESSION optimizer_
SELECT t1.a
FROM t1
WHERE t1.a IN (
SELECT t5.a
FROM t5, t6
)
HAVING a IN (
SELECT a
FROM t7
);
| Changed in maria: | |
| milestone: | none → 5.3 |
| assignee: | nobody → Sergey Petrunia (sergefp) |
| Changed in maria: | |
| importance: | Undecided → High |
| Changed in maria: | |
| importance: | High → Critical |
| Changed in maria: | |
| assignee: | Sergey Petrunia (sergefp) → Timour Katchaounov (timour) |
| assignee: | Timour Katchaounov (timour) → Sergey Petrunia (sergefp) |
| Changed in maria: | |
| status: | New → Fix Committed |
| Changed in maria: | |
| status: | Fix Committed → Fix Released |

The crash happens inside JOIN::get_ partial_ cost_and_ fanout( ) in this code:
sj_ inner_fanout= 1.0; sj_table= i + tab->n_sj_tables;
last_
}
>> if (tab->records_read && (tab->table->map & filter_map))
{
record_count *= tab->records_read;
read_time += tab->read_time;
if (tab->emb_sj_nest)
we crash because tab->table==NULL.
tab->table==NULL because 'tab' refers to SJ-Materialization nes