Skip to content

Commit 3109d99

Browse files
committed
MDEV-36323: Split Materialized code: last_refills is never set in 11.0+
SplM_opt_info::last_refills is never set, so remove it. It was used in In JOIN_TAB::choose_best_splitting(), use local variable "refills" there, instead. The logic in the function is that we compute startup_cost= refills * spl_plan->cost; only when we have a splitting query plan which implies "refills" was set accordingly. Also - Added a comment about what "refills" is. - Updated derived_cond_pushdown.result: the change makes the Split-Materialized plans more expensive, so the join order changes from t3, <split-materialized(outer_ref)> to <split-materialized>, t3
1 parent 6521b41 commit 3109d99

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

mysql-test/main/derived_cond_pushdown.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22725,8 +22725,8 @@ where dt.a=t1.a and t3.a < 3
2272522725
from t1 limit 5;
2272622726
id select_type table type possible_keys key key_len ref rows Extra
2272722727
1 PRIMARY t1 ALL NULL NULL NULL NULL 1000
22728+
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where
2272822729
2 DEPENDENT SUBQUERY <derived3> ref key0 key0 5 test.t1.a 1
22729-
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
2273022730
3 LATERAL DERIVED t2 ref a a 5 test.t1.a 10
2273122731
select
2273222732
a,

sql/opt_split.cc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ class SplM_opt_info : public Sql_alloc
291291
double unsplit_oper_cost;
292292
/* Cardinality of T when nothing is pushed */
293293
double unsplit_card;
294-
double last_refills;
295294

296295
SplM_plan_info *find_plan(TABLE *table, uint key, uint parts);
297296
};
@@ -1056,6 +1055,25 @@ SplM_plan_info * JOIN_TAB::choose_best_splitting(uint idx,
10561055
if (best_table)
10571056
{
10581057
*spl_pd_boundary= this->table->map;
1058+
/*
1059+
Compute "refills" - how many times we'll need to refill the split-
1060+
materialized temp. table. Split-materialized table has references to
1061+
preceding table(s). Suppose the join prefix is (t1, t2, t3) and
1062+
split-materialized refers to table t2:
1063+
1064+
t1 t2 t3 <split_materialized>
1065+
^ |
1066+
+------------ +
1067+
1068+
If we do not use join buffer for table t3, then we'll need to refill
1069+
the split-materialized table partial_join_cardinality({t1, t2}) times.
1070+
(this assumes that fanout of table t3 is greater than 1, which is
1071+
typically true).
1072+
If table t3 uses join buffer, then every time we get a record combination
1073+
of {t1.row,t2.row,t3.row} the t2.row may be different and so we will need
1074+
to refill <split_materialized> every time, that is,
1075+
partial_join_cardinality(t1,t3,t3) times.
1076+
*/
10591077
if (!best_param_tables)
10601078
refills= 1;
10611079
else
@@ -1176,7 +1194,7 @@ SplM_plan_info * JOIN_TAB::choose_best_splitting(uint idx,
11761194
The best plan that employs splitting is cheaper than
11771195
the plan without splitting
11781196
*/
1179-
startup_cost= spl_opt_info->last_refills * spl_plan->cost;
1197+
startup_cost= refills * spl_plan->cost;
11801198
records= (ha_rows) (spl_opt_info->unsplit_card * spl_plan->split_sel);
11811199
if (unlikely(thd->trace_started()) && ! already_printed)
11821200
{

0 commit comments

Comments
 (0)