Skip to content

Commit 8d329aa

Browse files
committed
Bug #48709: Assertion failed in sql_select.cc:11782:
int join_read_key(JOIN_TAB*) The eq_ref access method TABLE_REF (accessed through JOIN_TAB) to save state and to track if this is the first row it finds or not. This state was not reset on subquery re-execution causing an assert. Fixed by resetting the state before the subquery re-execution.
1 parent 79c147f commit 8d329aa

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

mysql-test/r/subselect.result

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4502,4 +4502,29 @@ WHERE a = 230;
45024502
MAX(b) (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b)
45034503
NULL 0
45044504
DROP TABLE t1, st1, st2;
4505+
#
4506+
# Bug #48709: Assertion failed in sql_select.cc:11782:
4507+
# int join_read_key(JOIN_TAB*)
4508+
#
4509+
CREATE TABLE t1 (pk int PRIMARY KEY, int_key int);
4510+
INSERT INTO t1 VALUES (10,1), (14,1);
4511+
CREATE TABLE t2 (pk int PRIMARY KEY, int_key int);
4512+
INSERT INTO t2 VALUES (3,3), (5,NULL), (7,3);
4513+
# should have eq_ref for t1
4514+
EXPLAIN
4515+
SELECT * FROM t2 outr
4516+
WHERE outr.int_key NOT IN (SELECT t1.pk FROM t1, t2)
4517+
ORDER BY outr.pk;
4518+
id select_type table type possible_keys key key_len ref rows Extra
4519+
x x outr ALL x x x x x x
4520+
x x t1 eq_ref x x x x x x
4521+
x x t2 index x x x x x x
4522+
# should not crash on debug binaries
4523+
SELECT * FROM t2 outr
4524+
WHERE outr.int_key NOT IN (SELECT t1.pk FROM t1, t2)
4525+
ORDER BY outr.pk;
4526+
pk int_key
4527+
3 3
4528+
7 3
4529+
DROP TABLE t1,t2;
45054530
End of 5.0 tests.

mysql-test/t/subselect.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,4 +3481,30 @@ WHERE a = 230;
34813481

34823482
DROP TABLE t1, st1, st2;
34833483

3484+
--echo #
3485+
--echo # Bug #48709: Assertion failed in sql_select.cc:11782:
3486+
--echo # int join_read_key(JOIN_TAB*)
3487+
--echo #
3488+
3489+
CREATE TABLE t1 (pk int PRIMARY KEY, int_key int);
3490+
INSERT INTO t1 VALUES (10,1), (14,1);
3491+
3492+
CREATE TABLE t2 (pk int PRIMARY KEY, int_key int);
3493+
INSERT INTO t2 VALUES (3,3), (5,NULL), (7,3);
3494+
3495+
--echo # should have eq_ref for t1
3496+
--replace_column 1 x 2 x 5 x 6 x 7 x 8 x 9 x 10 x
3497+
EXPLAIN
3498+
SELECT * FROM t2 outr
3499+
WHERE outr.int_key NOT IN (SELECT t1.pk FROM t1, t2)
3500+
ORDER BY outr.pk;
3501+
3502+
--echo # should not crash on debug binaries
3503+
SELECT * FROM t2 outr
3504+
WHERE outr.int_key NOT IN (SELECT t1.pk FROM t1, t2)
3505+
ORDER BY outr.pk;
3506+
3507+
DROP TABLE t1,t2;
3508+
3509+
34843510
--echo End of 5.0 tests.

sql/sql_select.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,11 @@ JOIN::reinit()
15531553
if (join_tab_save)
15541554
memcpy(join_tab, join_tab_save, sizeof(JOIN_TAB) * tables);
15551555

1556+
/* need to reset ref access state (see join_read_key) */
1557+
if (join_tab)
1558+
for (uint i= 0; i < tables; i++)
1559+
join_tab[i].ref.key_err= TRUE;
1560+
15561561
if (tmp_join)
15571562
restore_tmp();
15581563

0 commit comments

Comments
 (0)