mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Optimizer trace: print cost and #rows of the join prefix
The names rows_for_plan and cost_for_plan follow MySQL Also added post-join-operation selectivity cost
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -508,4 +508,31 @@ SET optimizer_trace = 'enabled=on';
|
|||||||
DELETE FROM t1 WHERE f = 'x';
|
DELETE FROM t1 WHERE f = 'x';
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # Print cost_for_plan and rows_for_plan for join prefix
|
||||||
|
--echo #
|
||||||
|
create table t0(a int);
|
||||||
|
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
||||||
|
create table one_k (a int, b int, key(b));
|
||||||
|
insert into one_k select A.a + B.a*10 + C.a*100, A.a + B.a*10 + C.a*100 from t0 A, t0 B, t0 C;
|
||||||
|
|
||||||
|
analyze table t0, one_k persistent for all;
|
||||||
|
|
||||||
|
set @tmp_jcl=@@join_cache_level;
|
||||||
|
set join_cache_level=0;
|
||||||
|
set optimizer_trace=1;
|
||||||
|
|
||||||
|
--echo # Check cost/row numbers when multiple tables are joined
|
||||||
|
--echo # (cost_for_plan is the same as best_access_path.cost for single-table SELECTs
|
||||||
|
--echo # but for joins using condition selectivity it is not as trivial. So,
|
||||||
|
--echo # now we are printing it)
|
||||||
|
explain select * from t0 A, one_k B where A.a<5 and B.a<800;
|
||||||
|
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
|
||||||
|
|
||||||
|
set join_cache_level=@tmp_jcl;
|
||||||
|
|
||||||
|
--echo # This shows post-join selectivity
|
||||||
|
explain select * from t0 A, one_k B where A.a=B.b and B.a<800;
|
||||||
|
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
|
||||||
|
|
||||||
set optimizer_trace='enabled=off';
|
set optimizer_trace='enabled=off';
|
||||||
|
@@ -213,7 +213,9 @@ explain select * from t1 where a=1 or b=1 {
|
|||||||
"chosen": true
|
"chosen": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"rows_for_plan": 2,
|
||||||
|
"cost_for_plan": 4.5484
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@@ -209,7 +209,9 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
|
|||||||
"cause": "cost"
|
"cause": "cost"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"rows_for_plan": 1,
|
||||||
|
"cost_for_plan": 2.2
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@@ -99,7 +99,9 @@ select * from db1.t1 {
|
|||||||
"chosen": true
|
"chosen": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"rows_for_plan": 3,
|
||||||
|
"cost_for_plan": 2.6051
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -210,7 +212,9 @@ select * from db1.v1 {
|
|||||||
"chosen": true
|
"chosen": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"rows_for_plan": 3,
|
||||||
|
"cost_for_plan": 2.6051
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@@ -9383,6 +9383,11 @@ best_extension_by_limited_search(JOIN *join,
|
|||||||
current_record_count /
|
current_record_count /
|
||||||
(double) TIME_FOR_COMPARE));
|
(double) TIME_FOR_COMPARE));
|
||||||
|
|
||||||
|
if (unlikely(thd->trace_started()))
|
||||||
|
{
|
||||||
|
trace_one_table.add("rows_for_plan", current_record_count);
|
||||||
|
trace_one_table.add("cost_for_plan", current_read_time);
|
||||||
|
}
|
||||||
advance_sj_state(join, remaining_tables, idx, ¤t_record_count,
|
advance_sj_state(join, remaining_tables, idx, ¤t_record_count,
|
||||||
¤t_read_time, &loose_scan_pos);
|
¤t_read_time, &loose_scan_pos);
|
||||||
|
|
||||||
@@ -9441,6 +9446,10 @@ best_extension_by_limited_search(JOIN *join,
|
|||||||
remaining_tables &
|
remaining_tables &
|
||||||
~real_table_bit);
|
~real_table_bit);
|
||||||
join->positions[idx].cond_selectivity= pushdown_cond_selectivity;
|
join->positions[idx].cond_selectivity= pushdown_cond_selectivity;
|
||||||
|
|
||||||
|
if (unlikely(thd->trace_started()) && pushdown_cond_selectivity < 1.0)
|
||||||
|
trace_one_table.add("selectivity", pushdown_cond_selectivity);
|
||||||
|
|
||||||
double partial_join_cardinality= current_record_count *
|
double partial_join_cardinality= current_record_count *
|
||||||
pushdown_cond_selectivity;
|
pushdown_cond_selectivity;
|
||||||
if ( (search_depth > 1) && (remaining_tables & ~real_table_bit) & allowed_tables )
|
if ( (search_depth > 1) && (remaining_tables & ~real_table_bit) & allowed_tables )
|
||||||
|
Reference in New Issue
Block a user