SELECT hangs with ICP=on, InnoDB, EXISTS subquery
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MariaDB |
Fix Released
|
High
|
Sergey Petrunia |
Bug Description
The following query
SELECT COUNT(*) FROM t1 AS alias1, t2
WHERE c = g
AND ( EXISTS
( SELECT * FROM t1, t2
WHERE a = f
AND h <= alias1.e
AND a > alias1.b )
OR a = 0 AND h < 'z' );
hangs, seemingly forever, being executed with index_condition
The provided variation of the test case hits the problem on the 2nd SELECT. If you want it to happen on the 1st time, un-comment the line INSERT INTO t1 ... SELECT before the actual SELECT.
The problem is not limited to a connection: if the data is such that the 2nd attempt hangs, it happens regardless whether is is executed in the same connection as the 1st, or in another one.
COUNT in the select is not essential, it is there just to reduce the amount of produced output. It can be just SELECT *.
bzr version-info
revision-id: <email address hidden>
date: 2011-12-14 04:56:54 +0400
build-date: 2011-12-15 20:27:09 +0400
revno: 3349
branch-nick: maria-5.3
Also reproducible on 5.3.2 release.
Stack trace from the thread while it hangs:
#0 0xffffe430 in __kernel_vsyscall ()
#1 0x400c7125 in pthread_
#2 0x087e3dc2 in safe_cond_wait (cond=0x9e09cd4, mp=0x9e09c68,
file=0x89c1b38 "os/os0sync.c", line=210) at thr_mutex.c:498
#3 0x08704c5c in os_cond_wait (cond=0x9e09cd4, mutex=0x9e09c68)
at os/os0sync.c:210
#4 0x087054ac in os_event_wait_low (event=0x9e09c68, reset_sig_count=1)
at os/os0sync.c:636
#5 0x08740f54 in sync_array_
at sync/sync0arr.c:451
#6 0x087421a2 in rw_lock_x_lock_wait (lock=0x9e09b80,
file_
#7 0x0874228e in rw_lock_x_lock_low (lock=0x9e09b80, pass=0,
file_
#8 0x08742354 in rw_lock_x_lock_func (lock=0x9e09b80, pass=0,
file_
#9 0x0876aa16 in btr_search_
cursor=
#10 0x08769e0f in btr_search_
at ./include/
#11 0x08761ad8 in btr_cur_
tuple=
has_
mtr=0x53a4e8fc) at btr/btr0cur.c:722
#12 0x08768dc8 in btr_pcur_
tuple=
has_
mtr=0x53a4e8fc) at ./include/
#13 0x08730376 in row_sel_
sec_
out_
mtr=0x53a4e8fc) at row/row0sel.c:2947
#14 0x08732815 in row_search_
buf=0x9ee9810 "\376\217\
match_mode=1, direction=0) at row/row0sel.c:4577
#15 0x086d50e5 in ha_innobase:
buf=0x9ee9810 "\376\217\
find_
#16 0x08439120 in handler:
buf=0x9ee9810 "\376\217\
find_
#17 0x081eca1a in handler:
buf=0x9ee9810 "\376\217\
#18 0x08375bc3 in join_read_
#19 0x083743e4 in sub_select (join=0x9eebbd8, join_tab=0x9ee299c,
end_
#20 0x08374ad1 in evaluate_
error=0) at sql_select.cc:15372
#21 0x0837457f in sub_select (join=0x9eebbd8, join_tab=0x9ee2798,
end_
#22 0x08373c8c in do_select (join=0x9eebbd8, fields=0x9ef20dc, table=0x0,
procedure=0x0) at sql_select.cc:14836
#23 0x083581cd in JOIN::exec (this=0x9eebbd8) at sql_select.cc:2621
#24 0x083589fd in mysql_select (thd=0x9e62b18, rref_pointer_
tables=
order=0x0, group=0x0, having=0x0, proc_param=0x0,
select_
select_
#25 0x083508ef in handle_select (thd=0x9e62b18, lex=0x9e64214,
result=
#26 0x082ebe28 in execute_
at sql_parse.cc:5148
#27 0x082e3204 in mysql_execute_
#28 0x082ee463 in mysql_parse (thd=0x9e62b18,
rawbuf=
found_
#29 0x082e0e66 in dispatch_command (command=COM_QUERY, thd=0x9e62b18,
packet=
#30 0x082e0310 in do_command (thd=0x9e62b18) at sql_parse.cc:922
#31 0x082dd2d5 in handle_
#32 0x400c2b25 in start_thread () from /lib/libpthread
#33 0x402ee34e in clone () from /lib/libc.so.6
Minimal optimizer_switch: in_to_exists=
or materialization
(all three are current defaults)
Full optimizer_switch:
index_merge=
EXPLAIN:
1 PRIMARY alias1 ALL PRIMARY,c NULL NULL NULL 64 100.00 Using where
1 PRIMARY t2 ref g g 5 test.alias1.c 9 100.00 Using index condition; Using where
2 DEPENDENT SUBQUERY t1 index PRIMARY d 3 NULL 64 100.00 Using where; Using index
2 DEPENDENT SUBQUERY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index condition; Using where
Field or reference 'test.alias1.e' of SELECT #2 was resolved in SELECT #1
Field or reference 'test.alias1.b' of SELECT #2 was resolved in SELECT #1
select count(0) AS `COUNT(*)` from `test`.`t1` `alias1` join `test`.`t2` where ((`test`.`t2`.`g` = `test`.
# Notes on the test case:
#
# - It seems that keys k2,k3,k4 may be on an unused column,
# but on whatever reason are needed to be there.
# I could not get rid of them.
#
# - AUTO_INCREMENT is not needed, but I'm keeping it
# as it's easier to play with data this way.
# Test case:
--source include/
CREATE TABLE t1
( a INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
b INT, c INT, d DATE NOT NULL, e VARCHAR(1),
KEY (c), KEY (d), KEY k2(b), KEY k3(b), KEY k4(b)
) ENGINE=InnoDB;
INSERT INTO t1 (b,c,d,e) VALUES
(6,5,'2006-
(6,5,'2007-
(8,5,'1900-
(4,5,'2001-
(6,5,'2007-
(8,5,'1900-
(4,5,'2001-
(4,5,'1900-
(4,5,'2006-
(1,5,'2008-
(4,5,'1900-
(4,5,'2006-
(4,5,'2001-
(4,5,'2006-
(1,5,'2008-
(4,5,'1900-
(4,5,'2006-
(6,5,'2007-
(8,5,'1900-
(6,5,'2007-
(8,5,'1900-
(4,5,'2006-
(1,5,'2008-
(4,5,'1900-
(4,5,'2006-
(4,5,'2001-
(6,5,'2007-
(8,5,'1900-
(4,5,'2001-
(6,5,'2007-
(8,8,'1900-
(4,1,'2001-
CREATE TABLE t2
( f INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
g INT,
h VARCHAR(1),
KEY (g)
) ENGINE=InnoDB;
INSERT INTO t2 (g,h) VALUES
(3,'e')
(5,'l')
(7,'f')
(6,'i')
(0,'p')
(3,'e')
(7,'d')
(9,'u')
(0,'f')
(1,'u')
(6,'q')
(0,'f')
(1,'u')
(8,'y')
(5,'j')
(1,'x')
(0,'f')
(1,'u')
(7,'f')
(7,'d')
(9,'u')
(0,'f')
(5,'j')
(1,'x')
(4,'v')
(0,'p')
(3,'e')
(5,'l')
(0,'p')
(3,'e')
(7,'f')
# Uncomment this line if you want
# the query hang on the first run:
# INSERT INTO t1 (b,c,d,e) SELECT b,c,d,e FROM t1;
SET optimizer_
SELECT COUNT(*) FROM t1 AS alias1, t2
WHERE c = g
AND ( EXISTS
( SELECT * FROM t1, t2
WHERE a = f
AND h <= alias1.e
AND a > alias1.b )
OR a = 0 AND h < 'z' );
SELECT COUNT(*) FROM t1 AS alias1, t2
WHERE c = g
AND ( EXISTS
( SELECT * FROM t1, t2
WHERE a = f
AND h <= alias1.e
AND a > alias1.b )
OR a = 0 AND h < 'z' );
description: | updated |
Changed in maria: | |
importance: | Undecided → High |
Changed in maria: | |
status: | New → Fix Committed |
Fix released with 5.3.3-rc.