Crash or invalid read at st_join_table::cleanup, st_table::disable_keyread with materialization=ON, semijoin=ON
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
Fix Released
|
Critical
|
Sergey Petrunia |
Bug Description
Queries similar to the one provided in the test case either cause a crash or valgrind 'Invalid read' errors.
The crash is sporadic and was mainly observed on a non-simplified test case.
Valgrind complaints are persistent.
Stack trace from a crash:
#2 0x00000000006e0125 in handle_segfault (sig=11) at mysqld.cc:2827
#3 <signal handler called>
#4 0x000000000076ce2c in st_table:
at table.h:990
#5 0x000000000078821f in st_join_
at sql_select.cc:9733
#6 0x0000000000776d53 in JOIN::destroy (this=0x300fa60) at sql_select.cc:2788
#7 0x00000000008f3a49 in st_select_
at sql_union.cc:930
#8 0x00000000008f35fe in st_select_
at sql_union.cc:795
#9 0x00000000008f3aa3 in st_select_
at sql_union.cc:937
#10 0x00000000007774b6 in mysql_select (thd=0x7fab8c0c
rref_
fields=..., conds=0x2fa0d08, og_num=3, order=0x2fa1228, group=0x0,
having=
result=
at sql_select.cc:2987
#11 0x000000000076dd1d in handle_select (thd=0x7fab8c0c
lex=
at sql_select.cc:283
#12 0x00000000006fce84 in execute_
all_
#13 0x00000000006f3f5a in mysql_execute_
at sql_parse.cc:2250
#14 0x00000000006ff864 in mysql_parse (thd=0x7fab8c0c
rawbuf=
length=701, found_semicolon
#15 0x00000000006f1772 in dispatch_command (command=COM_QUERY,
thd=
at sql_parse.cc:1221
#16 0x00000000006f0aa6 in do_command (thd=0x7fab8c0c
#17 0x00000000006ed9fc in handle_
at sql_connect.cc:1191
#18 0x00007faba7f50a4f in start_thread () from /lib64/
One of the traces from Valgrind (for the provided test case, it produces 13 of those, the full output is attached):
==2328== Invalid read of size 1
==2328== at 0x831667F: st_table:
==2328== by 0x832FADA: st_join_
==2328== by 0x831F3F7: JOIN::destroy() (sql_select.
==2328== by 0x8484E59: st_select_
==2328== by 0x8484A6E: st_select_
==2328== by 0x8484EAE: st_select_
==2328== by 0x831FB1D: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_
==2328== by 0x83174A9: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:283)
==2328== by 0x82B03DE: execute_
==2328== by 0x82A7196: mysql_execute_
==2328== by 0x82B2A2A: mysql_parse(THD*, char*, unsigned int, char const**) (sql_parse.cc:6113)
==2328== by 0x82A4DC8: dispatch_
==2328== by 0x82A421B: do_command(THD*) (sql_parse.cc:916)
==2328== by 0x82A114B: handle_
==2328== by 0xBC9AB4: start_thread (in /lib/libpthread
==2328== by 0xB2083D: clone (in /lib/libc-2.11.so)
==2328== Address 0x5925c98 is 1,688 bytes inside a block of size 2,964 free'd
==2328== at 0x40057F6: free (vg_replace_
==2328== by 0x879BACA: _myfree (safemalloc.c:335)
==2328== by 0x879AE29: free_root (my_alloc.c:364)
==2328== by 0x833A991: free_tmp_
==2328== by 0x8241B5D: subselect_
==2328== by 0x823748D: Item_subselect:
==2328== by 0x823764C: Item_in_
==2328== by 0x832FB97: st_join_
==2328== by 0x8330552: JOIN::cleanup(bool) (sql_select.
==2328== by 0x8484F51: st_select_
==2328== by 0x8330302: JOIN::join_free() (sql_select.
==2328== by 0x833B099: do_select(JOIN*, List<Item>*, st_table*, Procedure*) (sql_select.
==2328== by 0x831F22F: JOIN::exec() (sql_select.
==2328== by 0x831FA5E: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_
==2328== by 0x83174A9: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:283)
==2328== by 0x82B03DE: execute_
revision-id: <email address hidden>
date: 2011-12-09 14:30:50 -0800
build-date: 2011-12-11 00:53:46 +0300
revno: 3339
branch-nick: maria-5.3
Crash was also observed on older versions, including 5.3.2 release, with materialization
Minimal optimizer_switch: not required for the current 5.3-main (materializatio
Full optimizer_
EXPLAIN output:
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2100.00 Using where; Using temporary
2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 5 test.t2.b 1 100.00 Using where; Distinct
3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00 Using temporary
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache>
Test case (if it doesn't produce a crash, run with valgrind):
# These are defaults now, but setting them for older versions
SET optimizer_
CREATE TABLE t1 ( a INT );
INSERT INTO t1 VALUES (1), (2);
CREATE TABLE t2 ( b INT );
INSERT INTO t2 VALUES (3), (4);
CREATE TABLE t3 ( c INT );
INSERT INTO t3 VALUES (5), (6);
SELECT * FROM t1 WHERE EXISTS (
SELECT DISTINCT b FROM t2
WHERE b <= a
AND b IN ( SELECT c FROM t3 GROUP BY c )
);
Changed in maria: | |
status: | New → Confirmed |
importance: | Undecided → Critical |
assignee: | Sergey Petrunia (sergefp) → Igor Babaev (igorb-seattle) |
Changed in maria: | |
status: | Confirmed → Fix Committed |
Changed in maria: | |
assignee: | Igor Babaev (igorb-seattle) → Sergey Petrunia (sergefp) |
Fix released with 5.3.3-rc.