Skip to content

Commit

Permalink
MDEV-31116 SIGSEGV in test_if_skip_sort_order|JOIN::optimize_stage2
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DaveGosselin-MariaDB committed Nov 8, 2023
1 parent 9cc179c commit 1f7ab85
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions mysql-test/main/order_by_innodb.result
Expand Up @@ -296,3 +296,13 @@ a b c
6 2 26
6 3 36
drop table t1;
#
# MDEV-31116: SIGSEGV in test_if_skip_sort_order|JOIN::optimize_stage2
#
CREATE TABLE t1 (a BINARY (2),b BINARY (1),KEY(a)) ENGINE=innodb;
INSERT INTO t1 select 'ab', NULL from seq_1_to_14;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE a >'') ORDER BY a LIMIT 1;
a b
ab NULL
DROP TABLE t1;
# End of 11.0 tests
9 changes: 9 additions & 0 deletions mysql-test/main/order_by_innodb.test
Expand Up @@ -250,3 +250,12 @@ explain select * from t1 force index(r) order by a,b limit 20;
explain select * from t1 force index(r) order by a desc,b limit 20;
select * from t1 force index(r) order by a desc,b limit 20;
drop table t1;

--echo #
--echo # MDEV-31116: SIGSEGV in test_if_skip_sort_order|JOIN::optimize_stage2
--echo #
CREATE TABLE t1 (a BINARY (2),b BINARY (1),KEY(a)) ENGINE=innodb;
INSERT INTO t1 select 'ab', NULL from seq_1_to_14;
SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE a >'') ORDER BY a LIMIT 1;
DROP TABLE t1;
--echo # End of 11.0 tests
2 changes: 1 addition & 1 deletion sql/sql_select.cc
Expand Up @@ -26478,7 +26478,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
!table->is_clustering_key(best_key)))
goto use_filesort;

if (table->opt_range_keys.is_set(best_key) && best_key != ref_key)
if (select && table->opt_range_keys.is_set(best_key) && best_key != ref_key)
{
key_map tmp_map;
tmp_map.clear_all(); // Force the creation of quick select
Expand Down

0 comments on commit 1f7ab85

Please sign in to comment.