summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Petrunia <sergey@mariadb.com>2022-12-08 21:24:31 +0300
committerMonty <monty@mariadb.org>2022-12-20 23:11:29 +0200
commitcdd59723e9445cec921a2cf308eb6a855c5cbc04 (patch)
tree640233c456edbb3d950476cb90bb2b82c5b19b36
parent723a178fa7981fade2c68d9220db0cfcde899544 (diff)
downloadmariadb-git-cdd59723e9445cec921a2cf308eb6a855c5cbc04.tar.gz
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.
-rw-r--r--mysql-test/main/opt_trace.result1159
-rw-r--r--mysql-test/main/opt_trace_index_merge.result27
-rw-r--r--mysql-test/main/opt_trace_index_merge_innodb.result25
-rw-r--r--mysql-test/main/opt_trace_security.result54
-rw-r--r--sql/opt_index_cond_pushdown.cc8
-rw-r--r--sql/sql_select.cc90
6 files changed, 551 insertions, 812 deletions
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index 2c34f35742c..adc295775f8 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -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": []
}
]
}
@@ -641,17 +632,6 @@ select * from v2 {
"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,
"steps": []
@@ -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": []
}
]
}
@@ -1010,43 +991,27 @@ explain select * from v1 {
"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,
"steps": []
@@ -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": {
@@ -1813,17 +1770,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,
"steps": []
@@ -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": {
@@ -2646,17 +2588,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,
"steps": []
@@ -2820,27 +2751,23 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
}
},
{
- "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": []
}
]
}
@@ -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": []
}
]
}
@@ -5087,43 +4975,27 @@ explain select * from (select rand() from t1)q {
"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,
"steps": []
@@ -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": []
}
]
}
@@ -11898,12 +11697,6 @@ SELECT 'a\0' LIMIT 0 {
}
},
{
- "attaching_conditions_to_tables": {
- "attached_conditions_computation": [],
- "attached_conditions_summary": []
- }
- },
- {
"join_execution": {
"select_id": 1,
"steps": []
@@ -12018,23 +11811,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": []
}
]
}
@@ -12800,10 +12588,22 @@ explain select * from t1 where a<10 and b between 10 and 50 and 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"
}
]
}
@@ -12811,18 +12611,6 @@ explain select * from t1 where a<10 and b between 10 and 50 and 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,
"steps": []
@@ -13221,79 +13009,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": []
}
]
}
@@ -13356,8 +13136,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"
}
]
}
diff --git a/mysql-test/main/opt_trace_index_merge.result b/mysql-test/main/opt_trace_index_merge.result
index 5435637f98c..58d213c0584 100644
--- a/mysql-test/main/opt_trace_index_merge.result
+++ b/mysql-test/main/opt_trace_index_merge.result
@@ -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": []
}
]
}
diff --git a/mysql-test/main/opt_trace_index_merge_innodb.result b/mysql-test/main/opt_trace_index_merge_innodb.result
index 415d80b893d..6711db9c334 100644
--- a/mysql-test/main/opt_trace_index_merge_innodb.result
+++ b/mysql-test/main/opt_trace_index_merge_innodb.result
@@ -256,10 +256,21 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
}
},
{
+ "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"
}
]
}
@@ -267,18 +278,6 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
}
},
{
- "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,
"steps": []
diff --git a/mysql-test/main/opt_trace_security.result b/mysql-test/main/opt_trace_security.result
index 778494b549b..9ef6cadec5f 100644
--- a/mysql-test/main/opt_trace_security.result
+++ b/mysql-test/main/opt_trace_security.result
@@ -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": []
}
]
}
diff --git a/sql/opt_index_cond_pushdown.cc b/sql/opt_index_cond_pushdown.cc
index 6a24fa95b68..7bda8c45ac7 100644
--- a/sql/opt_index_cond_pushdown.cc
+++ b/sql/opt_index_cond_pushdown.cc
@@ -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",
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 726ebcb6a1e..0e7a3a42580 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -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
@@ -3141,8 +3139,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)))
@@ -5118,8 +5114,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;
@@ -12935,6 +12929,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;
/*
@@ -13011,6 +13009,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
@@ -13026,6 +13027,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);
}
}
}
@@ -13602,6 +13606,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);
}
@@ -14679,6 +14699,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;
@@ -31857,61 +31880,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)
*/