mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
MDEV-35164: optimizer_join_limit_pref_ratio: assertion when the ORDER BY table becomes constant
Assertion failure has happened due to this scenario: A query was ran with optimizer_join_limit_pref_ratio=1. The query had "ORDER BY t1.col LIMIT N". The optimizer set join->limit_shortcut_applicable=1. Then, table t1 was marked as constant. The code in choose_query_plan() still set join->limit_optimization_mode=1 which caused the optimizer to only consider t1 as the first non-const table. But t1 was already put into the join prefix as the constant table. The optimizer couldn't produce any join order at all and crashed. Fixed by not searching for shortcut plan if ORDER BY table is a constant. We will not try to do sorting anyway in this case (and LIMIT short-cutting will be done for any join order).
This commit is contained in:
@ -205,9 +205,29 @@ set @trace=(select trace from information_schema.optimizer_trace);
|
||||
--source include/optimizer_trace_no_costs.inc
|
||||
select json_detailed(json_extract(@trace, '$**.join_limit_shortcut_choice')) as JS;
|
||||
|
||||
|
||||
set optimizer_search_depth=@tmp_osd;
|
||||
set optimizer_trace=@tmp_os;
|
||||
|
||||
--echo # An extra testcase for MDEV-35164 (its main testcase is below).
|
||||
alter table t1 add unique key(col2);
|
||||
insert into t10 select * from t10;
|
||||
insert into t10 select * from t10;
|
||||
analyze table t10;
|
||||
|
||||
--echo # This will not crash and also show that sorting is not done when
|
||||
--echo # ORDER BY only refers to const table columns:
|
||||
explain
|
||||
select
|
||||
*
|
||||
from
|
||||
t1
|
||||
join t10 on t1.a=t10.a
|
||||
join t11 on t1.b=t11.b
|
||||
where
|
||||
t1.col2=3
|
||||
order by
|
||||
t1.col1
|
||||
limit 10;
|
||||
drop table t1, t10, t11;
|
||||
|
||||
--echo #
|
||||
@ -219,4 +239,15 @@ INSERT INTO t1 VALUES (1),(2);
|
||||
SELECT * FROM t1 ORDER BY c1 LIMIT 1;
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-35164: optimizer_join_limit_pref_ratio: assertion when the ORDER BY table becomes constant
|
||||
--echo # Original testcase:
|
||||
--echo #
|
||||
SET optimizer_join_limit_pref_ratio=1;
|
||||
CREATE TABLE t1 (a INT KEY,b INT, KEY(b)) ;
|
||||
INSERT INTO t1 VALUES (2,NULL);
|
||||
INSERT INTO t1 VALUES (5,NULL);
|
||||
SELECT * FROM t1 NATURAL JOIN t1 AS t2 WHERE t1.b=NULL ORDER BY t1.a LIMIT 1;
|
||||
DROP TABLE t1;
|
||||
|
||||
set optimizer_join_limit_pref_ratio=default;
|
||||
|
Reference in New Issue
Block a user