Crash in Item_field::Item_field from add_ref_to_table_cond() with semijoin+materialization
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
Fix Released
|
High
|
Sergey Petrunia |
Bug Description
The following query:
SELECT t2.a, t1.c
FROM t1, t2
WHERE t2.d IN ( SELECT d FROM t3 )
AND t1.d = t2.d
GROUP BY 1 , 2;
causes the following crash:
#3 <signal handler called>
#4 0x000000000059e554 in Item_field:
#5 0x00000000007445f1 in add_ref_
#6 0x000000000074e725 in JOIN::optimize (this=0x52e7f80) at sql_select.cc:1544
#7 0x00000000007505bb in mysql_select (thd=0x51dd268, rref_pointer_
order=0x0, group=0x529d740, having=0x0, proc_param=0x0, select_
at sql_select.cc:2887
#8 0x0000000000756a7a in handle_select (thd=0x51dd268, lex=0x51df670, result=0x529d8e0, setup_tables_
#9 0x00000000006a33de in execute_
#10 0x00000000006a50bc in mysql_execute_
#11 0x00000000006ade55 in mysql_parse (thd=0x51dd268,
rawbuf=
found_
#12 0x00000000006aed25 in dispatch_command (command=COM_QUERY, thd=0x51dd268,
packet=
at sql_parse.cc:1211
#13 0x00000000006b0333 in do_command (thd=0x51dd268) at sql_parse.cc:906
#14 0x000000000069ac67 in handle_
#15 0x00000033b600673d in start_thread () from /lib64/
#16 0x00000033b58d40cd in clone () from /lib64/libc.so.6
Explain also crashes. Seems that t2 must have 1 row for the crash to happen.
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:01:28 +0300
revno: 3167
branch-nick: maria-5.3
test case:
CREATE TABLE t1 (c int, d varchar(1), KEY(d)) ;
INSERT INTO t1 VALUES (2,'x')
CREATE TABLE t2 (a int, d varchar(1)) ;
INSERT INTO t2 VALUES (1,'x');
CREATE TABLE t3 (d varchar(1)) ;
INSERT INTO t3 VALUES ('x'),(
SET SESSION optimizer_
SELECT t2.a, t1.c
FROM t1, t2
WHERE t2.d IN ( SELECT d FROM t3 )
AND t1.d = t2.d
GROUP BY 1 , 2;
Changed in maria: | |
milestone: | none → 5.3 |
assignee: | nobody → Sergey Petrunia (sergefp) |
Changed in maria: | |
importance: | Undecided → High |
Changed in maria: | |
status: | Fix Committed → Fix Released |
It seems, the problem is that KEY_PART::fieldnr is not set for temporary tables. It is most apparent when materialization table's key has two columns:
MariaDB [bug836491]> create table t100 (a int, b int) ;
Query OK, 0 rows affected (0.12 sec)
MariaDB [bug836491]> insert into t100 select a,a from test.ten;
Query OK, 10 rows affected (0.05 sec)
Records: 10 Duplicates: 0 Warnings: 0
MariaDB [bug836491]> create table t101 as select * from t100;
Query OK, 10 rows affected (0.09 sec)
Records: 10 Duplicates: 0 Warnings: 0
MariaDB [bug836491]> explain select * from t100 where (a,b) in (select a,b from t101); ------- -----+- ------- -----+- ------- +------ ------- --+---- ------- ---+--- ------+ ------- ----+-- ----+-- -----+ ------- -----+- ------- -----+- ------- +------ ------- --+---- ------- ---+--- ------+ ------- ----+-- ----+-- -----+ ------- -----+- ------- -----+- ------- +------ ------- --+---- ------- ---+--- ------+ ------- ----+-- ----+-- -----+
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | PRIMARY | t100 | ALL | NULL | NULL | NULL | NULL | 10 | |
| 1 | PRIMARY | <subquery2> | eq_ref | distinct_key | distinct_key | 10 | func,func | 1 | |
| 2 | SUBQUERY | t101 | ALL | NULL | NULL | NULL | NULL | 10 | |
+----+-
3 rows in set (0.03 sec)
Breakpoint 21, create_tmp_table (thd=0xba91280, param=0xbaf535c, fields=@0xbaf53d8, group=0x0, distinct=true, save_sum_ fields= true, select_ options= 2147768832, rows_limit= 184467440737095 51615, table_alias= 0x89ac970 "sj-materialize", do_not_open=false) at sql_select.cc:13130 fields= true, select_ options= 2147768832, rows_limit= 184467440737095 51615, table_alias= 0x89ac970 "sj-materialize", do_not_open=false) at sql_select.cc:13130 materialization _part1 (sjm_tab=0xbb18b7c) at opt_subselect. cc:2959
(gdb) fini
Run till exit from #0 create_tmp_table (thd=0xba91280, param=0xbaf535c, fields=@0xbaf53d8, group=0x0, distinct=true, save_sum_
0x08424f59 in setup_sj_
Value returned is $77 = (TABLE *) 0xbb1a1f0
(gdb) p sjm->table- >key_info[ 0].key_ part[0] .fieldnr >key_info[ 0].key_ part[1] .fieldnr >key_info[ 0].key_ parts
$80 = 0
(gdb) p sjm->table-
$81 = 0
(gdb) p sjm->table-
$82 = 2
One can see that the key has two key parts, and key_part[ 1].fieldnr= =key_part[ 0].fieldnr, which is apparently wrong (a column can't be present in the key two times)