Commit cbd99688 authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-21095: Make Optimizer Trace support Index Condition Pushdown

Fixes over previous patches: do tracing of attached conditions
close to where we generate them.

Fix the tracing code to print the right conditions.
parent 07f21cfb
......@@ -177,23 +177,18 @@ select * from v1 {
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": "t1.a = 1"
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a = 1"
}
]
}
},
{
"table": "t1",
"attached_condition": "t1.a = 1"
"make_join_readinfo": []
}
]
}
......@@ -353,23 +348,18 @@ select * from (select * from t1 where t1.a=1)q {
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": "t1.a = 1"
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a = 1"
}
]
}
},
{
"table": "t1",
"attached_condition": "t1.a = 1"
"make_join_readinfo": []
}
]
}
......@@ -536,12 +526,18 @@ select * from v2 {
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": "t1.a = 1"
}
]
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a = 1"
}
]
}
},
{
"make_join_readinfo": []
}
]
}
......@@ -615,23 +611,18 @@ select * from v2 {
"cost": 0.012418701
},
{
"make_join_readinfo": [
{
"table": "<derived2>",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "<derived2>",
"attached_condition": null
}
]
}
},
{
"table": "<derived2>",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......@@ -640,17 +631,6 @@ select * from v2 {
"join_execution": {
"select_id": 1,
"steps": [
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a = 1"
}
]
}
},
{
"join_execution": {
"select_id": 2,
......@@ -788,23 +768,18 @@ explain select * from v2 {
"cost": 0.01159965
},
{
"make_join_readinfo": [
{
"table": "t2",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t2",
"attached_condition": null
}
]
}
},
{
"table": "t2",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......@@ -931,12 +906,18 @@ explain select * from v1 {
"cost": 0.017968034
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
}
]
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{
"make_join_readinfo": []
}
]
}
......@@ -1009,43 +990,27 @@ explain select * from v1 {
"rows": 10,
"cost": 0.012757506
},
{
"make_join_readinfo": [
{
"table": "<derived2>",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "<derived2>",
"attached_condition": null
}
]
}
},
{
"join_execution": {
"select_id": 1,
"steps": [
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"table": "<derived2>",
"attached_condition": null
}
]
}
},
{
"make_join_readinfo": []
}
]
}
},
{
"join_execution": {
"select_id": 1,
"steps": [
{
"join_execution": {
"select_id": 2,
......@@ -1356,31 +1321,22 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b {
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": "t1.b is not null"
},
{
"table": "t2",
"index_condition": "t1.a = t2.b + 2"
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.b is not null"
"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"
}
]
}
},
{
"table": "t2",
"attached_condition": "t1.a = t2.b + 2"
"make_join_readinfo": []
}
]
}
......@@ -1551,23 +1507,18 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
"cost": 0.004191135
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{
"table": "t1",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......@@ -1780,12 +1731,18 @@ set statement optimizer_scan_setup_cost=0 for EXPLAIN SELECT MIN(d) FROM t1 wher
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": "t1.b = 2 and t1.c = 3"
}
]
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.b = 2 and t1.c = 3"
}
]
}
},
{
"make_join_readinfo": []
},
{
"reconsidering_access_paths_for_index_ordering": {
......@@ -1812,17 +1769,6 @@ 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": {
"select_id": 1,
......@@ -2024,23 +1970,18 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id {
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": "t1.a >= 20010104e0"
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a >= 20010104e0"
}
]
}
},
{
"table": "t1",
"attached_condition": "t1.a >= 20010104e0"
"make_join_readinfo": []
}
]
}
......@@ -2235,23 +2176,18 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id {
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": "t1.a = 20010104e0"
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a = 20010104e0"
}
]
}
},
{
"table": "t1",
"attached_condition": "t1.a = 20010104e0"
"make_join_readinfo": []
}
]
}
......@@ -2542,12 +2478,18 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 {
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
}
]
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{
"make_join_readinfo": []
},
{
"reconsidering_access_paths_for_index_ordering": {
......@@ -2645,17 +2587,6 @@ 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": {
"select_id": 1,
......@@ -2820,27 +2751,23 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
}
},
{
"condition_on_constant_tables": "1",
"computing_condition": []
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [
{
"condition_on_constant_tables": "1",
"computing_condition": []
}
],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{
"table": "t1",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......@@ -3035,35 +2962,27 @@ explain select * from t1 left join t2 on t2.a=t1.a {
}
},
{
"condition_on_constant_tables": "1",
"computing_condition": []
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
},
{
"table": "t2",
"index_condition": "trigcond(trigcond(t1.a is not null))"
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
"attaching_conditions_to_tables": {
"attached_conditions_computation": [
{
"condition_on_constant_tables": "1",
"computing_condition": []
}
],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
},
{
"table": "t2",
"attached_condition": "trigcond(trigcond(t1.a is not null))"
}
]
}
},
{
"table": "t2",
"attached_condition": "trigcond(trigcond(t1.a is not null))"
"make_join_readinfo": []
}
]
}
......@@ -3239,27 +3158,23 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
}
},
{
"condition_on_constant_tables": "1",
"computing_condition": []
"attaching_conditions_to_tables": {
"attached_conditions_computation": [
{
"condition_on_constant_tables": "1",
"computing_condition": []
}
],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......@@ -3650,31 +3565,22 @@ explain extended select * from t1 where a in (select p from t2) {
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
},
{
"table": "t2",
"index_condition": "t2.p = t1.a"
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
},
{
"table": "t2",
"attached_condition": "t2.p = t1.a"
}
]
}
},
{
"table": "t2",
"attached_condition": "t2.p = t1.a"
"make_join_readinfo": []
}
]
}
......@@ -4038,23 +3944,18 @@ explain select * from t1 where pk = 2 and a=5 and b=1 {
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{
"table": "t1",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......@@ -4184,23 +4085,18 @@ select f1(a) from t1 {
"cost": 0.01066122
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{
"table": "t1",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......@@ -4306,23 +4202,18 @@ select f2(a) from t1 {
"cost": 0.01066122
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{
"table": "t1",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......@@ -4352,7 +4243,7 @@ a
2
select length(trace) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
length(trace)
2869
2819
set optimizer_trace_max_mem_size=100;
select * from t1;
a
......@@ -4366,7 +4257,7 @@ select * from t1 {
"join_preparation": {
"select_id": 1,
"steps": [
2769 0
2719 0
set optimizer_trace_max_mem_size=0;
select * from t1;
a
......@@ -4374,7 +4265,7 @@ a
2
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
select * from t1 2869 0
select * from t1 2819 0
drop table t1;
set optimizer_trace='enabled=off';
set @@optimizer_trace_max_mem_size= @save_optimizer_trace_max_mem_size;
......@@ -4843,31 +4734,22 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 {
}
},
{
"make_join_readinfo": [
{
"table": "t0",
"index_condition": "t0.a < 3 and t0.a is not null"
},
{
"table": "t1",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t0",
"attached_condition": "t0.a < 3 and t0.a is not 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
}
]
}
},
{
"table": "t1",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......@@ -5008,12 +4890,18 @@ explain select * from (select rand() from t1)q {
"cost": 0.010504815
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
}
]
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{
"make_join_readinfo": []
}
]
}
......@@ -5086,43 +4974,27 @@ explain select * from (select rand() from t1)q {
"rows": 3,
"cost": 0.012461052
},
{
"make_join_readinfo": [
{
"table": "<derived2>",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "<derived2>",
"attached_condition": null
}
]
}
},
{
"join_execution": {
"select_id": 1,
"steps": [
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"table": "<derived2>",
"attached_condition": null
}
]
}
},
{
"make_join_readinfo": []
}
]
}
},
{
"join_execution": {
"select_id": 1,
"steps": [
{
"join_execution": {
"select_id": 2,
......@@ -5680,51 +5552,35 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
}
},
{
"condition_on_constant_tables": "1",
"computing_condition": []
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
},
{
"table": "<subquery2>",
"index_condition": "t1.a = `sj-materialize`.a"
},
{
"table": "t_inner_1",
"index_condition": null
},
{
"table": "t_inner_2",
"index_condition": 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
"attaching_conditions_to_tables": {
"attached_conditions_computation": [
{
"condition_on_constant_tables": "1",
"computing_condition": []
}
],
"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": null
}
]
}
},
{
"table": "<subquery2>",
"attached_condition": "t1.a = `sj-materialize`.a"
"make_join_readinfo": []
}
]
}
......@@ -8055,63 +7911,38 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
}
},
{
"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": {
"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
},
{
"table": "t_inner_3",
"attached_condition": "t_inner_3.a = t_outer_2.a"
}
]
}
},
{
"table": "t_inner_3",
"attached_condition": "t_inner_3.a = t_outer_2.a"
"make_join_readinfo": []
}
]
}
......@@ -10456,83 +10287,51 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
}
},
{
"condition_on_constant_tables": "1",
"computing_condition": []
},
{
"make_join_readinfo": [
{
"table": "t_outer_1",
"index_condition": null
},
{
"table": "<subquery2>",
"index_condition": "t_outer_1.a = `sj-materialize`.a"
},
{
"table": "t_inner_1",
"index_condition": null
},
{
"table": "t_inner_2",
"index_condition": null
},
{
"table": "t_outer_2",
"index_condition": null
},
{
"table": "<subquery3>",
"index_condition": "t_outer_2.a = `sj-materialize`.a"
},
{
"table": "t_inner_4",
"index_condition": null
},
{
"table": "t_inner_3",
"index_condition": 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
"attaching_conditions_to_tables": {
"attached_conditions_computation": [
{
"condition_on_constant_tables": "1",
"computing_condition": []
}
],
"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": null
},
{
"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": null
}
]
}
},
{
"table": "<subquery3>",
"attached_condition": "t_outer_2.a = `sj-materialize`.a"
"make_join_readinfo": []
}
]
}
......@@ -11762,12 +11561,6 @@ SELECT 'a\0' LIMIT 0 {
"steps": []
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": []
}
},
{
"join_execution": {
"select_id": 1,
......@@ -11883,23 +11676,18 @@ select count(*) from seq_1_to_10000000 {
"cost": 444.7880673
},
{
"make_join_readinfo": [
{
"table": "seq_1_to_10000000",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "seq_1_to_10000000",
"attached_condition": null
}
]
}
},
{
"table": "seq_1_to_10000000",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......@@ -12636,29 +12424,29 @@ explain select * from t1 where a<10 and b between 10 and 50 and c < 10 {
"resulting_condition": "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.a < 10 and t1.b between 10 and 50 and t1.c < 10"
}
]
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": "t1.b between 10 and 50 and t1.c < 10"
"index_condition": "t1.a < 10",
"row_condition": "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"
}
]
}
},
{
"join_execution": {
"select_id": 1,
......@@ -13058,79 +12846,71 @@ explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and
}
},
{
"table": "t1",
"range_analysis": {
"table_scan": {
"rows": 10000,
"cost": 1.581538
},
"potential_range_indexes": [
{
"index": "a",
"usable": true,
"key_parts": ["a"]
},
"attaching_conditions_to_tables": {
"attached_conditions_computation": [
{
"index": "b",
"usable": true,
"key_parts": ["b"]
"table": "t1",
"range_analysis": {
"table_scan": {
"rows": 10000,
"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"
}
}
}
],
"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"
"attached_conditions_summary": [
{
"table": "three",
"attached_condition": null
},
"analyzing_index_merge_union": []
},
"group_index_range": {
"chosen": false,
"cause": "not single_table"
}
{
"table": "t1",
"attached_condition": "t1.a = three.a and t1.b < 5000 and t1.c < 1000"
}
]
}
},
{
"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"
"make_join_readinfo": []
}
]
}
......@@ -13190,8 +12970,7 @@ out1
[
{
"table": "t10",
"attached_condition": "t10.c < 10",
"index_condition": "t10.a < 3 and t10.b <> 5"
"attached_condition": "t10.a < 3 and t10.b <> 5 and t10.c < 10"
}
]
}
......
......@@ -257,23 +257,18 @@ explain select * from t1 where a=1 or b=1 {
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": "t1.a = 1 or t1.b = 1"
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.a = 1 or t1.b = 1"
}
]
}
},
{
"table": "t1",
"attached_condition": "t1.a = 1 or t1.b = 1"
"make_join_readinfo": []
}
]
}
......
......@@ -255,29 +255,28 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"resulting_condition": "t1.key1 = 1 and t1.pk1 <> 0"
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": "t1.pk1 <> 0"
}
]
}
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
"index_condition": "t1.pk1 <> 0"
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null,
"index_condition": "t1.pk1 <> 0"
}
]
}
},
{
"join_execution": {
"select_id": 1,
......
......@@ -133,23 +133,18 @@ select * from db1.t1 {
"cost": 0.010504815
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{
"table": "t1",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......@@ -280,23 +275,18 @@ select * from db1.v1 {
"cost": 0.010504815
},
{
"make_join_readinfo": [
{
"table": "t1",
"index_condition": null
}
]
}
]
}
},
{
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
"attaching_conditions_to_tables": {
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
"table": "t1",
"attached_condition": null
}
]
}
},
{
"table": "t1",
"attached_condition": null
"make_join_readinfo": []
}
]
}
......
......@@ -17,6 +17,7 @@
#include "mariadb.h"
#include "sql_select.h"
#include "sql_test.h"
#include "opt_trace.h"
/****************************************************************************
* Index Condition Pushdown code starts
......@@ -355,6 +356,8 @@ void push_index_cond(JOIN_TAB *tab, uint keyno)
{
Item *idx_remainder_cond= 0;
tab->pre_idx_push_select_cond= tab->select_cond;
Json_writer_object trace(tab->join->thd);
trace.add_table_name(tab);
/*
For BKA cache we store condition to special BKA cache field
because evaluation of the condition requires additional operations
......@@ -387,6 +390,7 @@ void push_index_cond(JOIN_TAB *tab, uint keyno)
idx_remainder_cond= NULL;
}
}
trace.add("index_condition", idx_cond);
/*
Disable eq_ref's "lookup cache" if we've pushed down an index
......@@ -424,6 +428,10 @@ void push_index_cond(JOIN_TAB *tab, uint keyno)
}
else
tab->select_cond= idx_remainder_cond;
if (tab->select_cond)
trace.add("row_condition", tab->select_cond);
if (tab->select)
{
DBUG_EXECUTE("where",
......
......@@ -349,8 +349,6 @@ 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 bool process_direct_rownum_comparison(THD *thd, SELECT_LEX_UNIT *unit,
Item *cond);
void trace_attached_conditions(THD *thd, JOIN *join);
void trace_join_readinfo(THD *thd, JOIN *join);
#ifndef DBUG_OFF
......@@ -3139,8 +3137,6 @@ int JOIN::optimize_stage2()
if (make_join_readinfo(this, select_opts_for_readinfo, no_jbuf_after))
DBUG_RETURN(1);
trace_join_readinfo(thd, this);
/* Perform FULLTEXT search before all regular searches */
if (!(select_options & SELECT_DESCRIBE))
if (init_ftfuncs(thd, select_lex, MY_TEST(order)))
......@@ -5116,8 +5112,6 @@ mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds,
goto err; // 1
}
trace_attached_conditions(thd, join);
if (thd->lex->describe & DESCRIBE_EXTENDED)
{
join->conds_history= join->conds;
......@@ -12980,6 +12974,10 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
DBUG_ENTER("make_join_select");
if (select)
{
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");
add_not_null_conds(join);
table_map used_tables;
/*
......@@ -13056,6 +13054,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
{
add_cond_and_fix(thd, &outer_ref_cond, join->outer_ref_cond);
join->outer_ref_cond= outer_ref_cond;
Json_writer_object trace(thd);
trace.add("outer_ref_cond", outer_ref_cond);
}
}
else
......@@ -13071,6 +13072,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
add_cond_and_fix(thd, &pseudo_bits_cond,
join->pseudo_bits_cond);
join->pseudo_bits_cond= pseudo_bits_cond;
Json_writer_object trace(thd);
trace.add("pseudo_bits_cond", pseudo_bits_cond);
}
}
}
......@@ -13647,6 +13651,22 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
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);
trace_one_table.add("attached_condition", cond);
}
}
}
DBUG_RETURN(0);
}
......@@ -14724,6 +14744,9 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
uint i;
DBUG_ENTER("make_join_readinfo");
Json_writer_object trace_wrapper(join->thd);
Json_writer_array trace_arr(join->thd, "make_join_readinfo");
bool statistics= MY_TEST(!(join->select_options & SELECT_DESCRIBE));
bool sorted= 1;
......@@ -31905,61 +31928,6 @@ bool JOIN::transform_all_conds_and_on_exprs_in_join_list(
return false;
}
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)
*/
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