Commit 07f21cfb authored by Rex's avatar Rex Committed by Sergei Petrunia

MDEV-21092,MDEV-21095,MDEV-29997: Optimizer Trace for index condition...

MDEV-21092,MDEV-21095,MDEV-29997: Optimizer Trace for index condition pushdown, partition pruning, exists-to-in

        Add Optimizer Tracing for:
        - Index Condition Pushdown
        - Partition Pruning
        - Exists-to-IN optimization
parent dba78f3c
...@@ -177,15 +177,23 @@ select * from v1 { ...@@ -177,15 +177,23 @@ select * from v1 {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": "t1.a = 1"
"table": "t1", }
"attached": "t1.a = 1" ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a = 1"
} }
] ]
} }
...@@ -345,15 +353,23 @@ select * from (select * from t1 where t1.a=1)q { ...@@ -345,15 +353,23 @@ select * from (select * from t1 where t1.a=1)q {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": "t1.a = 1"
"table": "t1", }
"attached": "t1.a = 1" ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a = 1"
} }
] ]
} }
...@@ -520,15 +536,12 @@ select * from v2 { ...@@ -520,15 +536,12 @@ select * from v2 {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": "t1.a = 1"
"table": "t1", }
"attached": "t1.a = 1" ]
}
]
}
} }
] ]
} }
...@@ -602,15 +615,23 @@ select * from v2 { ...@@ -602,15 +615,23 @@ select * from v2 {
"cost": 0.012418701 "cost": 0.012418701
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "<derived2>",
{ "index_condition": null
"table": "<derived2>", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "<derived2>",
"attached_condition": null
} }
] ]
} }
...@@ -619,6 +640,17 @@ select * from v2 { ...@@ -619,6 +640,17 @@ select * from v2 {
"join_execution": { "join_execution": {
"select_id": 1, "select_id": 1,
"steps": [ "steps": [
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a = 1"
}
]
}
},
{ {
"join_execution": { "join_execution": {
"select_id": 2, "select_id": 2,
...@@ -756,15 +788,23 @@ explain select * from v2 { ...@@ -756,15 +788,23 @@ explain select * from v2 {
"cost": 0.01159965 "cost": 0.01159965
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t2",
{ "index_condition": null
"table": "t2", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t2",
"attached_condition": null
} }
] ]
} }
...@@ -891,15 +931,12 @@ explain select * from v1 { ...@@ -891,15 +931,12 @@ explain select * from v1 {
"cost": 0.017968034 "cost": 0.017968034
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
}
]
}
} }
] ]
} }
...@@ -973,15 +1010,23 @@ explain select * from v1 { ...@@ -973,15 +1010,23 @@ explain select * from v1 {
"cost": 0.012757506 "cost": 0.012757506
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "<derived2>",
{ "index_condition": null
"table": "<derived2>", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "<derived2>",
"attached_condition": null
} }
] ]
} }
...@@ -990,6 +1035,17 @@ explain select * from v1 { ...@@ -990,6 +1035,17 @@ explain select * from v1 {
"join_execution": { "join_execution": {
"select_id": 1, "select_id": 1,
"steps": [ "steps": [
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{ {
"join_execution": { "join_execution": {
"select_id": 2, "select_id": 2,
...@@ -1300,19 +1356,31 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { ...@@ -1300,19 +1356,31 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": "t1.b is not null"
"table": "t1", },
"attached": "t1.b is not null" {
}, "table": "t2",
{ "index_condition": "t1.a = t2.b + 2"
"table": "t2", }
"attached": "t1.a = t2.b + 2" ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.b is not null"
},
{
"table": "t2",
"attached_condition": "t1.a = t2.b + 2"
} }
] ]
} }
...@@ -1483,15 +1551,23 @@ EXPLAIN SELECT DISTINCT a FROM t1 { ...@@ -1483,15 +1551,23 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
"cost": 0.004191135 "cost": 0.004191135
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
} }
] ]
} }
...@@ -1704,15 +1780,12 @@ set statement optimizer_scan_setup_cost=0 for EXPLAIN SELECT MIN(d) FROM t1 wher ...@@ -1704,15 +1780,12 @@ set statement optimizer_scan_setup_cost=0 for EXPLAIN SELECT MIN(d) FROM t1 wher
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": "t1.b = 2 and t1.c = 3"
"table": "t1", }
"attached": "t1.b = 2 and t1.c = 3" ]
}
]
}
}, },
{ {
"reconsidering_access_paths_for_index_ordering": { "reconsidering_access_paths_for_index_ordering": {
...@@ -1739,6 +1812,17 @@ set statement optimizer_scan_setup_cost=0 for EXPLAIN SELECT MIN(d) FROM t1 wher ...@@ -1739,6 +1812,17 @@ set statement optimizer_scan_setup_cost=0 for EXPLAIN SELECT MIN(d) FROM t1 wher
] ]
} }
}, },
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.b = 2 and t1.c = 3"
}
]
}
},
{ {
"join_execution": { "join_execution": {
"select_id": 1, "select_id": 1,
...@@ -1940,15 +2024,23 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id { ...@@ -1940,15 +2024,23 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": "t1.a >= 20010104e0"
"table": "t1", }
"attached": "t1.a >= 20010104e0" ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a >= 20010104e0"
} }
] ]
} }
...@@ -2143,15 +2235,23 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id { ...@@ -2143,15 +2235,23 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": "t1.a = 20010104e0"
"table": "t1", }
"attached": "t1.a = 20010104e0" ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a = 20010104e0"
} }
] ]
} }
...@@ -2442,15 +2542,12 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { ...@@ -2442,15 +2542,12 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
}
]
}
}, },
{ {
"reconsidering_access_paths_for_index_ordering": { "reconsidering_access_paths_for_index_ordering": {
...@@ -2548,6 +2645,17 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { ...@@ -2548,6 +2645,17 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
] ]
} }
}, },
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a <=> 1 and t1.b <=> 2"
}
]
}
},
{ {
"join_execution": { "join_execution": {
"select_id": 1, "select_id": 1,
...@@ -2716,15 +2824,23 @@ select t1.a from t1 left join t2 on t1.a=t2.a { ...@@ -2716,15 +2824,23 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
"computing_condition": [] "computing_condition": []
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
} }
] ]
} }
...@@ -2923,19 +3039,31 @@ explain select * from t1 left join t2 on t2.a=t1.a { ...@@ -2923,19 +3039,31 @@ explain select * from t1 left join t2 on t2.a=t1.a {
"computing_condition": [] "computing_condition": []
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", },
"attached": null {
}, "table": "t2",
{ "index_condition": "trigcond(trigcond(t1.a is not null))"
"table": "t2", }
"attached": "trigcond(trigcond(t1.a is not null))" ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
},
{
"table": "t2",
"attached_condition": "trigcond(trigcond(t1.a is not null))"
} }
] ]
} }
...@@ -3115,15 +3243,23 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and ...@@ -3115,15 +3243,23 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
"computing_condition": [] "computing_condition": []
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
} }
] ]
} }
...@@ -3514,19 +3650,31 @@ explain extended select * from t1 where a in (select p from t2) { ...@@ -3514,19 +3650,31 @@ explain extended select * from t1 where a in (select p from t2) {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", },
"attached": null {
}, "table": "t2",
{ "index_condition": "t2.p = t1.a"
"table": "t2", }
"attached": "t2.p = t1.a" ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
},
{
"table": "t2",
"attached_condition": "t2.p = t1.a"
} }
] ]
} }
...@@ -3890,15 +4038,23 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { ...@@ -3890,15 +4038,23 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
} }
] ]
} }
...@@ -4028,15 +4184,23 @@ select f1(a) from t1 { ...@@ -4028,15 +4184,23 @@ select f1(a) from t1 {
"cost": 0.01066122 "cost": 0.01066122
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
} }
] ]
} }
...@@ -4142,15 +4306,23 @@ select f2(a) from t1 { ...@@ -4142,15 +4306,23 @@ select f2(a) from t1 {
"cost": 0.01066122 "cost": 0.01066122
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
} }
] ]
} }
...@@ -4180,7 +4352,7 @@ a ...@@ -4180,7 +4352,7 @@ a
2 2
select length(trace) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; select length(trace) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
length(trace) length(trace)
2747 2869
set optimizer_trace_max_mem_size=100; set optimizer_trace_max_mem_size=100;
select * from t1; select * from t1;
a a
...@@ -4194,7 +4366,7 @@ select * from t1 { ...@@ -4194,7 +4366,7 @@ select * from t1 {
"join_preparation": { "join_preparation": {
"select_id": 1, "select_id": 1,
"steps": [ "steps": [
2647 0 2769 0
set optimizer_trace_max_mem_size=0; set optimizer_trace_max_mem_size=0;
select * from t1; select * from t1;
a a
...@@ -4202,7 +4374,7 @@ a ...@@ -4202,7 +4374,7 @@ a
2 2
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
select * from t1 2747 0 select * from t1 2869 0
drop table t1; drop table t1;
set optimizer_trace='enabled=off'; set optimizer_trace='enabled=off';
set @@optimizer_trace_max_mem_size= @save_optimizer_trace_max_mem_size; set @@optimizer_trace_max_mem_size= @save_optimizer_trace_max_mem_size;
...@@ -4671,19 +4843,31 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { ...@@ -4671,19 +4843,31 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t0",
{ "index_condition": "t0.a < 3 and t0.a is not null"
"table": "t0", },
"attached": "t0.a < 3 and t0.a is not null" {
}, "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t0",
"attached_condition": "t0.a < 3 and t0.a is not null"
},
{
"table": "t1",
"attached_condition": null
} }
] ]
} }
...@@ -4824,15 +5008,12 @@ explain select * from (select rand() from t1)q { ...@@ -4824,15 +5008,12 @@ explain select * from (select rand() from t1)q {
"cost": 0.010504815 "cost": 0.010504815
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
}
]
}
} }
] ]
} }
...@@ -4906,15 +5087,23 @@ explain select * from (select rand() from t1)q { ...@@ -4906,15 +5087,23 @@ explain select * from (select rand() from t1)q {
"cost": 0.012461052 "cost": 0.012461052
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "<derived2>",
{ "index_condition": null
"table": "<derived2>", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "<derived2>",
"attached_condition": null
} }
] ]
} }
...@@ -4923,6 +5112,17 @@ explain select * from (select rand() from t1)q { ...@@ -4923,6 +5112,17 @@ explain select * from (select rand() from t1)q {
"join_execution": { "join_execution": {
"select_id": 1, "select_id": 1,
"steps": [ "steps": [
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{ {
"join_execution": { "join_execution": {
"select_id": 2, "select_id": 2,
...@@ -5484,27 +5684,47 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_ ...@@ -5484,27 +5684,47 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
"computing_condition": [] "computing_condition": []
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", },
"attached": null {
}, "table": "<subquery2>",
{ "index_condition": "t1.a = `sj-materialize`.a"
"table": "t_inner_1", },
"attached": null {
}, "table": "t_inner_1",
{ "index_condition": null
"table": "t_inner_2", },
"attached": null {
}, "table": "t_inner_2",
{ "index_condition": null
"table": "<subquery2>", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
},
{
"table": "t_inner_1",
"attached_condition": null
},
{
"table": "t_inner_2",
"attached_condition": null
},
{
"table": "<subquery2>",
"attached_condition": "t1.a = `sj-materialize`.a"
} }
] ]
} }
...@@ -7829,41 +8049,69 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ...@@ -7829,41 +8049,69 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"cost": 0.540166532 "cost": 0.540166532
}, },
{ {
"substitute_best_equal": { "substitute_best_equal": {
"condition": "WHERE", "condition": "WHERE",
"resulting_condition": "t_inner_1.a = t_outer_1.a and t_inner_3.a = t_outer_2.a" "resulting_condition": "t_inner_1.a = t_outer_1.a and t_inner_3.a = t_outer_2.a"
} }
},
{
"make_join_readinfo": [
{
"table": "t_outer_1",
"index_condition": null
},
{
"table": "t_inner_1",
"index_condition": "t_inner_1.a = t_outer_1.a"
},
{
"table": "t_inner_2",
"index_condition": null
},
{
"table": "t_inner_4",
"index_condition": null
},
{
"table": "t_outer_2",
"index_condition": null
},
{
"table": "t_inner_3",
"index_condition": "t_inner_3.a = t_outer_2.a"
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t_outer_1",
"attached_condition": null
},
{
"table": "t_inner_1",
"attached_condition": "t_inner_1.a = t_outer_1.a"
},
{
"table": "t_inner_2",
"attached_condition": null
},
{
"table": "t_inner_4",
"attached_condition": null
},
{
"table": "t_outer_2",
"attached_condition": null
}, },
{ {
"attaching_conditions_to_tables": { "table": "t_inner_3",
"attached_conditions_computation": [], "attached_condition": "t_inner_3.a = t_outer_2.a"
"attached_conditions_summary": [
{
"table": "t_outer_1",
"attached": null
},
{
"table": "t_inner_1",
"attached": "t_inner_1.a = t_outer_1.a"
},
{
"table": "t_inner_2",
"attached": null
},
{
"table": "t_inner_4",
"attached": null
},
{
"table": "t_outer_2",
"attached": null
},
{
"table": "t_inner_3",
"attached": "t_inner_3.a = t_outer_2.a"
}
]
}
} }
] ]
} }
...@@ -10212,43 +10460,79 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ...@@ -10212,43 +10460,79 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
"computing_condition": [] "computing_condition": []
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t_outer_1",
{ "index_condition": null
"table": "t_outer_1", },
"attached": null {
}, "table": "<subquery2>",
{ "index_condition": "t_outer_1.a = `sj-materialize`.a"
"table": "t_inner_1", },
"attached": null {
}, "table": "t_inner_1",
{ "index_condition": null
"table": "t_inner_2", },
"attached": null {
}, "table": "t_inner_2",
{ "index_condition": null
"table": "<subquery2>", },
"attached": null {
}, "table": "t_outer_2",
{ "index_condition": null
"table": "t_outer_2", },
"attached": null {
}, "table": "<subquery3>",
{ "index_condition": "t_outer_2.a = `sj-materialize`.a"
"table": "t_inner_4", },
"attached": null {
}, "table": "t_inner_4",
{ "index_condition": null
"table": "t_inner_3", },
"attached": null {
}, "table": "t_inner_3",
{ "index_condition": null
"table": "<subquery3>", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t_outer_1",
"attached_condition": null
},
{
"table": "t_inner_1",
"attached_condition": null
},
{
"table": "t_inner_2",
"attached_condition": null
},
{
"table": "<subquery2>",
"attached_condition": "t_outer_1.a = `sj-materialize`.a"
},
{
"table": "t_outer_2",
"attached_condition": null
},
{
"table": "t_inner_4",
"attached_condition": null
},
{
"table": "t_inner_3",
"attached_condition": null
},
{
"table": "<subquery3>",
"attached_condition": "t_outer_2.a = `sj-materialize`.a"
} }
] ]
} }
...@@ -11478,6 +11762,12 @@ SELECT 'a\0' LIMIT 0 { ...@@ -11478,6 +11762,12 @@ SELECT 'a\0' LIMIT 0 {
"steps": [] "steps": []
} }
}, },
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": []
}
},
{ {
"join_execution": { "join_execution": {
"select_id": 1, "select_id": 1,
...@@ -11593,15 +11883,23 @@ select count(*) from seq_1_to_10000000 { ...@@ -11593,15 +11883,23 @@ select count(*) from seq_1_to_10000000 {
"cost": 444.7880673 "cost": 444.7880673
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "seq_1_to_10000000",
{ "index_condition": null
"table": "seq_1_to_10000000", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "seq_1_to_10000000",
"attached_condition": null
} }
] ]
} }
...@@ -12339,15 +12637,24 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 { ...@@ -12339,15 +12637,24 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": "t1.b between 10 and 50 and t1.c < 10"
"table": "t1", }
"attached": "t1.a < 10 and t1.b between 10 and 50 and t1.c < 10" ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.b between 10 and 50 and t1.c < 10",
"index_condition": "t1.a < 10"
} }
] ]
} }
...@@ -12751,68 +13058,79 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and ...@@ -12751,68 +13058,79 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
} }
}, },
{ {
"attaching_conditions_to_tables": { "table": "t1",
"attached_conditions_computation": [ "range_analysis": {
{ "table_scan": {
"table": "t1", "rows": 10000,
"range_analysis": { "cost": 1.581538
"table_scan": { },
"rows": 10000, "potential_range_indexes": [
"cost": 1.581538
},
"potential_range_indexes": [
{
"index": "a",
"usable": true,
"key_parts": ["a"]
},
{
"index": "b",
"usable": true,
"key_parts": ["b"]
}
],
"setup_range_conditions": [],
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "a"
},
{
"index": "b",
"ranges": ["(NULL) < (b) < (5000)"],
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 4312,
"cost": 5.325058827,
"chosen": false,
"cause": "cost"
}
],
"analyzing_roworder_intersect": {
"cause": "too few roworder scans"
},
"analyzing_index_merge_union": []
},
"group_index_range": {
"chosen": false,
"cause": "not single_table"
}
}
}
],
"attached_conditions_summary": [
{ {
"table": "three", "index": "a",
"attached": null "usable": true,
"key_parts": ["a"]
}, },
{ {
"table": "t1", "index": "b",
"attached": "t1.a = three.a and t1.b < 5000 and t1.c < 1000" "usable": true,
"key_parts": ["b"]
} }
] ],
"setup_range_conditions": [],
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "a"
},
{
"index": "b",
"ranges": ["(NULL) < (b) < (5000)"],
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 4312,
"cost": 5.325058827,
"chosen": false,
"cause": "cost"
}
],
"analyzing_roworder_intersect": {
"cause": "too few roworder scans"
},
"analyzing_index_merge_union": []
},
"group_index_range": {
"chosen": false,
"cause": "not single_table"
}
} }
},
{
"make_join_readinfo": [
{
"table": "three",
"index_condition": null
},
{
"table": "t1",
"index_condition": "t1.a = three.a and t1.b < 5000 and t1.c < 1000"
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "three",
"attached_condition": null
},
{
"table": "t1",
"attached_condition": "t1.a = three.a"
} }
] ]
} }
...@@ -12826,6 +13144,127 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and ...@@ -12826,6 +13144,127 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
] ]
} 0 0 } 0 0
drop table three, t1; drop table three, t1;
#
# MDEV-21095: Index condition push down is not reflected in optimizer trace
#
create table t10 (a int, b int, c int, key(a,b));
insert into t10 select seq, seq, seq from seq_1_to_10000;
explain format=json select * from t10 where a<3 and b!=5 and c<10;
EXPLAIN
{
"query_block": {
"select_id": 1,
"cost": 0.003717837,
"nested_loop": [
{
"table": {
"table_name": "t10",
"access_type": "range",
"possible_keys": ["a"],
"key": "a",
"key_length": "5",
"used_key_parts": ["a"],
"loops": 1,
"rows": 2,
"cost": 0.003717837,
"filtered": 100,
"index_condition": "t10.a < 3 and t10.b <> 5",
"attached_condition": "t10.c < 10"
}
}
]
}
}
set optimizer_trace='enabled=on';
select * from t10 where a<3 and b!=5 and c<10;
a b c
1 1 1
2 2 2
select json_detailed(json_extract(trace, '$**.attaching_conditions_to_tables')) as out1 from information_schema.optimizer_trace;
out1
[
{
"attached_conditions_computation":
[],
"attached_conditions_summary":
[
{
"table": "t10",
"attached_condition": "t10.c < 10",
"index_condition": "t10.a < 3 and t10.b <> 5"
}
]
}
]
drop table t10;
#
# MDEV-21092: EXISTS to IN is not reflected in the optimizer trace
#
set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on';
set optimizer_trace='enabled=on';
create table t1 (cn_c int, cn_n char(10), cn_a int );
create table t2 (ci_p int, ci_c int );
create table t3 (ci_p int, ci_c int );
SELECT cn_n FROM t1 WHERE (EXISTS (select 1 from t2 where ci_p > 100000 and cn_c = ci_c)
OR (cn_n LIKE 'L%') )
AND cn_a > 1000000;
cn_n
select json_detailed(json_extract(trace, '$.steps[*].join_optimization[0].steps[0].transformation')) from information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$.steps[*].join_optimization[0].steps[0].transformation'))
[
{
"select_id": 2,
"from": "EXISTS (SELECT)",
"to": "IN (SELECT)",
"upper_not": false
}
]
drop table t1, t2, t3;
#
# MDEV-29997 Partition Pruning not included in optimizer tracing
#
create table t2 (a int, b int) partition by hash(a) partitions 10;
create table t3 (a int, b int) partition by hash(a) partitions 10;
INSERT INTO t2 SELECT seq, seq from seq_1_to_10;
INSERT INTO t3 SELECT seq, seq from seq_1_to_10;
set optimizer_trace='enabled=on';
explain partitions select * from t2,t3 where t2.a in (2,3,4) and t3.a in (4,5);
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t3 p4,p5 ALL NULL NULL NULL NULL 2 Using where
1 SIMPLE t2 p2,p3,p4 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
select json_detailed(json_extract(trace, '$**.prune_partitions')) from information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.prune_partitions'))
[
{
"table": "t2",
"used_partitions": "p2,p3,p4"
},
{
"table": "t3",
"used_partitions": "p4,p5"
}
]
drop table t2,t3;
create table t1 (
a int
) partition by range (a)
( partition p0 values less than(10),
partition p1 values less than (20),
partition p2 values less than (25)
);
insert into t1 values (5),(15),(22);
explain select * from t1 where a = 28;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
select json_detailed(json_extract(trace, '$**.prune_partitions')) from information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.prune_partitions'))
[
{
"table": "t1",
"used_partitions": ""
}
]
drop table t1;
set @@optimizer_switch= @save_optimizer_switch; set @@optimizer_switch= @save_optimizer_switch;
set @@use_stat_tables= @save_use_stat_tables; set @@use_stat_tables= @save_use_stat_tables;
set @@histogram_size= @save_histogram_size; set @@histogram_size= @save_histogram_size;
......
...@@ -932,7 +932,64 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and ...@@ -932,7 +932,64 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
drop table three, t1; drop table three, t1;
--echo #
--echo # MDEV-21095: Index condition push down is not reflected in optimizer trace
--echo #
create table t10 (a int, b int, c int, key(a,b));
insert into t10 select seq, seq, seq from seq_1_to_10000;
explain format=json select * from t10 where a<3 and b!=5 and c<10;
set optimizer_trace='enabled=on';
select * from t10 where a<3 and b!=5 and c<10;
select json_detailed(json_extract(trace, '$**.attaching_conditions_to_tables')) as out1 from information_schema.optimizer_trace;
drop table t10;
--echo #
--echo # MDEV-21092: EXISTS to IN is not reflected in the optimizer trace
--echo #
set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on';
set optimizer_trace='enabled=on';
create table t1 (cn_c int, cn_n char(10), cn_a int );
create table t2 (ci_p int, ci_c int );
create table t3 (ci_p int, ci_c int );
SELECT cn_n FROM t1 WHERE (EXISTS (select 1 from t2 where ci_p > 100000 and cn_c = ci_c)
OR (cn_n LIKE 'L%') )
AND cn_a > 1000000;
select json_detailed(json_extract(trace, '$.steps[*].join_optimization[0].steps[0].transformation')) from information_schema.optimizer_trace;
drop table t1, t2, t3;
--echo #
--echo # MDEV-29997 Partition Pruning not included in optimizer tracing
--echo #
--source include/have_partition.inc
create table t2 (a int, b int) partition by hash(a) partitions 10;
create table t3 (a int, b int) partition by hash(a) partitions 10;
INSERT INTO t2 SELECT seq, seq from seq_1_to_10;
INSERT INTO t3 SELECT seq, seq from seq_1_to_10;
set optimizer_trace='enabled=on';
explain partitions select * from t2,t3 where t2.a in (2,3,4) and t3.a in (4,5);
select json_detailed(json_extract(trace, '$**.prune_partitions')) from information_schema.optimizer_trace;
drop table t2,t3;
create table t1 (
a int
) partition by range (a)
( partition p0 values less than(10),
partition p1 values less than (20),
partition p2 values less than (25)
);
insert into t1 values (5),(15),(22);
explain select * from t1 where a = 28;
select json_detailed(json_extract(trace, '$**.prune_partitions')) from information_schema.optimizer_trace;
drop table t1;
set @@optimizer_switch= @save_optimizer_switch; set @@optimizer_switch= @save_optimizer_switch;
set @@use_stat_tables= @save_use_stat_tables; set @@use_stat_tables= @save_use_stat_tables;
set @@histogram_size= @save_histogram_size; set @@histogram_size= @save_histogram_size;
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
...@@ -257,15 +257,23 @@ explain select * from t1 where a=1 or b=1 { ...@@ -257,15 +257,23 @@ explain select * from t1 where a=1 or b=1 {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": "t1.a = 1 or t1.b = 1"
"table": "t1", }
"attached": "t1.a = 1 or t1.b = 1" ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a = 1 or t1.b = 1"
} }
] ]
} }
......
...@@ -256,15 +256,24 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { ...@@ -256,15 +256,24 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
} }
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": "t1.pk1 <> 0" ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null,
"index_condition": "t1.pk1 <> 0"
} }
] ]
} }
......
...@@ -133,15 +133,23 @@ select * from db1.t1 { ...@@ -133,15 +133,23 @@ select * from db1.t1 {
"cost": 0.010504815 "cost": 0.010504815
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
} }
] ]
} }
...@@ -272,15 +280,23 @@ select * from db1.v1 { ...@@ -272,15 +280,23 @@ select * from db1.v1 {
"cost": 0.010504815 "cost": 0.010504815
}, },
{ {
"attaching_conditions_to_tables": { "make_join_readinfo": [
"attached_conditions_computation": [], {
"attached_conditions_summary": [ "table": "t1",
{ "index_condition": null
"table": "t1", }
"attached": null ]
} }
] ]
} }
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
} }
] ]
} }
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
// RESOLVED_AGAINST_ALIAS, ... // RESOLVED_AGAINST_ALIAS, ...
#include "sql_expression_cache.h" #include "sql_expression_cache.h"
#include "sql_lex.h" // empty_clex_str #include "sql_lex.h" // empty_clex_str
#include "my_json_writer.h" // for dbug_print_opt_trace()
const String my_null_string("NULL", 4, default_charset_info); const String my_null_string("NULL", 4, default_charset_info);
const String my_default_string("DEFAULT", 7, default_charset_info); const String my_default_string("DEFAULT", 7, default_charset_info);
...@@ -10887,6 +10888,29 @@ const char *dbug_print_item(Item *item) ...@@ -10887,6 +10888,29 @@ const char *dbug_print_item(Item *item)
return "Couldn't fit into buffer"; return "Couldn't fit into buffer";
} }
/*
Return the optimizer trace collected so far for the current thread.
*/
const char *dbug_print_opt_trace()
{
if (current_thd)
{
if (current_thd->opt_trace.is_started())
{
String *s= const_cast<String *>(current_thd->opt_trace
.get_current_json()->output.get_string());
return s->c_ptr();
}
else
return "Trace empty";
}
else
return "No Thread";
}
const char *dbug_print_select(SELECT_LEX *sl) const char *dbug_print_select(SELECT_LEX *sl)
{ {
char *buf= dbug_item_print_buf; char *buf= dbug_item_print_buf;
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "sql_parse.h" // check_stack_overrun #include "sql_parse.h" // check_stack_overrun
#include "sql_cte.h" #include "sql_cte.h"
#include "sql_test.h" #include "sql_test.h"
#include "opt_trace.h"
double get_post_group_estimate(JOIN* join, double join_op_rows); double get_post_group_estimate(JOIN* join, double join_op_rows);
...@@ -3342,6 +3343,14 @@ bool Item_exists_subselect::exists2in_processor(void *opt_arg) ...@@ -3342,6 +3343,14 @@ bool Item_exists_subselect::exists2in_processor(void *opt_arg)
set possible optimization strategies set possible optimization strategies
*/ */
in_subs->emb_on_expr_nest= emb_on_expr_nest; in_subs->emb_on_expr_nest= emb_on_expr_nest;
{
OPT_TRACE_TRANSFORM(thd, trace_wrapper, trace_transform,
in_subs->get_select_lex()->select_number,
"EXISTS (SELECT)", "IN (SELECT)");
trace_transform.add( "upper_not", ( upper_not?true:false ) );
}
res= check_and_do_in_subquery_rewrites(join); res= check_and_do_in_subquery_rewrites(join);
first_select->join->prepare_stage2(); first_select->join->prepare_stage2();
......
...@@ -4198,6 +4198,20 @@ bool prune_partitions(THD *thd, TABLE *table, Item *pprune_cond) ...@@ -4198,6 +4198,20 @@ bool prune_partitions(THD *thd, TABLE *table, Item *pprune_cond)
table->all_partitions_pruned_away= true; table->all_partitions_pruned_away= true;
retval= TRUE; retval= TRUE;
} }
if (unlikely(thd->trace_started()))
{
String parts;
String_list parts_list;
make_used_partitions_str(thd->mem_root, prune_param.part_info, &parts,
parts_list);
Json_writer_object trace_wrapper(thd);
Json_writer_object trace_prune(thd, "prune_partitions");
trace_prune.add_table_name(table);
trace_prune.add("used_partitions", parts.c_ptr());
}
DBUG_RETURN(retval); DBUG_RETURN(retval);
} }
......
...@@ -349,6 +349,8 @@ static void fix_items_after_optimize(THD *thd, SELECT_LEX *select_lex); ...@@ -349,6 +349,8 @@ static void fix_items_after_optimize(THD *thd, SELECT_LEX *select_lex);
static void optimize_rownum(THD *thd, SELECT_LEX_UNIT *unit, Item *cond); static void optimize_rownum(THD *thd, SELECT_LEX_UNIT *unit, Item *cond);
static bool process_direct_rownum_comparison(THD *thd, SELECT_LEX_UNIT *unit, static bool process_direct_rownum_comparison(THD *thd, SELECT_LEX_UNIT *unit,
Item *cond); Item *cond);
void trace_attached_conditions(THD *thd, JOIN *join);
void trace_join_readinfo(THD *thd, JOIN *join);
#ifndef DBUG_OFF #ifndef DBUG_OFF
...@@ -3137,6 +3139,8 @@ int JOIN::optimize_stage2() ...@@ -3137,6 +3139,8 @@ int JOIN::optimize_stage2()
if (make_join_readinfo(this, select_opts_for_readinfo, no_jbuf_after)) if (make_join_readinfo(this, select_opts_for_readinfo, no_jbuf_after))
DBUG_RETURN(1); DBUG_RETURN(1);
trace_join_readinfo(thd, this);
/* Perform FULLTEXT search before all regular searches */ /* Perform FULLTEXT search before all regular searches */
if (!(select_options & SELECT_DESCRIBE)) if (!(select_options & SELECT_DESCRIBE))
if (init_ftfuncs(thd, select_lex, MY_TEST(order))) if (init_ftfuncs(thd, select_lex, MY_TEST(order)))
...@@ -5112,6 +5116,8 @@ mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds, ...@@ -5112,6 +5116,8 @@ mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds,
goto err; // 1 goto err; // 1
} }
trace_attached_conditions(thd, join);
if (thd->lex->describe & DESCRIBE_EXTENDED) if (thd->lex->describe & DESCRIBE_EXTENDED)
{ {
join->conds_history= join->conds; join->conds_history= join->conds;
...@@ -13073,10 +13079,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -13073,10 +13079,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
/* /*
Step #2: Extract WHERE/ON parts Step #2: Extract WHERE/ON parts
*/ */
Json_writer_object trace_wrapper(thd);
Json_writer_object trace_conditions(thd, "attaching_conditions_to_tables");
Json_writer_array trace_attached_comp(thd,
"attached_conditions_computation");
uint i; uint i;
for (i= join->top_join_tab_count - 1; i >= join->const_tables; i--) for (i= join->top_join_tab_count - 1; i >= join->const_tables; i--)
{ {
...@@ -13644,23 +13647,6 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -13644,23 +13647,6 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
i++; i++;
} }
if (unlikely(thd->trace_started()))
{
trace_attached_comp.end();
Json_writer_array trace_attached_summary(thd,
"attached_conditions_summary");
for (tab= first_depth_first_tab(join); tab;
tab= next_depth_first_tab(join, tab))
{
if (!tab->table)
continue;
Item *const cond = tab->select_cond;
Json_writer_object trace_one_table(thd);
trace_one_table.
add_table_name(tab).
add("attached", cond);
}
}
} }
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -14778,7 +14764,7 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after) ...@@ -14778,7 +14764,7 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
} }
check_join_cache_usage_for_tables(join, options, no_jbuf_after); check_join_cache_usage_for_tables(join, options, no_jbuf_after);
JOIN_TAB *first_tab; JOIN_TAB *first_tab;
for (tab= first_tab= first_linear_tab(join, for (tab= first_tab= first_linear_tab(join,
WITH_BUSH_ROOTS, WITHOUT_CONST_TABLES); WITH_BUSH_ROOTS, WITHOUT_CONST_TABLES);
...@@ -31920,6 +31906,60 @@ bool JOIN::transform_all_conds_and_on_exprs_in_join_list( ...@@ -31920,6 +31906,60 @@ bool JOIN::transform_all_conds_and_on_exprs_in_join_list(
} }
void trace_attached_conditions(THD *thd, JOIN *join)
{
if (!unlikely(thd->trace_started()))
return;
Json_writer_object trace_wrapper(thd);
Json_writer_object trace_conditions(thd, "attaching_conditions_to_tables");
Json_writer_array trace_attached_comp(thd,
"attached_conditions_computation");
JOIN_TAB *tab;
trace_attached_comp.end();
Json_writer_array trace_attached_summary(thd,
"attached_conditions_summary");
for (tab= first_depth_first_tab(join);
tab;
tab= next_depth_first_tab(join, tab))
{
if (!tab->table)
continue;
Item *const remaining_cond = tab->select_cond;
Item *const idx_cond = tab->table->file->pushed_idx_cond;
Json_writer_object trace_one_table(thd);
trace_one_table.add_table_name(tab);
trace_one_table.add("attached_condition", remaining_cond);
if (idx_cond)
trace_one_table.add("index_condition", idx_cond);
}
}
void trace_join_readinfo(THD *thd, JOIN *join)
{
if (!unlikely(thd->trace_started()))
return;
Json_writer_object trace_wrapper(thd);
Json_writer_array trace_conditions(thd, "make_join_readinfo");
JOIN_TAB *tab;
for (tab= first_linear_tab(join, WITH_BUSH_ROOTS, WITHOUT_CONST_TABLES);
tab;
tab= next_linear_tab(join, tab, WITH_BUSH_ROOTS))
{
Json_writer_object trace_one_table(thd);
trace_one_table.add_table_name(tab);
trace_one_table.add("index_condition", tab->select_cond);
}
}
/** /**
@} (end of group Query_Optimizer) @} (end of group Query_Optimizer)
*/ */
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