Skip to content

Commit

Permalink
MDEV-23596: Assertion `tab->ref.use_count' failed in join_read_key_un…
Browse files Browse the repository at this point in the history
…lock_row

The issue here was that the query was using ORDER BY LIMIT optimzation where
the access method was changed from EQ_REF access to an index scan (index that would
resolve the ORDER BY clause).
But the parameter READ_RECORD::unlock_row was not reset to rr_unlock_row, which is
used when the access method is not EQ_REF access.
  • Loading branch information
Varun Gupta committed Aug 27, 2020
1 parent 62d1e3b commit f69cc26
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mysql-test/r/order_by.result
Original file line number Diff line number Diff line change
Expand Up @@ -3356,3 +3356,19 @@ SET max_sort_length= @save_max_sort_length;
SET sort_buffer_size= @save_sort_buffer_size;
SET max_length_for_sort_data= @save_max_length_for_sort_data;
DROP TABLE t1;
#
# MDEV-23596: Assertion `tab->ref.use_count' failed in join_read_key_unlock_row
#
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, KEY(b));
INSERT INTO t1 VALUES (0, 1),(1, 2);
CREATE TABLE t2 SELECT * FROM t1;
EXPLAIN SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2
2 DEPENDENT SUBQUERY t1 index PRIMARY b 5 NULL 1 Using where
SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2;
c
1
NULL
DROP TABLE t1,t2;
# end of 10.1 tests
15 changes: 15 additions & 0 deletions mysql-test/t/order_by.test
Original file line number Diff line number Diff line change
Expand Up @@ -2196,3 +2196,18 @@ SET max_sort_length= @save_max_sort_length;
SET sort_buffer_size= @save_sort_buffer_size;
SET max_length_for_sort_data= @save_max_length_for_sort_data;
DROP TABLE t1;

--echo #
--echo # MDEV-23596: Assertion `tab->ref.use_count' failed in join_read_key_unlock_row
--echo #

CREATE TABLE t1 (a INT PRIMARY KEY, b INT, KEY(b));
INSERT INTO t1 VALUES (0, 1),(1, 2);
CREATE TABLE t2 SELECT * FROM t1;

EXPLAIN SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2;
SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2;

DROP TABLE t1,t2;

--echo # end of 10.1 tests
3 changes: 3 additions & 0 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21601,6 +21601,9 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
else if (select && select->quick)
select->quick->need_sorted_output();

tab->read_record.unlock_row= (tab->type == JT_EQ_REF) ?
join_read_key_unlock_row : rr_unlock_row;

} // QEP has been modified

/*
Expand Down

0 comments on commit f69cc26

Please sign in to comment.