Details
Description
SET optimizer_trace= 'enabled=on'; |
|
CREATE TABLE t1 (id INT PRIMARY KEY); |
INSERT INTO t1 VALUES (1),(2); |
|
CREATE TABLE t2 (a INT); |
INSERT INTO t2 VALUES (3),(4); |
|
SELECT * FROM t1 WHERE id < ( SELECT SUM(a) FROM t2 ); |
|
SELECT JSON_VALID(trace) FROM information_schema.optimizer_trace; |
|
# Cleanup
|
DROP TABLE t1, t2; |
SELECT * FROM t1 WHERE id < ( SELECT SUM(a) FROM t2 ); |
id
|
1
|
2
|
SELECT JSON_VALID(trace) FROM information_schema.optimizer_trace; |
JSON_VALID(trace)
|
0
|
The plan is
{
|
"query_optimization": { |
"r_total_time_ms": 0.214919473 |
},
|
"query_block": { |
"select_id": 1, |
"r_loops": 1, |
"r_total_time_ms": 0.015704535, |
"nested_loop": [ |
{
|
"table": { |
"table_name": "t1", |
"access_type": "range", |
"possible_keys": ["PRIMARY"], |
"key": "PRIMARY", |
"key_length": "4", |
"used_key_parts": ["id"], |
"r_loops": 1, |
"rows": 2, |
"r_rows": 2, |
"r_table_time_ms": 0.004733423, |
"r_other_time_ms": 0.007802125, |
"filtered": 100, |
"r_filtered": 100, |
"attached_condition": "t1.`id` < (subquery#2)", |
"using_index": true |
}
|
}
|
],
|
"subqueries": [ |
{
|
"query_block": { |
"select_id": 2, |
"r_loops": 1, |
"r_total_time_ms": 0.019324802, |
"nested_loop": [ |
{
|
"table": { |
"table_name": "t2", |
"access_type": "ALL", |
"r_loops": 1, |
"rows": 2, |
"r_rows": 2, |
"r_table_time_ms": 0.00379075, |
"r_other_time_ms": 0.007952552, |
"filtered": 100, |
"r_filtered": 100 |
}
|
}
|
]
|
}
|
}
|
]
|
}
|
The problematic part of the optimizer trace is
{
|
"substitute_best_equal": {
|
"condition": "WHERE",
|
"resulting_condition": "t1.`id` < (/* select#2 */ select #^B)"
|
}
|
},
|
{
|
"attaching_conditions_to_tables": {
|
"attached_conditions_computation": [],
|
"attached_conditions_summary": [
|
{
|
"table": "t1",
|
"attached": "t1.`id` < (/* select#2 */ select #^B)"
|
}
|
]
|
}
|
}
|
where #^B are actually special symbols.