mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-35072: Assertion with optimizer_join_limit_pref_ratio and 1-table select
Variant for 11.2+: In recompute_join_cost_with_limit(), do not subtract the cost of checking the WHERE: pos->records_read* WHERE_COST_THD(join->thd) It is already included in pos->read_time. Also added comments about difference between this fix and the pre-11.2 variant.
This commit is contained in:
@ -114,7 +114,7 @@ JS
|
||||
"full_join_cost": "REPLACED",
|
||||
"risk_ratio": 10,
|
||||
"shortcut_join_cost": "REPLACED",
|
||||
"shortcut_cost_with_risk": 0.492018616,
|
||||
"shortcut_cost_with_risk": 0.495218616,
|
||||
"use_shortcut_cost": true
|
||||
}
|
||||
]
|
||||
@ -166,7 +166,7 @@ JS
|
||||
"full_join_cost": "REPLACED",
|
||||
"risk_ratio": 10,
|
||||
"shortcut_join_cost": "REPLACED",
|
||||
"shortcut_cost_with_risk": 19.4241863,
|
||||
"shortcut_cost_with_risk": 16.2273863,
|
||||
"use_shortcut_cost": true
|
||||
}
|
||||
]
|
||||
@ -254,7 +254,7 @@ JS
|
||||
"full_join_cost": "REPLACED",
|
||||
"risk_ratio": 10,
|
||||
"shortcut_join_cost": "REPLACED",
|
||||
"shortcut_cost_with_risk": 199.426608,
|
||||
"shortcut_cost_with_risk": 197.826608,
|
||||
"use_shortcut_cost": false
|
||||
}
|
||||
]
|
||||
@ -375,7 +375,7 @@ JS
|
||||
"full_join_cost": "REPLACED",
|
||||
"risk_ratio": 10,
|
||||
"shortcut_join_cost": "REPLACED",
|
||||
"shortcut_cost_with_risk": 0.532449162,
|
||||
"shortcut_cost_with_risk": 0.535649162,
|
||||
"use_shortcut_cost": true
|
||||
}
|
||||
]
|
||||
@ -463,11 +463,21 @@ JS
|
||||
"full_join_cost": "REPLACED",
|
||||
"risk_ratio": 10,
|
||||
"shortcut_join_cost": "REPLACED",
|
||||
"shortcut_cost_with_risk": 0.492018616,
|
||||
"shortcut_cost_with_risk": 0.495218616,
|
||||
"use_shortcut_cost": true
|
||||
}
|
||||
]
|
||||
set optimizer_search_depth=@tmp_osd;
|
||||
set optimizer_trace=@tmp_os;
|
||||
set optimizer_join_limit_pref_ratio=default;
|
||||
drop table t1, t10, t11;
|
||||
#
|
||||
# MDEV-35072: Assertion failure with optimizer_join_limit_pref_ratio and 1-table select
|
||||
#
|
||||
SET optimizer_join_limit_pref_ratio=1;
|
||||
CREATE TABLE t1 (c1 INT, INDEX(c1));
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
SELECT * FROM t1 ORDER BY c1 LIMIT 1;
|
||||
c1
|
||||
1
|
||||
DROP TABLE t1;
|
||||
set optimizer_join_limit_pref_ratio=default;
|
||||
|
@ -208,6 +208,15 @@ select json_detailed(json_extract(@trace, '$**.join_limit_shortcut_choice')) as
|
||||
|
||||
set optimizer_search_depth=@tmp_osd;
|
||||
set optimizer_trace=@tmp_os;
|
||||
set optimizer_join_limit_pref_ratio=default;
|
||||
drop table t1, t10, t11;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-35072: Assertion failure with optimizer_join_limit_pref_ratio and 1-table select
|
||||
--echo #
|
||||
SET optimizer_join_limit_pref_ratio=1;
|
||||
CREATE TABLE t1 (c1 INT, INDEX(c1));
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
SELECT * FROM t1 ORDER BY c1 LIMIT 1;
|
||||
DROP TABLE t1;
|
||||
|
||||
set optimizer_join_limit_pref_ratio=default;
|
||||
|
@ -11626,6 +11626,8 @@ double recompute_join_cost_with_limit(const JOIN *join, bool skip_sorting,
|
||||
POSITION *pos= join->best_positions + join->const_tables;
|
||||
/*
|
||||
Generally, we assume that producing X% of output takes X% of the cost.
|
||||
(Note: before 11.0, we subtracted COST_EPS here. In 11.0+, there's no need
|
||||
to do this)
|
||||
*/
|
||||
double partial_join_cost= join->best_read * fraction;
|
||||
|
||||
@ -11646,10 +11648,11 @@ double recompute_join_cost_with_limit(const JOIN *join, bool skip_sorting,
|
||||
{
|
||||
/*
|
||||
Subtract the remainder of the first table's cost we had in
|
||||
join->best_read:
|
||||
join->best_read.
|
||||
(Before 11.0, we also subtracted pos->records_read/TIME_FOR_COMPARE.
|
||||
In 11.0+, that time is already included in pos->read_time)
|
||||
*/
|
||||
partial_join_cost -= pos->read_time*fraction;
|
||||
partial_join_cost -= pos->records_read*fraction * WHERE_COST_THD(join->thd);
|
||||
|
||||
/* Add the cost of the new access method we've got: */
|
||||
partial_join_cost= COST_ADD(partial_join_cost, *first_table_cost);
|
||||
@ -11666,12 +11669,7 @@ double recompute_join_cost_with_limit(const JOIN *join, bool skip_sorting,
|
||||
table. Do the same for costs of checking the WHERE.
|
||||
*/
|
||||
double extra_first_table_cost= pos->read_time * (1.0 - fraction);
|
||||
double extra_first_table_where= pos->records_read * (1.0 - fraction) *
|
||||
WHERE_COST_THD(join->thd);
|
||||
|
||||
partial_join_cost= COST_ADD(partial_join_cost,
|
||||
COST_ADD(extra_first_table_cost,
|
||||
extra_first_table_where));
|
||||
partial_join_cost= COST_ADD(partial_join_cost, extra_first_table_cost);
|
||||
}
|
||||
return partial_join_cost;
|
||||
}
|
||||
|
Reference in New Issue
Block a user