Skip to content

Commit 46c4fd4

Browse files
montywispetrunia
authored andcommitted
Fixed cost calculation for SELECT STRAIGHT_JOIN
Main fix was replacing read_time+= with read_time I also did updated the 'identical' code in optimize_straight_join) and best_extension_by_limited_search() to make them eaiser to compare. Reviewer: Sergei Petrunia <sergey@mariadb.com>
1 parent e240e8d commit 46c4fd4

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

sql/sql_select.cc

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8942,7 +8942,7 @@ determine_search_depth(JOIN *join)
89428942
*/
89438943

89448944
static void
8945-
optimize_straight_join(JOIN *join, table_map join_tables)
8945+
optimize_straight_join(JOIN *join, table_map remaining_tables)
89468946
{
89478947
JOIN_TAB *s;
89488948
uint idx= join->const_tables;
@@ -8960,30 +8960,32 @@ optimize_straight_join(JOIN *join, table_map join_tables)
89608960
Json_writer_object trace_one_table(thd);
89618961
if (unlikely(thd->trace_started()))
89628962
{
8963-
trace_plan_prefix(join, idx, join_tables);
8963+
trace_plan_prefix(join, idx, remaining_tables);
89648964
trace_one_table.add_table_name(s);
89658965
}
89668966
/* Find the best access method from 's' to the current partial plan */
8967-
best_access_path(join, s, join_tables, join->positions, idx,
8967+
best_access_path(join, s, remaining_tables, join->positions, idx,
89688968
disable_jbuf, record_count,
89698969
position, &loose_scan_pos);
89708970

8971-
/* compute the cost of the new plan extended with 's' */
8971+
/* Compute the cost of the new plan extended with 's' */
89728972
record_count= COST_MULT(record_count, position->records_read);
89738973
const double filter_cmp_gain= position->range_rowid_filter_info
89748974
? position->range_rowid_filter_info->get_cmp_gain(record_count)
89758975
: 0;
8976-
read_time+= COST_ADD(read_time - filter_cmp_gain,
8977-
COST_ADD(position->read_time,
8978-
record_count / TIME_FOR_COMPARE));
8979-
advance_sj_state(join, join_tables, idx, &record_count, &read_time,
8976+
read_time= COST_ADD(read_time,
8977+
COST_ADD(position->read_time -
8978+
filter_cmp_gain,
8979+
record_count /
8980+
TIME_FOR_COMPARE));
8981+
advance_sj_state(join, remaining_tables, idx, &record_count, &read_time,
89808982
&loose_scan_pos);
89818983

8982-
join_tables&= ~(s->table->map);
8984+
remaining_tables&= ~(s->table->map);
89838985
double pushdown_cond_selectivity= 1.0;
89848986
if (use_cond_selectivity > 1)
89858987
pushdown_cond_selectivity= table_cond_selectivity(join, idx, s,
8986-
join_tables);
8988+
remaining_tables);
89878989
position->cond_selectivity= pushdown_cond_selectivity;
89888990
++idx;
89898991
}
@@ -9965,16 +9967,16 @@ best_extension_by_limited_search(JOIN *join,
99659967
best_access_path(join, s, remaining_tables, join->positions, idx,
99669968
disable_jbuf, record_count, position, &loose_scan_pos);
99679969

9968-
/* Compute the cost of extending the plan with 's' */
9970+
/* Compute the cost of the new plan extended with 's' */
99699971
current_record_count= COST_MULT(record_count, position->records_read);
99709972
const double filter_cmp_gain= position->range_rowid_filter_info
99719973
? position->range_rowid_filter_info->get_cmp_gain(current_record_count)
99729974
: 0;
9973-
current_read_time=COST_ADD(read_time,
9974-
COST_ADD(position->read_time -
9975-
filter_cmp_gain,
9976-
current_record_count /
9977-
TIME_FOR_COMPARE));
9975+
current_read_time= COST_ADD(read_time,
9976+
COST_ADD(position->read_time -
9977+
filter_cmp_gain,
9978+
current_record_count /
9979+
TIME_FOR_COMPARE));
99789980

99799981
if (unlikely(thd->trace_started()))
99809982
{

0 commit comments

Comments
 (0)