summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Petrunia <sergey@mariadb.com>2022-12-08 21:24:31 +0300
committerSergei Petrunia <sergey@mariadb.com>2022-12-13 14:44:08 +0200
commit6ef49c7b8cbc77f23719b09bbb93f0e1c6d61ea6 (patch)
treed18866b28d9db5a57a27cd8526b37784e18cf630
parentb6c5d74e708eea046325e9cb2c2031d602bb27e9 (diff)
downloadmariadb-git-bb-MDEV-21092-21095-29997-optimizer-trace-updates.tar.gz
MDEV-21095: Make Optimizer Trace support Index Condition Pushdownbb-MDEV-21092-21095-29997-optimizer-trace-updates
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.result1028
-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.cc91
6 files changed, 489 insertions, 744 deletions
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index 29af1f343bf..abfb85da737 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -167,23 +167,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": []
}
]
}
@@ -333,23 +328,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": []
}
]
}
@@ -506,12 +496,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": []
}
]
}
@@ -575,23 +571,18 @@ select * from v2 {
"best_join_order": ["<derived2>"]
},
{
- "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": []
}
]
}
@@ -601,17 +592,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": []
@@ -738,23 +718,18 @@ explain select * from v2 {
"best_join_order": ["t2"]
},
{
- "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": []
}
]
}
@@ -871,12 +846,18 @@ explain select * from v1 {
"best_join_order": ["t1"]
},
{
- "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": []
}
]
}
@@ -940,43 +921,27 @@ explain select * from v1 {
"best_join_order": ["<derived2>"]
},
{
- "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": []
@@ -1254,31 +1219,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": []
}
]
}
@@ -1441,23 +1397,18 @@ EXPLAIN SELECT DISTINCT a FROM t1 {
"best_join_order": ["t1"]
},
{
- "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": []
}
]
}
@@ -1654,23 +1605,18 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a {
}
},
{
- "make_join_readinfo": [
- {
- "table": "t1",
- "index_condition": "t1.b = 2 and t1.c = 3"
- }
- ]
- }
- ]
- }
- },
- {
- "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.b = 2 and t1.c = 3"
+ }
+ ]
+ }
+ },
{
- "table": "t1",
- "attached_condition": "t1.b = 2 and t1.c = 3"
+ "make_join_readinfo": []
}
]
}
@@ -1868,23 +1814,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": []
}
]
}
@@ -2071,23 +2012,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": []
}
]
}
@@ -2372,12 +2308,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": {
@@ -2478,17 +2420,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": []
@@ -2642,27 +2573,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": []
}
]
}
@@ -2843,35 +2770,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": []
}
]
}
@@ -3037,27 +2956,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": []
}
]
}
@@ -3389,43 +3304,31 @@ explain extended select * from t1 where a in (select pk from t10) {
}
},
{
- "condition_on_constant_tables": "1",
- "computing_condition": []
- },
- {
- "make_join_readinfo": [
- {
- "table": "t1",
- "index_condition": null
- },
- {
- "table": "<subquery2>",
- "index_condition": "t1.a = `sj-materialize`.pk"
- },
- {
- "table": "t10",
- "index_condition": null
- }
- ]
- }
- ]
- }
- },
- {
- "attaching_conditions_to_tables": {
- "attached_conditions_computation": [],
- "attached_conditions_summary": [
- {
- "table": "t1",
- "attached_condition": null
- },
- {
- "table": "t10",
- "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": "t10",
+ "attached_condition": null
+ },
+ {
+ "table": "<subquery2>",
+ "attached_condition": null
+ }
+ ]
+ }
},
{
- "table": "<subquery2>",
- "attached_condition": "t1.a = `sj-materialize`.pk"
+ "make_join_readinfo": []
}
]
}
@@ -3785,23 +3688,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": []
}
]
}
@@ -3923,23 +3821,18 @@ select f1(a) from t1 {
"best_join_order": ["t1"]
},
{
- "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": []
}
]
}
@@ -4035,23 +3928,18 @@ select f2(a) from t1 {
"best_join_order": ["t1"]
},
{
- "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": []
}
]
}
@@ -4081,7 +3969,7 @@ a
2
select length(trace) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
length(trace)
-2482
+2432
set optimizer_trace_max_mem_size=100;
select * from t1;
a
@@ -4095,7 +3983,7 @@ select * from t1 {
"join_preparation": {
"select_id": 1,
"steps": [
- 2382 0
+ 2332 0
set optimizer_trace_max_mem_size=0;
select * from t1;
a
@@ -4103,7 +3991,7 @@ a
2
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
-select * from t1 2482 0
+select * from t1 2432 0
drop table t1;
set optimizer_trace='enabled=off';
set @@optimizer_trace_max_mem_size= @save_optimizer_trace_max_mem_size;
@@ -4548,31 +4436,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": []
}
]
}
@@ -4703,12 +4582,18 @@ explain select * from (select rand() from t1)q {
"best_join_order": ["t1"]
},
{
- "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": []
}
]
}
@@ -4772,43 +4657,27 @@ explain select * from (select rand() from t1)q {
"best_join_order": ["<derived2>"]
},
{
- "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": []
@@ -5288,51 +5157,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": []
}
]
}
@@ -7394,63 +7247,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": []
}
]
}
@@ -8978,83 +8806,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": "t_outer_2",
- "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": "<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_outer_2",
- "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_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_outer_2",
+ "attached_condition": null
+ },
+ {
+ "table": "t_inner_1",
+ "attached_condition": null
+ },
+ {
+ "table": "t_inner_2",
+ "attached_condition": null
+ },
+ {
+ "table": "<subquery2>",
+ "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": []
}
]
}
@@ -10384,12 +10180,6 @@ SELECT 'a\0' LIMIT 0 {
}
},
{
- "attaching_conditions_to_tables": {
- "attached_conditions_computation": [],
- "attached_conditions_summary": []
- }
- },
- {
"join_execution": {
"select_id": 1,
"steps": []
@@ -10494,23 +10284,18 @@ select count(*) from seq_1_to_10000000 {
"best_join_order": ["seq_1_to_10000000"]
},
{
- "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": []
}
]
}
@@ -11034,8 +10819,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 86e714acfbc..bfea0fefc01 100644
--- a/mysql-test/main/opt_trace_index_merge.result
+++ b/mysql-test/main/opt_trace_index_merge.result
@@ -243,23 +243,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 b604853b715..31742ed97ac 100644
--- a/mysql-test/main/opt_trace_index_merge_innodb.result
+++ b/mysql-test/main/opt_trace_index_merge_innodb.result
@@ -249,10 +249,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"
}
]
}
@@ -260,18 +271,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 d5dfba14082..4ed619ca7fd 100644
--- a/mysql-test/main/opt_trace_security.result
+++ b/mysql-test/main/opt_trace_security.result
@@ -123,23 +123,18 @@ select * from db1.t1 {
"best_join_order": ["t1"]
},
{
- "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": []
}
]
}
@@ -260,23 +255,18 @@ select * from db1.v1 {
"best_join_order": ["t1"]
},
{
- "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 4340fdaae53..a1c91228aa4 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -323,8 +323,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
@@ -3103,8 +3101,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)))
@@ -5072,8 +5068,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;
@@ -12303,6 +12297,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;
/*
@@ -12375,6 +12373,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
@@ -12390,6 +12391,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);
}
}
}
@@ -12955,6 +12959,23 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (!tab->bush_children)
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);
}
@@ -14024,6 +14045,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;
@@ -31098,61 +31122,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)
*/