Skip to content

Commit 1f7ab85

Browse files
MDEV-31116 SIGSEGV in test_if_skip_sort_order|JOIN::optimize_stage2
test_if_skip_sort_order() should check that the 'select' pointer (=tab->select) is not NULL before dereferencing it when invoking the test_quick_select method. The check was erroneously removed by: 1c88ac6 Simple cleanup of removing QQ comments from sql_select.cc
1 parent 9cc179c commit 1f7ab85

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

mysql-test/main/order_by_innodb.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,13 @@ a b c
296296
6 2 26
297297
6 3 36
298298
drop table t1;
299+
#
300+
# MDEV-31116: SIGSEGV in test_if_skip_sort_order|JOIN::optimize_stage2
301+
#
302+
CREATE TABLE t1 (a BINARY (2),b BINARY (1),KEY(a)) ENGINE=innodb;
303+
INSERT INTO t1 select 'ab', NULL from seq_1_to_14;
304+
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE a >'') ORDER BY a LIMIT 1;
305+
a b
306+
ab NULL
307+
DROP TABLE t1;
308+
# End of 11.0 tests

mysql-test/main/order_by_innodb.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,12 @@ explain select * from t1 force index(r) order by a,b limit 20;
250250
explain select * from t1 force index(r) order by a desc,b limit 20;
251251
select * from t1 force index(r) order by a desc,b limit 20;
252252
drop table t1;
253+
254+
--echo #
255+
--echo # MDEV-31116: SIGSEGV in test_if_skip_sort_order|JOIN::optimize_stage2
256+
--echo #
257+
CREATE TABLE t1 (a BINARY (2),b BINARY (1),KEY(a)) ENGINE=innodb;
258+
INSERT INTO t1 select 'ab', NULL from seq_1_to_14;
259+
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE a >'') ORDER BY a LIMIT 1;
260+
DROP TABLE t1;
261+
--echo # End of 11.0 tests

sql/sql_select.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26478,7 +26478,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
2647826478
!table->is_clustering_key(best_key)))
2647926479
goto use_filesort;
2648026480

26481-
if (table->opt_range_keys.is_set(best_key) && best_key != ref_key)
26481+
if (select && table->opt_range_keys.is_set(best_key) && best_key != ref_key)
2648226482
{
2648326483
key_map tmp_map;
2648426484
tmp_map.clear_all(); // Force the creation of quick select

0 commit comments

Comments
 (0)