Commit b3c470a3 authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-23646: Optimizer trace: optimize_cond() should show ON expression processing

Print the build_equal_items() step for ON expression processing
parent b9a45ba4
...@@ -2319,6 +2319,13 @@ select t1.a from t1 left join t2 on t1.a=t2.a { ...@@ -2319,6 +2319,13 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
"join_optimization": { "join_optimization": {
"select_id": 1, "select_id": 1,
"steps": [ "steps": [
{
"build_equal_items": {
"condition": "ON expr",
"attached_to": "t2",
"resulting_condition": "multiple equal(t1.a, t2.a)"
}
},
{ {
"table_dependencies": [ "table_dependencies": [
{ {
...@@ -2449,6 +2456,13 @@ explain select * from t1 left join t2 on t2.a=t1.a { ...@@ -2449,6 +2456,13 @@ explain select * from t1 left join t2 on t2.a=t1.a {
"join_optimization": { "join_optimization": {
"select_id": 1, "select_id": 1,
"steps": [ "steps": [
{
"build_equal_items": {
"condition": "ON expr",
"attached_to": "t2",
"resulting_condition": "multiple equal(t2.a, t1.a)"
}
},
{ {
"table_dependencies": [ "table_dependencies": [
{ {
...@@ -2621,6 +2635,13 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and ...@@ -2621,6 +2635,13 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
"join_optimization": { "join_optimization": {
"select_id": 1, "select_id": 1,
"steps": [ "steps": [
{
"build_equal_items": {
"condition": "ON expr",
"attached_to": "t3",
"resulting_condition": "multiple equal(t2.a, t1.a, t3.a) and multiple equal(t2.b, t3.b)"
}
},
{ {
"table_dependencies": [ "table_dependencies": [
{ {
...@@ -9007,5 +9028,46 @@ json_detailed(json_extract(trace, '$**.substitute_best_equal')) ...@@ -9007,5 +9028,46 @@ json_detailed(json_extract(trace, '$**.substitute_best_equal'))
"resulting_condition": "t2.a = t1.a and t3.a = t1.a and t1.a + t1.a < 1000" "resulting_condition": "t2.a = t1.a and t3.a = t1.a and t1.a + t1.a < 1000"
} }
] ]
# The next query is test for:
# MDEV-23646: Optimizer trace: optimize_cond() should show ON expression processing
select
json_detailed(json_extract(trace, '$**.condition_processing'))
from
information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.condition_processing'))
[
{
"condition": "WHERE",
"original_condition": "t1.b > 5555",
"steps":
[
{
"build_equal_items":
{
"condition": "ON expr",
"attached_to": "t3",
"resulting_condition": "t3.a + t2.a < 1000 and multiple equal(t2.a, t1.a, t3.a)"
}
},
{
"transformation": "equality_propagation",
"resulting_condition": "t1.b > 5555"
},
{
"transformation": "constant_propagation",
"resulting_condition": "t1.b > 5555"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "t1.b > 5555"
}
]
}
]
drop table t1,t2,t3; drop table t1,t2,t3;
set optimizer_trace='enabled=off'; set optimizer_trace='enabled=off';
...@@ -773,11 +773,19 @@ select ...@@ -773,11 +773,19 @@ select
from t1 left join (t2,t3) on t2.a=t1.a and t3.a=t2.a and t3.a + t2.a <1000 from t1 left join (t2,t3) on t2.a=t1.a and t3.a=t2.a and t3.a + t2.a <1000
where where
t1.b > 5555; t1.b > 5555;
select select
json_detailed(json_extract(trace, '$**.substitute_best_equal')) json_detailed(json_extract(trace, '$**.substitute_best_equal'))
from from
information_schema.optimizer_trace; information_schema.optimizer_trace;
--echo # The next query is test for:
--echo # MDEV-23646: Optimizer trace: optimize_cond() should show ON expression processing
select
json_detailed(json_extract(trace, '$**.condition_processing'))
from
information_schema.optimizer_trace;
drop table t1,t2,t3; drop table t1,t2,t3;
set optimizer_trace='enabled=off'; set optimizer_trace='enabled=off';
...@@ -15488,6 +15488,16 @@ static COND *build_equal_items(JOIN *join, COND *cond, ...@@ -15488,6 +15488,16 @@ static COND *build_equal_items(JOIN *join, COND *cond,
table->on_expr= build_equal_items(join, table->on_expr, inherited, table->on_expr= build_equal_items(join, table->on_expr, inherited,
nested_join_list, ignore_on_conds, nested_join_list, ignore_on_conds,
&table->cond_equal); &table->cond_equal);
if (unlikely(join->thd->trace_started()))
{
const char *table_name;
if (table->nested_join)
table_name= table->nested_join->join_list.head()->alias.str;
else
table_name= table->alias.str;
trace_condition(join->thd, "ON expr", "build_equal_items",
table->on_expr, table_name);
}
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment