SET optimizer_trace_max_mem_size=1048576;
SET end_markers_in_json=on;
SET optimizer_trace="enabled=on,one_line=off";
CREATE TABLE t1
(
key1 INT NOT NULL,
INDEX i1(key1)
);
Inserting 1024 records into t1
ALTER TABLE t1 ADD key2 INT NOT NULL, ADD INDEX i2(key2);
ALTER TABLE t1 ADD key3 INT NOT NULL, ADD INDEX i3(key3);
ALTER TABLE t1 ADD key4 INT NOT NULL, ADD INDEX i4(key4);
ALTER TABLE t1 ADD key5 INT NOT NULL, ADD INDEX i5(key5);
ALTER TABLE t1 ADD key6 INT NOT NULL, ADD INDEX i6(key6);
ALTER TABLE t1 ADD key7 INT NOT NULL, ADD INDEX i7(key7);
ALTER TABLE t1 ADD key8 INT NOT NULL, ADD INDEX i8(key8);
UPDATE t1 SET
key2=key1,
key3=key1,
key4=key1,
key5=key1,
key6=key1,
key7=key1,
key8=1024-key1;
CREATE TABLE t2 (
key1a INT NOT NULL,
key1b INT NOT NULL,
key2 INT NOT NULL,
key2_1 INT NOT NULL,
key2_2 INT NOT NULL,
key3 INT NOT NULL,
primary key i1a (key1a, key1b),
INDEX i1b (key1b, key1a),
INDEX i2_1(key2, key2_1),
INDEX i2_2(key2, key2_1)
);
Warnings:
Note 1831 Duplicate index 'i2_2' defined on the table 'test.t2'. This is deprecated and will be disallowed in a future release.
INSERT INTO t2 SELECT key1,key1,key1 div 10, key1 % 10, key1 % 10, key1 FROM t1;
EXPLAIN SELECT * FROM t1 WHERE key2 < 5 OR key2 > 1020;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range i2 i2 4 NULL 47 Using index condition
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t1 WHERE key2 < 5 OR key2 > 1020 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t1`.`key1` AS `key1`,`t1`.`key2` AS `key2`,`t1`.`key3` AS `key3`,`t1`.`key4` AS `key4`,`t1`.`key5` AS `key5`,`t1`.`key6` AS `key6`,`t1`.`key7` AS `key7`,`t1`.`key8` AS `key8` from `t1` where ((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 217.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "i1",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i2",
"usable": true,
"key_parts": [
"key2"
] /* key_parts */
},
{
"index": "i3",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i4",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i5",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i6",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i7",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i8",
"usable": false,
"cause": "not_applicable"
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "i2",
"ranges": [
"key2 < 5",
"1020 < key2"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 47,
"cost": 58.41,
"chosen": true
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "i2",
"rows": 47,
"ranges": [
"key2 < 5",
"1020 < key2"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 47,
"cost_for_plan": 58.41,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "range",
"rows": 47,
"cost": 67.81,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 67.81,
"rows_for_plan": 47,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t1`",
"pushed_index_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))",
"table_condition_attached": null,
"access_type": "range"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
set @@optimizer_trace_features="range_optimizer=off";
EXPLAIN SELECT * FROM t1 WHERE key2 < 5 OR key2 > 1020;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range i2 i2 4 NULL 47 Using index condition
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t1 WHERE key2 < 5 OR key2 > 1020 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t1`.`key1` AS `key1`,`t1`.`key2` AS `key2`,`t1`.`key3` AS `key3`,`t1`.`key4` AS `key4`,`t1`.`key5` AS `key5`,`t1`.`key6` AS `key6`,`t1`.`key7` AS `key7`,`t1`.`key8` AS `key8` from `t1` where ((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 217.15
} /* table_scan */,
"potential_range_indices": "...",
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": "...",
"analyzing_range_alternatives": "...",
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "i2",
"rows": 47,
"ranges": [
"key2 < 5",
"1020 < key2"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 47,
"cost_for_plan": 58.41,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "range",
"rows": 47,
"cost": 67.81,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 67.81,
"rows_for_plan": 47,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t1`",
"pushed_index_condition": "((`t1`.`key2` < 5) or (`t1`.`key2` > 1020))",
"table_condition_attached": null,
"access_type": "range"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
set @@optimizer_trace_features="range_optimizer=on";
EXPLAIN SELECT * FROM t1 WHERE key1 < 3 OR key2 > 1020;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge i1,i2 i1,i2 4,4 NULL 45 Using sort_union(i1,i2); Using where
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t1 WHERE key1 < 3 OR key2 > 1020 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t1`.`key1` AS `key1`,`t1`.`key2` AS `key2`,`t1`.`key3` AS `key3`,`t1`.`key4` AS `key4`,`t1`.`key5` AS `key5`,`t1`.`key6` AS `key6`,`t1`.`key7` AS `key7`,`t1`.`key8` AS `key8` from `t1` where ((`t1`.`key1` < 3) or (`t1`.`key2` > 1020))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t1`.`key1` < 3) or (`t1`.`key2` > 1020))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((`t1`.`key1` < 3) or (`t1`.`key2` > 1020))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((`t1`.`key1` < 3) or (`t1`.`key2` > 1020))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((`t1`.`key1` < 3) or (`t1`.`key2` > 1020))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 217.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "i1",
"usable": true,
"key_parts": [
"key1"
] /* key_parts */
},
{
"index": "i2",
"usable": true,
"key_parts": [
"key2"
] /* key_parts */
},
{
"index": "i3",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i4",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i5",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i6",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i7",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i8",
"usable": false,
"cause": "not_applicable"
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"analyzing_index_merge": [
{
"indices_to_merge": [
{
"range_scan_alternatives": [
{
"index": "i1",
"ranges": [
"key1 < 3"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
"rows": 3,
"cost": 1.6526,
"chosen": true
}
] /* range_scan_alternatives */,
"index_to_merge": "i1",
"cumulated_cost": 1.6526
},
{
"range_scan_alternatives": [
{
"index": "i2",
"ranges": [
"1020 < key2"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
"rows": 42,
"cost": 10.282,
"chosen": true
}
] /* range_scan_alternatives */,
"index_to_merge": "i2",
"cumulated_cost": 11.935
}
] /* indices_to_merge */,
"cost_of_reading_ranges": 11.935,
"cost_sort_rowid_and_read_disk": 8.0666,
"cost_duplicate_removal": 38.361,
"total_cost": 58.363
}
] /* analyzing_index_merge */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "index_merge",
"index_merge_of": [
{
"type": "range_scan",
"index": "i1",
"rows": 3,
"ranges": [
"key1 < 3"
] /* ranges */
},
{
"type": "range_scan",
"index": "i2",
"rows": 42,
"ranges": [
"1020 < key2"
] /* ranges */
}
] /* index_merge_of */
} /* range_access_plan */,
"rows_for_plan": 45,
"cost_for_plan": 58.363,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "range",
"rows": 45,
"cost": 67.363,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 67.363,
"rows_for_plan": 45,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t1`.`key1` < 3) or (`t1`.`key2` > 1020))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "((`t1`.`key1` < 3) or (`t1`.`key2` > 1020))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t1`",
"access_type": "range"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT key2, MIN(key2_1) FROM t2 GROUP BY key2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range i2_1,i2_2 i2_1 4 NULL 103 Using index for group-by
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT key2, MIN(key2_1) FROM t2 GROUP BY key2 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t2`.`key2` AS `key2`,min(`t2`.`key2_1`) AS `MIN(key2_1)` from `t2` group by `t2`.`key2`"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"table_dependencies": [
{
"table": "`t2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"rows_estimation": [
{
"table": "`t2`",
"const_keys_added": {
"keys": [
"i2_1",
"i2_2"
] /* keys */,
"cause": "group_by"
} /* const_keys_added */,
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 215.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "PRIMARY",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i1b",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i2_1",
"usable": true,
"key_parts": [
"key2",
"key2_1"
] /* key_parts */
},
{
"index": "i2_2",
"usable": true,
"key_parts": [
"key2",
"key2_1"
] /* key_parts */
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "i2_1",
"cost": 235.03,
"chosen": false,
"cause": "cost"
} /* best_covering_index_scan */,
"group_index_range": {
"potential_group_range_indices": [
{
"index": "PRIMARY",
"usable": false,
"cause": "not_covering"
},
{
"index": "i1b",
"usable": false,
"cause": "not_covering"
},
{
"index": "i2_1",
"covering": true,
"rows": 103,
"cost": 71.2
},
{
"index": "i2_2",
"covering": true,
"rows": 103,
"cost": 71.2
}
] /* potential_group_range_indices */
} /* group_index_range */,
"best_group_range_summary": {
"type": "index_group",
"index": "i2_1",
"group_attribute": "key2_1",
"min_aggregate": true,
"max_aggregate": false,
"distinct_aggregate": false,
"rows": 103,
"cost": 71.2,
"key_parts_used_for_access": [
"key2"
] /* key_parts_used_for_access */,
"ranges": [
] /* ranges */,
"chosen": true
} /* best_group_range_summary */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "index_group",
"index": "i2_1",
"group_attribute": "key2_1",
"min_aggregate": true,
"max_aggregate": false,
"distinct_aggregate": false,
"rows": 103,
"cost": 71.2,
"key_parts_used_for_access": [
"key2"
] /* key_parts_used_for_access */,
"ranges": [
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 103,
"cost_for_plan": 71.2,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t2`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "range",
"rows": 103,
"cost": 91.8,
"chosen": true,
"use_tmp_table": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 91.8,
"rows_for_plan": 103,
"sort_cost": 103,
"new_cost_for_plan": 194.8,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": null,
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t2`",
"attached": null
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"clause_processing": {
"clause": "GROUP BY",
"original_clause": "`t2`.`key2`",
"items": [
{
"item": "`t2`.`key2`"
}
] /* items */,
"resulting_clause_is_simple": true,
"resulting_clause": "`t2`.`key2`"
} /* clause_processing */
},
{
"refine_plan": [
{
"table": "`t2`",
"access_type": "range"
}
] /* refine_plan */
},
{
"reconsidering_access_paths_for_index_ordering": {
"clause": "GROUP BY",
"index_order_summary": {
"table": "`t2`",
"index_provides_order": true,
"order_direction": "asc",
"index": "i2_1",
"plan_changed": false
} /* index_order_summary */
} /* reconsidering_access_paths_for_index_ordering */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT DISTINCT key2 FROM t2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range i2_1,i2_2 i2_1 4 NULL 103 Using index for group-by
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT DISTINCT key2 FROM t2 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select distinct `t2`.`key2` AS `key2` from `t2`"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"table_dependencies": [
{
"table": "`t2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"rows_estimation": [
{
"table": "`t2`",
"const_keys_added": {
"keys": [
"i2_1",
"i2_2"
] /* keys */,
"cause": "distinct"
} /* const_keys_added */,
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 215.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "PRIMARY",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i1b",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i2_1",
"usable": true,
"key_parts": [
"key2",
"key2_1"
] /* key_parts */
},
{
"index": "i2_2",
"usable": true,
"key_parts": [
"key2",
"key2_1"
] /* key_parts */
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "i2_1",
"cost": 235.03,
"chosen": false,
"cause": "cost"
} /* best_covering_index_scan */,
"group_index_range": {
"distinct_query": true,
"potential_group_range_indices": [
{
"index": "PRIMARY",
"usable": false,
"cause": "not_covering"
},
{
"index": "i1b",
"usable": false,
"cause": "not_covering"
},
{
"index": "i2_1",
"covering": true,
"rows": 103,
"cost": 71.2
},
{
"index": "i2_2",
"covering": true,
"rows": 103,
"cost": 71.2
}
] /* potential_group_range_indices */
} /* group_index_range */,
"best_group_range_summary": {
"type": "index_group",
"index": "i2_1",
"group_attribute": null,
"min_aggregate": false,
"max_aggregate": false,
"distinct_aggregate": false,
"rows": 103,
"cost": 71.2,
"key_parts_used_for_access": [
"key2"
] /* key_parts_used_for_access */,
"ranges": [
] /* ranges */,
"chosen": true
} /* best_group_range_summary */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "index_group",
"index": "i2_1",
"group_attribute": null,
"min_aggregate": false,
"max_aggregate": false,
"distinct_aggregate": false,
"rows": 103,
"cost": 71.2,
"key_parts_used_for_access": [
"key2"
] /* key_parts_used_for_access */,
"ranges": [
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 103,
"cost_for_plan": 71.2,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t2`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "range",
"rows": 103,
"cost": 91.8,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 91.8,
"rows_for_plan": 103,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": null,
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t2`",
"attached": null
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"clause_processing": {
"clause": "GROUP BY",
"original_clause": "`t2`.`key2`",
"items": [
{
"item": "`t2`.`key2`"
}
] /* items */,
"resulting_clause_is_simple": true,
"resulting_clause": "`t2`.`key2`"
} /* clause_processing */
},
{
"refine_plan": [
{
"table": "`t2`",
"access_type": "range"
}
] /* refine_plan */
},
{
"reconsidering_access_paths_for_index_ordering": {
"clause": "GROUP BY",
"index_order_summary": {
"table": "`t2`",
"index_provides_order": true,
"order_direction": "asc",
"index": "i2_1",
"plan_changed": false
} /* index_order_summary */
} /* reconsidering_access_paths_for_index_ordering */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT key2, MIN(key2_1) FROM t2
WHERE key2 = 5 or key2 = 4 or key2 = 3 or key2 = 2 or key2 = 1
GROUP BY key2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range i2_1,i2_2 i2_1 4 NULL 47 Using where; Using index
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT key2, MIN(key2_1) FROM t2
WHERE key2 = 5 or key2 = 4 or key2 = 3 or key2 = 2 or key2 = 1
GROUP BY key2 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t2`.`key2` AS `key2`,min(`t2`.`key2_1`) AS `MIN(key2_1)` from `t2` where ((`t2`.`key2` = 5) or (`t2`.`key2` = 4) or (`t2`.`key2` = 3) or (`t2`.`key2` = 2) or (`t2`.`key2` = 1)) group by `t2`.`key2`"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t2`.`key2` = 5) or (`t2`.`key2` = 4) or (`t2`.`key2` = 3) or (`t2`.`key2` = 2) or (`t2`.`key2` = 1))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(multiple equal(5, `t2`.`key2`) or multiple equal(4, `t2`.`key2`) or multiple equal(3, `t2`.`key2`) or multiple equal(2, `t2`.`key2`) or multiple equal(1, `t2`.`key2`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(multiple equal(5, `t2`.`key2`) or multiple equal(4, `t2`.`key2`) or multiple equal(3, `t2`.`key2`) or multiple equal(2, `t2`.`key2`) or multiple equal(1, `t2`.`key2`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "(multiple equal(5, `t2`.`key2`) or multiple equal(4, `t2`.`key2`) or multiple equal(3, `t2`.`key2`) or multiple equal(2, `t2`.`key2`) or multiple equal(1, `t2`.`key2`))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t2`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 215.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "PRIMARY",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i1b",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i2_1",
"usable": true,
"key_parts": [
"key2",
"key2_1"
] /* key_parts */
},
{
"index": "i2_2",
"usable": true,
"key_parts": [
"key2",
"key2_1"
] /* key_parts */
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "i2_1",
"cost": 235.03,
"chosen": false,
"cause": "cost"
} /* best_covering_index_scan */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"potential_group_range_indices": [
{
"index": "PRIMARY",
"usable": false,
"cause": "not_covering"
},
{
"index": "i1b",
"usable": false,
"cause": "not_covering"
},
{
"index": "i2_1",
"covering": true,
"index_dives_for_eq_ranges": true,
"ranges": [
"1 <= key2 <= 1",
"2 <= key2 <= 2",
"3 <= key2 <= 3",
"4 <= key2 <= 4",
"5 <= key2 <= 5"
] /* ranges */,
"rows": 5,
"cost": 32
},
{
"index": "i2_2",
"covering": true,
"index_dives_for_eq_ranges": true,
"ranges": [
"1 <= key2 <= 1",
"2 <= key2 <= 2",
"3 <= key2 <= 3",
"4 <= key2 <= 4",
"5 <= key2 <= 5"
] /* ranges */,
"rows": 5,
"cost": 32
}
] /* potential_group_range_indices */
} /* group_index_range */,
"best_group_range_summary": {
"type": "index_group",
"index": "i2_1",
"group_attribute": "key2_1",
"min_aggregate": true,
"max_aggregate": false,
"distinct_aggregate": false,
"rows": 5,
"cost": 32,
"key_parts_used_for_access": [
"key2"
] /* key_parts_used_for_access */,
"ranges": [
"1 <= key2 <= 1",
"2 <= key2 <= 2",
"3 <= key2 <= 3",
"4 <= key2 <= 4",
"5 <= key2 <= 5"
] /* ranges */,
"chosen": true
} /* best_group_range_summary */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "i2_1",
"ranges": [
"1 <= key2 <= 1",
"2 <= key2 <= 2",
"3 <= key2 <= 3",
"4 <= key2 <= 4",
"5 <= key2 <= 5"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
"rows": 47,
"cost": 11.724,
"chosen": true
},
{
"index": "i2_2",
"ranges": [
"1 <= key2 <= 1",
"2 <= key2 <= 2",
"3 <= key2 <= 3",
"4 <= key2 <= 4",
"5 <= key2 <= 5"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
"rows": 47,
"cost": 11.724,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "i2_1",
"rows": 47,
"ranges": [
"1 <= key2 <= 1",
"2 <= key2 <= 2",
"3 <= key2 <= 3",
"4 <= key2 <= 4",
"5 <= key2 <= 5"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 47,
"cost_for_plan": 11.724,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t2`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "range",
"rows": 5,
"cost": 21.124,
"chosen": true,
"use_tmp_table": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 21.124,
"rows_for_plan": 5,
"sort_cost": 5,
"new_cost_for_plan": 26.124,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t2`.`key2` = 5) or (`t2`.`key2` = 4) or (`t2`.`key2` = 3) or (`t2`.`key2` = 2) or (`t2`.`key2` = 1))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t2`",
"attached": "((`t2`.`key2` = 5) or (`t2`.`key2` = 4) or (`t2`.`key2` = 3) or (`t2`.`key2` = 2) or (`t2`.`key2` = 1))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"clause_processing": {
"clause": "GROUP BY",
"original_clause": "`t2`.`key2`",
"items": [
{
"item": "`t2`.`key2`"
}
] /* items */,
"resulting_clause_is_simple": true,
"resulting_clause": "`t2`.`key2`"
} /* clause_processing */
},
{
"refine_plan": [
{
"table": "`t2`",
"access_type": "range"
}
] /* refine_plan */
},
{
"reconsidering_access_paths_for_index_ordering": {
"clause": "GROUP BY",
"index_order_summary": {
"table": "`t2`",
"index_provides_order": true,
"order_direction": "asc",
"index": "i2_1",
"plan_changed": false
} /* index_order_summary */
} /* reconsidering_access_paths_for_index_ordering */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT * FROM t2 WHERE key2 = 1 AND (key2_1 = 1 OR key3 = 5);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref i2_1,i2_2 i2_1 4 const 10 Using where
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t2 WHERE key2 = 1 AND (key2_1 = 1 OR key3 = 5) {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t2`.`key1a` AS `key1a`,`t2`.`key1b` AS `key1b`,`t2`.`key2` AS `key2`,`t2`.`key2_1` AS `key2_1`,`t2`.`key2_2` AS `key2_2`,`t2`.`key3` AS `key3` from `t2` where ((`t2`.`key2` = 1) and ((`t2`.`key2_1` = 1) or (`t2`.`key3` = 5)))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t2`.`key2` = 1) and ((`t2`.`key2_1` = 1) or (`t2`.`key3` = 5)))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((multiple equal(1, `t2`.`key2_1`) or multiple equal(5, `t2`.`key3`)) and multiple equal(1, `t2`.`key2`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((multiple equal(1, `t2`.`key2_1`) or multiple equal(5, `t2`.`key3`)) and multiple equal(1, `t2`.`key2`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((multiple equal(1, `t2`.`key2_1`) or multiple equal(5, `t2`.`key3`)) and multiple equal(1, `t2`.`key2`))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
{
"table": "`t2`",
"field": "key2",
"equals": "1",
"null_rejecting": false
},
{
"table": "`t2`",
"field": "key2",
"equals": "1",
"null_rejecting": false
}
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t2`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 215.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "PRIMARY",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i1b",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i2_1",
"usable": true,
"key_parts": [
"key2",
"key2_1"
] /* key_parts */
},
{
"index": "i2_2",
"usable": true,
"key_parts": [
"key2",
"key2_1"
] /* key_parts */
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "i2_1",
"ranges": [
"1 <= key2 <= 1"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 10,
"cost": 13.01,
"chosen": true
},
{
"index": "i2_2",
"ranges": [
"1 <= key2 <= 1"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 10,
"cost": 13.01,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "i2_1",
"rows": 10,
"ranges": [
"1 <= key2 <= 1"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 10,
"cost_for_plan": 13.01,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t2`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "i2_1",
"rows": 10,
"cost": 12,
"chosen": true
},
{
"access_type": "ref",
"index": "i2_2",
"rows": 10,
"cost": 12,
"chosen": false
},
{
"access_type": "range",
"cause": "heuristic_index_cheaper",
"chosen": false
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 12,
"rows_for_plan": 10,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t2`.`key2` = 1) and ((`t2`.`key2_1` = 1) or (`t2`.`key3` = 5)))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t2`",
"attached": "((`t2`.`key2_1` = 1) or (`t2`.`key3` = 5))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t2`"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT * FROM t1 WHERE key2=10 OR key3=3 OR key4 <=> null;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge i2,i3,i4 i2,i3 4,4 NULL 2 Using union(i2,i3); Using where
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t1 WHERE key2=10 OR key3=3 OR key4 <=> null {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t1`.`key1` AS `key1`,`t1`.`key2` AS `key2`,`t1`.`key3` AS `key3`,`t1`.`key4` AS `key4`,`t1`.`key5` AS `key5`,`t1`.`key6` AS `key6`,`t1`.`key7` AS `key7`,`t1`.`key8` AS `key8` from `t1` where ((`t1`.`key2` = 10) or (`t1`.`key3` = 3) or (`t1`.`key4` <=> NULL))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t1`.`key2` = 10) or (`t1`.`key3` = 3) or (`t1`.`key4` <=> NULL))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(multiple equal(10, `t1`.`key2`) or multiple equal(3, `t1`.`key3`) or (`t1`.`key4` <=> NULL))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(multiple equal(10, `t1`.`key2`) or multiple equal(3, `t1`.`key3`) or (`t1`.`key4` <=> NULL))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "(multiple equal(10, `t1`.`key2`) or multiple equal(3, `t1`.`key3`) or (`t1`.`key4` <=> NULL))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 217.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "i1",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i2",
"usable": true,
"key_parts": [
"key2"
] /* key_parts */
},
{
"index": "i3",
"usable": true,
"key_parts": [
"key3"
] /* key_parts */
},
{
"index": "i4",
"usable": true,
"key_parts": [
"key4"
] /* key_parts */
},
{
"index": "i5",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i6",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i7",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i8",
"usable": false,
"cause": "not_applicable"
}
] /* potential_range_indices */,
"setup_range_conditions": [
{
"impossible_condition": {
"cause": "null_field_in_non_null_column"
} /* impossible_condition */
}
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"analyzing_index_merge": [
{
"indices_to_merge": [
{
"range_scan_alternatives": [
{
"index": "i2",
"ranges": [
"10 <= key2 <= 10"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
"rows": 1,
"cost": 2.21,
"chosen": true
}
] /* range_scan_alternatives */,
"index_to_merge": "i2",
"cumulated_cost": 2.21
},
{
"range_scan_alternatives": [
{
"index": "i3",
"ranges": [
"3 <= key3 <= 3"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
"rows": 1,
"cost": 2.21,
"chosen": true
}
] /* range_scan_alternatives */,
"index_to_merge": "i3",
"cumulated_cost": 4.42
}
] /* indices_to_merge */,
"cost_of_reading_ranges": 4.42,
"use_roworder_union": true,
"cause": "always_cheaper_than_not_roworder_retrieval",
"analyzing_roworder_scans": [
{
"type": "range_scan",
"index": "i2",
"rows": 1,
"ranges": [
"10 <= key2 <= 10"
] /* ranges */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
},
{
"type": "range_scan",
"index": "i3",
"rows": 1,
"ranges": [
"3 <= key3 <= 3"
] /* ranges */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
}
] /* analyzing_roworder_scans */,
"index_roworder_union_cost": 6.327,
"members": 2,
"chosen": true
}
] /* analyzing_index_merge */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "index_roworder_union",
"union_of": [
{
"type": "range_scan",
"index": "i2",
"rows": 1,
"ranges": [
"10 <= key2 <= 10"
] /* ranges */
},
{
"type": "range_scan",
"index": "i3",
"rows": 1,
"ranges": [
"3 <= key3 <= 3"
] /* ranges */
}
] /* union_of */
} /* range_access_plan */,
"rows_for_plan": 2,
"cost_for_plan": 6.327,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "range",
"rows": 2,
"cost": 6.727,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 6.727,
"rows_for_plan": 2,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t1`.`key2` = 10) or (`t1`.`key3` = 3) or (`t1`.`key4` <=> NULL))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "((`t1`.`key2` = 10) or (`t1`.`key3` = 3) or (`t1`.`key4` <=> NULL))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t1`",
"access_type": "range"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT * FROM t2 WHERE key2_1 < 79 OR key2 = 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL i2_1,i2_2 NULL NULL NULL 1024 Using where
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t2 WHERE key2_1 < 79 OR key2 = 2 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t2`.`key1a` AS `key1a`,`t2`.`key1b` AS `key1b`,`t2`.`key2` AS `key2`,`t2`.`key2_1` AS `key2_1`,`t2`.`key2_2` AS `key2_2`,`t2`.`key3` AS `key3` from `t2` where ((`t2`.`key2_1` < 79) or (`t2`.`key2` = 2))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t2`.`key2_1` < 79) or (`t2`.`key2` = 2))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((`t2`.`key2_1` < 79) or multiple equal(2, `t2`.`key2`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((`t2`.`key2_1` < 79) or multiple equal(2, `t2`.`key2`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((`t2`.`key2_1` < 79) or multiple equal(2, `t2`.`key2`))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t2`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 215.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "PRIMARY",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i1b",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i2_1",
"usable": true,
"key_parts": [
"key2",
"key2_1"
] /* key_parts */
},
{
"index": "i2_2",
"usable": true,
"key_parts": [
"key2",
"key2_1"
] /* key_parts */
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"range_scan_possible": false,
"cause": "condition_always_true",
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t2`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "scan",
"rows": 1024,
"cost": 213.05,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 213.05,
"rows_for_plan": 1024,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t2`.`key2_1` < 79) or (`t2`.`key2` = 2))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t2`",
"attached": "((`t2`.`key2_1` < 79) or (`t2`.`key2` = 2))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t2`",
"access_type": "table_scan"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT * FROM t2 WHERE key1a = 5 and key1b < 10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range PRIMARY,i1b PRIMARY 8 NULL 1 Using index condition
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t2 WHERE key1a = 5 and key1b < 10 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t2`.`key1a` AS `key1a`,`t2`.`key1b` AS `key1b`,`t2`.`key2` AS `key2`,`t2`.`key2_1` AS `key2_1`,`t2`.`key2_2` AS `key2_2`,`t2`.`key3` AS `key3` from `t2` where ((`t2`.`key1a` = 5) and (`t2`.`key1b` < 10))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t2`.`key1a` = 5) and (`t2`.`key1b` < 10))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((`t2`.`key1b` < 10) and multiple equal(5, `t2`.`key1a`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((`t2`.`key1b` < 10) and multiple equal(5, `t2`.`key1a`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((`t2`.`key1b` < 10) and multiple equal(5, `t2`.`key1a`))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
{
"table": "`t2`",
"field": "key1a",
"equals": "5",
"null_rejecting": false
}
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t2`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 215.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "PRIMARY",
"usable": true,
"key_parts": [
"key1a",
"key1b"
] /* key_parts */
},
{
"index": "i1b",
"usable": true,
"key_parts": [
"key1b",
"key1a"
] /* key_parts */
},
{
"index": "i2_1",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i2_2",
"usable": false,
"cause": "not_applicable"
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "PRIMARY",
"ranges": [
"5 <= key1a <= 5 AND key1b < 10"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 1,
"cost": 2.21,
"chosen": true
},
{
"index": "i1b",
"ranges": [
"key1b < 10"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 9,
"cost": 11.81,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "PRIMARY",
"rows": 1,
"ranges": [
"5 <= key1a <= 5 AND key1b < 10"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 1,
"cost_for_plan": 2.21,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t2`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "PRIMARY",
"rows": 10,
"cost": 12.24,
"chosen": true
},
{
"access_type": "range",
"rows": 1,
"cost": 2.41,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 2.41,
"rows_for_plan": 1,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t2`.`key1a` = 5) and (`t2`.`key1b` < 10))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t2`",
"attached": "((`t2`.`key1a` = 5) and (`t2`.`key1b` < 10))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t2`",
"pushed_index_condition": "((`t2`.`key1a` = 5) and (`t2`.`key1b` < 10))",
"table_condition_attached": null,
"access_type": "range"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT * FROM t2 WHERE (key1a = 5 and key1b < 10 and key1b > 2) or
(key1a = 4 and key1b < 7 and key1b > 3);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range PRIMARY,i1b PRIMARY 8 NULL 2 Using index condition
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t2 WHERE (key1a = 5 and key1b < 10 and key1b > 2) or
(key1a = 4 and key1b < 7 and key1b > 3) {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t2`.`key1a` AS `key1a`,`t2`.`key1b` AS `key1b`,`t2`.`key2` AS `key2`,`t2`.`key2_1` AS `key2_1`,`t2`.`key2_2` AS `key2_2`,`t2`.`key3` AS `key3` from `t2` where (((`t2`.`key1a` = 5) and (`t2`.`key1b` < 10) and (`t2`.`key1b` > 2)) or ((`t2`.`key1a` = 4) and (`t2`.`key1b` < 7) and (`t2`.`key1b` > 3)))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "(((`t2`.`key1a` = 5) and (`t2`.`key1b` < 10) and (`t2`.`key1b` > 2)) or ((`t2`.`key1a` = 4) and (`t2`.`key1b` < 7) and (`t2`.`key1b` > 3)))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(((`t2`.`key1b` < 10) and (`t2`.`key1b` > 2) and multiple equal(5, `t2`.`key1a`)) or ((`t2`.`key1b` < 7) and (`t2`.`key1b` > 3) and multiple equal(4, `t2`.`key1a`)))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(((`t2`.`key1b` < 10) and (`t2`.`key1b` > 2) and multiple equal(5, `t2`.`key1a`)) or ((`t2`.`key1b` < 7) and (`t2`.`key1b` > 3) and multiple equal(4, `t2`.`key1a`)))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "(((`t2`.`key1b` < 10) and (`t2`.`key1b` > 2) and multiple equal(5, `t2`.`key1a`)) or ((`t2`.`key1b` < 7) and (`t2`.`key1b` > 3) and multiple equal(4, `t2`.`key1a`)))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t2`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 215.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "PRIMARY",
"usable": true,
"key_parts": [
"key1a",
"key1b"
] /* key_parts */
},
{
"index": "i1b",
"usable": true,
"key_parts": [
"key1b",
"key1a"
] /* key_parts */
},
{
"index": "i2_1",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i2_2",
"usable": false,
"cause": "not_applicable"
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "PRIMARY",
"ranges": [
"4 <= key1a <= 4 AND 3 < key1b < 7",
"5 <= key1a <= 5 AND 2 < key1b < 10"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 2,
"cost": 4.41,
"chosen": true
},
{
"index": "i1b",
"ranges": [
"2 < key1b <= 3",
"3 < key1b < 7",
"7 <= key1b < 10"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 6,
"cost": 10.21,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "PRIMARY",
"rows": 2,
"ranges": [
"4 <= key1a <= 4 AND 3 < key1b < 7",
"5 <= key1a <= 5 AND 2 < key1b < 10"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 2,
"cost_for_plan": 4.41,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t2`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "range",
"rows": 2,
"cost": 4.81,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 4.81,
"rows_for_plan": 2,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "(((`t2`.`key1a` = 5) and (`t2`.`key1b` < 10) and (`t2`.`key1b` > 2)) or ((`t2`.`key1a` = 4) and (`t2`.`key1b` < 7) and (`t2`.`key1b` > 3)))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t2`",
"attached": "(((`t2`.`key1a` = 5) and (`t2`.`key1b` < 10) and (`t2`.`key1b` > 2)) or ((`t2`.`key1a` = 4) and (`t2`.`key1b` < 7) and (`t2`.`key1b` > 3)))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t2`",
"pushed_index_condition": "(((`t2`.`key1a` = 5) and (`t2`.`key1b` < 10) and (`t2`.`key1b` > 2)) or ((`t2`.`key1a` = 4) and (`t2`.`key1b` < 7) and (`t2`.`key1b` > 3)))",
"table_condition_attached": null,
"access_type": "range"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT * FROM t2 WHERE (key1b < 10 and key1b > 7) and
(key1a = 4 or key1a = 5);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range PRIMARY,i1b i1b 4 NULL 2 Using index condition
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t2 WHERE (key1b < 10 and key1b > 7) and
(key1a = 4 or key1a = 5) {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t2`.`key1a` AS `key1a`,`t2`.`key1b` AS `key1b`,`t2`.`key2` AS `key2`,`t2`.`key2_1` AS `key2_1`,`t2`.`key2_2` AS `key2_2`,`t2`.`key3` AS `key3` from `t2` where ((`t2`.`key1b` < 10) and (`t2`.`key1b` > 7) and ((`t2`.`key1a` = 4) or (`t2`.`key1a` = 5)))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t2`.`key1b` < 10) and (`t2`.`key1b` > 7) and ((`t2`.`key1a` = 4) or (`t2`.`key1a` = 5)))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((`t2`.`key1b` < 10) and (`t2`.`key1b` > 7) and (multiple equal(4, `t2`.`key1a`) or multiple equal(5, `t2`.`key1a`)))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((`t2`.`key1b` < 10) and (`t2`.`key1b` > 7) and (multiple equal(4, `t2`.`key1a`) or multiple equal(5, `t2`.`key1a`)))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((`t2`.`key1b` < 10) and (`t2`.`key1b` > 7) and (multiple equal(4, `t2`.`key1a`) or multiple equal(5, `t2`.`key1a`)))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t2`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 215.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "PRIMARY",
"usable": true,
"key_parts": [
"key1a",
"key1b"
] /* key_parts */
},
{
"index": "i1b",
"usable": true,
"key_parts": [
"key1b",
"key1a"
] /* key_parts */
},
{
"index": "i2_1",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i2_2",
"usable": false,
"cause": "not_applicable"
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "PRIMARY",
"ranges": [
"4 <= key1a <= 4 AND 7 < key1b < 10",
"5 <= key1a <= 5 AND 7 < key1b < 10"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 2,
"cost": 4.41,
"chosen": true
},
{
"index": "i1b",
"ranges": [
"7 < key1b < 10"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 2,
"cost": 3.41,
"chosen": true
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "i1b",
"rows": 2,
"ranges": [
"7 < key1b < 10"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 2,
"cost_for_plan": 3.41,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t2`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "range",
"rows": 2,
"cost": 3.81,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 3.81,
"rows_for_plan": 2,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t2`.`key1b` < 10) and (`t2`.`key1b` > 7) and ((`t2`.`key1a` = 4) or (`t2`.`key1a` = 5)))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t2`",
"attached": "((`t2`.`key1b` < 10) and (`t2`.`key1b` > 7) and ((`t2`.`key1a` = 4) or (`t2`.`key1a` = 5)))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t2`",
"pushed_index_condition": "((`t2`.`key1b` < 10) and (`t2`.`key1b` > 7) and ((`t2`.`key1a` = 4) or (`t2`.`key1a` = 5)))",
"table_condition_attached": null,
"access_type": "range"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT * FROM t1 WHERE (key1 > 1 OR key2 > 2);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL i1,i2 NULL NULL NULL 1024 Using where
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t1 WHERE (key1 > 1 OR key2 > 2) {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t1`.`key1` AS `key1`,`t1`.`key2` AS `key2`,`t1`.`key3` AS `key3`,`t1`.`key4` AS `key4`,`t1`.`key5` AS `key5`,`t1`.`key6` AS `key6`,`t1`.`key7` AS `key7`,`t1`.`key8` AS `key8` from `t1` where ((`t1`.`key1` > 1) or (`t1`.`key2` > 2))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t1`.`key1` > 1) or (`t1`.`key2` > 2))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((`t1`.`key1` > 1) or (`t1`.`key2` > 2))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((`t1`.`key1` > 1) or (`t1`.`key2` > 2))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((`t1`.`key1` > 1) or (`t1`.`key2` > 2))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 217.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "i1",
"usable": true,
"key_parts": [
"key1"
] /* key_parts */
},
{
"index": "i2",
"usable": true,
"key_parts": [
"key2"
] /* key_parts */
},
{
"index": "i3",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i4",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i5",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i6",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i7",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i8",
"usable": false,
"cause": "not_applicable"
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"analyzing_index_merge": [
{
"indices_to_merge": [
{
"range_scan_alternatives": [
{
"index": "i1",
"ranges": [
"1 < key1"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
"rows": 1023,
"cost": 227.35,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"chosen": false,
"cause": "cost"
},
{
"range_scan_alternatives": [
{
"index": "i2",
"ranges": [
"2 < key2"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
"rows": 1022,
"cost": 227.13,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"chosen": false,
"cause": "cost"
}
] /* indices_to_merge */,
"cost_of_reading_ranges": 0,
"chosen": false,
"cause": "cost"
}
] /* analyzing_index_merge */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "scan",
"rows": 1024,
"cost": 215.05,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 215.05,
"rows_for_plan": 1024,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t1`.`key1` > 1) or (`t1`.`key2` > 2))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "((`t1`.`key1` > 1) or (`t1`.`key2` > 2))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t1`",
"access_type": "table_scan"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT STRAIGHT_JOIN * FROM t1, t2
WHERE t1.key1=t2.key1a AND t1.key2 > 1020;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range i1,i2 i2 4 NULL 42 Using index condition
1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.key1 10 NULL
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT STRAIGHT_JOIN * FROM t1, t2
WHERE t1.key1=t2.key1a AND t1.key2 > 1020 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select straight_join `t1`.`key1` AS `key1`,`t1`.`key2` AS `key2`,`t1`.`key3` AS `key3`,`t1`.`key4` AS `key4`,`t1`.`key5` AS `key5`,`t1`.`key6` AS `key6`,`t1`.`key7` AS `key7`,`t1`.`key8` AS `key8`,`t2`.`key1a` AS `key1a`,`t2`.`key1b` AS `key1b`,`t2`.`key2` AS `key2`,`t2`.`key2_1` AS `key2_1`,`t2`.`key2_2` AS `key2_2`,`t2`.`key3` AS `key3` from `t1` join `t2` where ((`t1`.`key1` = `t2`.`key1a`) and (`t1`.`key2` > 1020))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t1`.`key1` = `t2`.`key1a`) and (`t1`.`key2` > 1020))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((`t1`.`key2` > 1020) and multiple equal(`t1`.`key1`, `t2`.`key1a`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((`t1`.`key2` > 1020) and multiple equal(`t1`.`key1`, `t2`.`key1a`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((`t1`.`key2` > 1020) and multiple equal(`t1`.`key1`, `t2`.`key1a`))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
},
{
"table": "`t2`",
"row_may_be_null": false,
"map_bit": 1,
"depends_on_map_bits": [
0
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
{
"table": "`t1`",
"field": "key1",
"equals": "`t2`.`key1a`",
"null_rejecting": false
},
{
"table": "`t2`",
"field": "key1a",
"equals": "`t1`.`key1`",
"null_rejecting": false
}
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 1024,
"cost": 217.15
} /* table_scan */,
"potential_range_indices": [
{
"index": "i1",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i2",
"usable": true,
"key_parts": [
"key2"
] /* key_parts */
},
{
"index": "i3",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i4",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i5",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i6",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i7",
"usable": false,
"cause": "not_applicable"
},
{
"index": "i8",
"usable": false,
"cause": "not_applicable"
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_single_table"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "i2",
"ranges": [
"1020 < key2"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 42,
"cost": 51.41,
"chosen": true
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "i2",
"rows": 42,
"ranges": [
"1020 < key2"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 42,
"cost_for_plan": 51.41,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
},
{
"table": "`t2`",
"table_scan": {
"rows": 1024,
"cost": 8
} /* table_scan */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "i1",
"usable": false,
"chosen": false
},
{
"access_type": "range",
"rows": 42,
"cost": 59.81,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 59.81,
"rows_for_plan": 42
},
{
"plan_prefix": [
"`t1`"
] /* plan_prefix */,
"table": "`t2`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "PRIMARY",
"rows": 10,
"cost": 432.08,
"chosen": true
},
{
"access_type": "scan",
"using_join_cache": true,
"rows": 768,
"cost": 6510.7,
"chosen": false
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 573.89,
"rows_for_plan": 420
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t2`.`key1a` = `t1`.`key1`) and (`t1`.`key2` > 1020))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "(`t1`.`key2` > 1020)"
},
{
"table": "`t2`",
"attached": null
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t1`",
"pushed_index_condition": "(`t1`.`key2` > 1020)",
"table_condition_attached": null,
"access_type": "range"
},
{
"table": "`t2`"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
DROP TABLE t1,t2;
CREATE TABLE t1 (
cola char(3) not null,
colb char(3) not null,
filler char(200),
key(cola),
key(colb)
);
INSERT INTO t1 VALUES ('foo','bar', 'ZZ'),('fuz','baz', 'ZZ');
Inserting records
EXPLAIN SELECT * FROM t1 WHERE cola = 'foo' AND colb = 'bar';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge cola,colb cola,colb 3,3 NULL 32 Using intersect(cola,colb); Using where
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t1 WHERE cola = 'foo' AND colb = 'bar' {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t1`.`cola` AS `cola`,`t1`.`colb` AS `colb`,`t1`.`filler` AS `filler` from `t1` where ((`t1`.`cola` = 'foo') and (`t1`.`colb` = 'bar'))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t1`.`cola` = 'foo') and (`t1`.`colb` = 'bar'))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(multiple equal('foo', `t1`.`cola`) and multiple equal('bar', `t1`.`colb`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(multiple equal('foo', `t1`.`cola`) and multiple equal('bar', `t1`.`colb`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "(multiple equal('foo', `t1`.`cola`) and multiple equal('bar', `t1`.`colb`))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
{
"table": "`t1`",
"field": "cola",
"equals": "'foo'",
"null_rejecting": false
},
{
"table": "`t1`",
"field": "colb",
"equals": "'bar'",
"null_rejecting": false
}
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 8704,
"cost": 2184.8
} /* table_scan */,
"potential_range_indices": [
{
"index": "cola",
"usable": true,
"key_parts": [
"cola"
] /* key_parts */
},
{
"index": "colb",
"usable": true,
"key_parts": [
"colb"
] /* key_parts */
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "cola",
"ranges": [
"foo <= cola <= foo"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
"rows": 533,
"cost": 640.61,
"chosen": true
},
{
"index": "colb",
"ranges": [
"bar <= colb <= bar"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
"rows": 533,
"cost": 640.61,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"intersecting_indices": [
{
"index": "cola",
"index_scan_cost": 11.231,
"cumulated_index_scan_cost": 11.231,
"disk_sweep_cost": 278.58,
"cumulated_total_cost": 289.81,
"usable": true,
"matching_rows_now": 533,
"isect_covering_with_this_index": false,
"chosen": true
},
{
"index": "colb",
"index_scan_cost": 11.231,
"cumulated_index_scan_cost": 22.462,
"disk_sweep_cost": 28.152,
"cumulated_total_cost": 50.613,
"usable": true,
"matching_rows_now": 32.639,
"isect_covering_with_this_index": false,
"chosen": true
}
] /* intersecting_indices */,
"clustered_pk": {
"clustered_pk_added_to_intersect": false,
"cause": "no_clustered_pk_index"
} /* clustered_pk */,
"rows": 32,
"cost": 50.613,
"covering": false,
"chosen": true
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "index_roworder_intersect",
"rows": 32,
"cost": 50.613,
"covering": false,
"clustered_pk_scan": false,
"intersect_of": [
{
"type": "range_scan",
"index": "cola",
"rows": 533,
"ranges": [
"foo <= cola <= foo"
] /* ranges */
},
{
"type": "range_scan",
"index": "colb",
"rows": 533,
"ranges": [
"bar <= colb <= bar"
] /* ranges */
}
] /* intersect_of */
} /* range_access_plan */,
"rows_for_plan": 32,
"cost_for_plan": 50.613,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "cola",
"rows": 533,
"cost": 639.6,
"chosen": true
},
{
"access_type": "ref",
"index": "colb",
"rows": 533,
"cost": 639.6,
"chosen": false
},
{
"access_type": "range",
"rows": 24,
"cost": 57.013,
"chosen": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 57.013,
"rows_for_plan": 24,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t1`.`colb` = 'bar') and (`t1`.`cola` = 'foo'))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "((`t1`.`colb` = 'bar') and (`t1`.`cola` = 'foo'))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t1`",
"access_type": "range"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT * FROM t1 WHERE cola = 'f\no';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref cola cola 3 const 1 Using index condition
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t1 WHERE cola = 'f\no' {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t1`.`cola` AS `cola`,`t1`.`colb` AS `colb`,`t1`.`filler` AS `filler` from `t1` where (`t1`.`cola` = 'f\\no')"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "(`t1`.`cola` = 'f\\no')",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "multiple equal('f\\no', `t1`.`cola`)"
},
{
"transformation": "constant_propagation",
"resulting_condition": "multiple equal('f\\no', `t1`.`cola`)"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "multiple equal('f\\no', `t1`.`cola`)"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
{
"table": "`t1`",
"field": "cola",
"equals": "'f\\no'",
"null_rejecting": false
}
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 8704,
"cost": 2184.8
} /* table_scan */,
"potential_range_indices": [
{
"index": "cola",
"usable": true,
"key_parts": [
"cola"
] /* key_parts */
},
{
"index": "colb",
"usable": false,
"cause": "not_applicable"
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "cola",
"ranges": [
"f\no <= cola <= f\no"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
"rows": 1,
"cost": 2.21,
"chosen": true
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "cola",
"rows": 1,
"ranges": [
"f\no <= cola <= f\no"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 1,
"cost_for_plan": 2.21,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "cola",
"rows": 1,
"cost": 1.2,
"chosen": true
},
{
"access_type": "range",
"cause": "heuristic_index_cheaper",
"chosen": false
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 1.2,
"rows_for_plan": 1,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "(`t1`.`cola` = 'f\\no')",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "(`t1`.`cola` = 'f\\no')"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t1`",
"pushed_index_condition": "(`t1`.`cola` = 'f\\no')",
"table_condition_attached": null
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
DROP TABLE t1;
CREATE TABLE t1(c INT);
INSERT INTO t1 VALUES (),();
CREATE TABLE t2 (b INT, KEY(b));
INSERT INTO t2 VALUES (),(),();
SET optimizer_trace_features="greedy_search=off,dynamic_range=on";
EXPLAIN SELECT 1 FROM
(SELECT 1 FROM t2,t1 WHERE b < c GROUP BY 1 LIMIT 1) AS d2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found
2 DERIVED t1 ALL NULL NULL NULL NULL 2 NULL
2 DERIVED t2 ALL b NULL NULL NULL 3 Range checked for each record (index map: 0x1)
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT 1 FROM
(SELECT 1 FROM t2,t1 WHERE b < c GROUP BY 1 LIMIT 1) AS d2 {
"steps": [
{
"join_preparation": {
"select#": 2,
"steps": [
{
"expanded_query": "/* select#2 */ select 1 AS `1` from `t2` join `t1` where (`t2`.`b` < `t1`.`c`) group by 1 limit 1"
}
] /* steps */
} /* join_preparation */
},
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select 1 AS `1` from (/* select#2 */ select 1 AS `1` from `t2` join `t1` where (`t2`.`b` < `t1`.`c`) group by 1 limit 1) `d2`"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"join_optimization": {
"select#": 2,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "(`t2`.`b` < `t1`.`c`)",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(`t2`.`b` < `t1`.`c`)"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(`t2`.`b` < `t1`.`c`)"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "(`t2`.`b` < `t1`.`c`)"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
},
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 1,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t2`",
"table_scan": {
"rows": 3,
"cost": 2
} /* table_scan */
},
{
"table": "`t1`",
"table_scan": {
"rows": 2,
"cost": 2
} /* table_scan */
}
] /* rows_estimation */
},
{
"considered_execution_plans": "..."
},
{
"attaching_conditions_to_tables": {
"original_condition": "(`t2`.`b` < `t1`.`c`)",
"attached_conditions_computation": [
{
"table": "`t2`",
"rechecking_index_usage": {
"recheck_reason": "not_first_table",
"range_analysis": {
"table_scan": {
"rows": 3,
"cost": 5.6
} /* table_scan */,
"potential_range_indices": [
{
"index": "b",
"usable": true,
"key_parts": [
"b"
] /* key_parts */
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "b",
"cost": 1.6465,
"chosen": true
} /* best_covering_index_scan */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_single_table"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "b",
"chosen": false,
"cause": "unknown"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */
} /* range_analysis */
} /* rechecking_index_usage */
}
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": null
},
{
"table": "`t2`",
"attached": "(`t2`.`b` < `t1`.`c`)"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"clause_processing": {
"clause": "GROUP BY",
"original_clause": "1",
"items": [
{
"item": "1",
"uses_only_constant_tables": true
}
] /* items */,
"resulting_clause_is_simple": true,
"resulting_clause": ""
} /* clause_processing */
},
{
"refine_plan": [
{
"table": "`t1`",
"access_type": "table_scan"
},
{
"table": "`t2`",
"access_type": "dynamic_range"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"creating_tmp_table": {
"tmp_table_info": {
"table": " `d2`",
"row_length": 5,
"key_length": 0,
"unique_constraint": false,
"location": "memory (heap)",
"row_limit_estimate": 209715
} /* tmp_table_info */
} /* creating_tmp_table */
},
{
"join_execution": {
"select#": 2,
"steps": [
{
"rows_estimation_per_outer_row": {
"table": "`t2`",
"range_analysis": {
"table_scan": {
"rows": 3,
"cost": 4.7051
} /* table_scan */,
"potential_range_indices": [
{
"index": "b",
"usable": true,
"key_parts": [
"b"
] /* key_parts */
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "b",
"cost": 1.6465,
"chosen": true
} /* best_covering_index_scan */,
"setup_range_conditions": [
{
"impossible_condition": {
"cause": "comparison_with_null_always_false"
} /* impossible_condition */
}
] /* setup_range_conditions */,
"impossible_range": true
} /* range_analysis */
} /* rows_estimation_per_outer_row */
},
{
"rows_estimation_per_outer_row": {
"table": "`t2`",
"range_analysis": {
"table_scan": {
"rows": 3,
"cost": 4.7051
} /* table_scan */,
"potential_range_indices": [
{
"index": "b",
"usable": true,
"key_parts": [
"b"
] /* key_parts */
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "b",
"cost": 1.6465,
"chosen": true
} /* best_covering_index_scan */,
"setup_range_conditions": [
{
"impossible_condition": {
"cause": "comparison_with_null_always_false"
} /* impossible_condition */
}
] /* setup_range_conditions */,
"impossible_range": true
} /* range_analysis */
} /* rows_estimation_per_outer_row */
}
] /* steps */
} /* join_execution */
},
{
"table_dependencies": [
{
"table": " `d2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"rows_estimation": [
{
"table": " `d2`",
"rows": 1,
"cost": 1,
"table_type": "system",
"empty": true
}
] /* rows_estimation */
},
{
"attaching_conditions_to_tables": {
"original_condition": null,
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
{
"join_explain": {
"select#": 2,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
SET optimizer_trace_features="greedy_search=off,dynamic_range=off";
EXPLAIN SELECT 1 FROM
(SELECT 1 FROM t2,t1 WHERE b < c GROUP BY 1 LIMIT 1) AS d2;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found
2 DERIVED t1 ALL NULL NULL NULL NULL 2 NULL
2 DERIVED t2 ALL b NULL NULL NULL 3 Range checked for each record (index map: 0x1)
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT 1 FROM
(SELECT 1 FROM t2,t1 WHERE b < c GROUP BY 1 LIMIT 1) AS d2 {
"steps": [
{
"join_preparation": {
"select#": 2,
"steps": [
{
"expanded_query": "/* select#2 */ select 1 AS `1` from `t2` join `t1` where (`t2`.`b` < `t1`.`c`) group by 1 limit 1"
}
] /* steps */
} /* join_preparation */
},
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select 1 AS `1` from (/* select#2 */ select 1 AS `1` from `t2` join `t1` where (`t2`.`b` < `t1`.`c`) group by 1 limit 1) `d2`"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"join_optimization": {
"select#": 2,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "(`t2`.`b` < `t1`.`c`)",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(`t2`.`b` < `t1`.`c`)"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(`t2`.`b` < `t1`.`c`)"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "(`t2`.`b` < `t1`.`c`)"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
},
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 1,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t2`",
"table_scan": {
"rows": 3,
"cost": 2
} /* table_scan */
},
{
"table": "`t1`",
"table_scan": {
"rows": 2,
"cost": 2
} /* table_scan */
}
] /* rows_estimation */
},
{
"considered_execution_plans": "..."
},
{
"attaching_conditions_to_tables": {
"original_condition": "(`t2`.`b` < `t1`.`c`)",
"attached_conditions_computation": [
{
"table": "`t2`",
"rechecking_index_usage": {
"recheck_reason": "not_first_table",
"range_analysis": {
"table_scan": {
"rows": 3,
"cost": 5.6
} /* table_scan */,
"potential_range_indices": [
{
"index": "b",
"usable": true,
"key_parts": [
"b"
] /* key_parts */
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "b",
"cost": 1.6465,
"chosen": true
} /* best_covering_index_scan */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_single_table"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "b",
"chosen": false,
"cause": "unknown"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */
} /* range_analysis */
} /* rechecking_index_usage */
}
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": null
},
{
"table": "`t2`",
"attached": "(`t2`.`b` < `t1`.`c`)"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"clause_processing": {
"clause": "GROUP BY",
"original_clause": "1",
"items": [
{
"item": "1",
"uses_only_constant_tables": true
}
] /* items */,
"resulting_clause_is_simple": true,
"resulting_clause": ""
} /* clause_processing */
},
{
"refine_plan": [
{
"table": "`t1`",
"access_type": "table_scan"
},
{
"table": "`t2`",
"access_type": "dynamic_range"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"creating_tmp_table": {
"tmp_table_info": {
"table": " `d2`",
"row_length": 5,
"key_length": 0,
"unique_constraint": false,
"location": "memory (heap)",
"row_limit_estimate": 209715
} /* tmp_table_info */
} /* creating_tmp_table */
},
{
"join_execution": {
"select#": 2,
"steps": [
{
"rows_estimation_per_outer_row": {
"table": "`t2`",
"range_analysis": {
"table_scan": {
"rows": 3,
"cost": 4.7051
} /* table_scan */,
"potential_range_indices": [
{
"index": "b",
"usable": true,
"key_parts": [
"b"
] /* key_parts */
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "b",
"cost": 1.6465,
"chosen": true
} /* best_covering_index_scan */,
"setup_range_conditions": [
{
"impossible_condition": {
"cause": "comparison_with_null_always_false"
} /* impossible_condition */
}
] /* setup_range_conditions */,
"impossible_range": true
} /* range_analysis */
} /* rows_estimation_per_outer_row */
}
] /* steps */
} /* join_execution */
},
{
"table_dependencies": [
{
"table": " `d2`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"rows_estimation": [
{
"table": " `d2`",
"rows": 1,
"cost": 1,
"table_type": "system",
"empty": true
}
] /* rows_estimation */
},
{
"attaching_conditions_to_tables": {
"original_condition": null,
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
{
"join_explain": {
"select#": 2,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
DROP TABLE t1,t2;
SET optimizer_trace_features=default;
CREATE TABLE t1 (
i1 int,
i2 int,
c char(1),
KEY k1 (i1),
KEY k2 (i1, i2)
);
INSERT INTO t1 VALUES (0,1,'2'),(3,2,'1');
EXPLAIN SELECT * FROM t1 WHERE i1 > '2' ORDER BY i1, i2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range k1,k2 k2 5 NULL 2 Using where
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t1 WHERE i1 > '2' ORDER BY i1, i2 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t1`.`i1` AS `i1`,`t1`.`i2` AS `i2`,`t1`.`c` AS `c` from `t1` where (`t1`.`i1` > '2') order by `t1`.`i1`,`t1`.`i2`"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "(`t1`.`i1` > '2')",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(`t1`.`i1` > '2')"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(`t1`.`i1` > '2')"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "(`t1`.`i1` > '2')"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 2,
"cost": 4.5049
} /* table_scan */,
"potential_range_indices": [
{
"index": "k1",
"usable": true,
"key_parts": [
"i1"
] /* key_parts */
},
{
"index": "k2",
"usable": true,
"key_parts": [
"i1",
"i2"
] /* key_parts */
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "k1",
"ranges": [
"2 < i1"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 2,
"cost": 3.41,
"chosen": true
},
{
"index": "k2",
"ranges": [
"2 < i1"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 2,
"cost": 3.41,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "k1",
"rows": 2,
"ranges": [
"2 < i1"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 2,
"cost_for_plan": 3.41,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "range",
"rows": 2,
"cost": 3.81,
"chosen": true,
"use_tmp_table": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 3.81,
"rows_for_plan": 2,
"sort_cost": 2,
"new_cost_for_plan": 5.81,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "(`t1`.`i1` > '2')",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "(`t1`.`i1` > '2')"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"clause_processing": {
"clause": "ORDER BY",
"original_clause": "`t1`.`i1`,`t1`.`i2`",
"items": [
{
"item": "`t1`.`i1`"
},
{
"item": "`t1`.`i2`"
}
] /* items */,
"resulting_clause_is_simple": true,
"resulting_clause": "`t1`.`i1`,`t1`.`i2`"
} /* clause_processing */
},
{
"refine_plan": [
{
"table": "`t1`",
"pushed_index_condition": "(`t1`.`i1` > '2')",
"table_condition_attached": null,
"access_type": "range"
}
] /* refine_plan */
},
{
"reconsidering_access_paths_for_index_ordering": {
"clause": "ORDER BY",
"rows_estimation": {
"table": "`t1`",
"index": "k2",
"range_analysis": {
"table_scan": {
"rows": 2,
"cost": 4.5049
} /* table_scan */,
"potential_range_indices": [
{
"index": "k1",
"usable": false,
"cause": "not_applicable"
},
{
"index": "k2",
"usable": true,
"key_parts": [
"i1",
"i2"
] /* key_parts */
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "k2",
"ranges": [
"2 < i1"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 2,
"cost": 3.41,
"chosen": true
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "k2",
"rows": 2,
"ranges": [
"2 < i1"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 2,
"cost_for_plan": 3.41,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
} /* rows_estimation */,
"index_order_summary": {
"table": "`t1`",
"index_provides_order": true,
"order_direction": "asc",
"disabled_pushed_condition_on_old_index": true,
"index": "k2",
"plan_changed": true,
"access_type": "range"
} /* index_order_summary */
} /* reconsidering_access_paths_for_index_ordering */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
EXPLAIN SELECT DISTINCT i1 FROM t1 WHERE i1 >= '1' ORDER BY i1 DESC;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index k1,k2 k1 5 NULL 2 Using where; Using index
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT DISTINCT i1 FROM t1 WHERE i1 >= '1' ORDER BY i1 DESC {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select distinct `t1`.`i1` AS `i1` from `t1` where (`t1`.`i1` >= '1') order by `t1`.`i1` desc"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "(`t1`.`i1` >= '1')",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(`t1`.`i1` >= '1')"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(`t1`.`i1` >= '1')"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "(`t1`.`i1` >= '1')"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 2,
"cost": 4.5049
} /* table_scan */,
"potential_range_indices": [
{
"index": "k1",
"usable": true,
"key_parts": [
"i1"
] /* key_parts */
},
{
"index": "k2",
"usable": true,
"key_parts": [
"i1",
"i2"
] /* key_parts */
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "k1",
"cost": 1.4233,
"chosen": true
} /* best_covering_index_scan */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"distinct_query": true,
"potential_group_range_indices": [
{
"index": "k1",
"covering": true,
"index_dives_for_eq_ranges": true,
"ranges": [
"1 <= i1"
] /* ranges */,
"rows": 3,
"cost": 1.9
},
{
"index": "k2",
"covering": true,
"index_dives_for_eq_ranges": true,
"ranges": [
"1 <= i1"
] /* ranges */,
"rows": 3,
"cost": 1.9
}
] /* potential_group_range_indices */
} /* group_index_range */,
"best_group_range_summary": {
"type": "index_group",
"index": "k1",
"group_attribute": null,
"min_aggregate": false,
"max_aggregate": false,
"distinct_aggregate": false,
"rows": 3,
"cost": 1.9,
"key_parts_used_for_access": [
"i1"
] /* key_parts_used_for_access */,
"ranges": [
"1 <= i1"
] /* ranges */,
"chosen": false,
"cause": "cost"
} /* best_group_range_summary */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "k1",
"ranges": [
"1 <= i1"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
"rows": 2,
"cost": 3.41,
"chosen": false,
"cause": "cost"
},
{
"index": "k2",
"ranges": [
"1 <= i1"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
"rows": 2,
"cost": 3.41,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "scan",
"rows": 2,
"cost": 2.4049,
"chosen": true,
"use_tmp_table": true
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 2.4049,
"rows_for_plan": 2,
"sort_cost": 2,
"new_cost_for_plan": 4.4049,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "(`t1`.`i1` >= '1')",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "(`t1`.`i1` >= '1')"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"clause_processing": {
"clause": "ORDER BY",
"original_clause": "`t1`.`i1` desc",
"items": [
{
"item": "`t1`.`i1`"
}
] /* items */,
"resulting_clause_is_simple": true,
"resulting_clause": "`t1`.`i1` desc"
} /* clause_processing */
},
{
"reconsidering_access_paths_for_index_ordering": {
"clause": "ORDER BY",
"rows_estimation": {
"table": "`t1`",
"index": "k1",
"range_analysis": {
"table_scan": {
"rows": 2,
"cost": 4.5049
} /* table_scan */,
"potential_range_indices": [
{
"index": "k1",
"usable": true,
"key_parts": [
"i1"
] /* key_parts */
},
{
"index": "k2",
"usable": false,
"cause": "not_applicable"
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "k1",
"cost": 1.4233,
"chosen": true
} /* best_covering_index_scan */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "cannot_do_reverse_ordering"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "k1",
"ranges": [
"1 <= i1"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
"rows": 2,
"cost": 3.41,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */
} /* analyzing_range_alternatives */
} /* range_analysis */
} /* rows_estimation */,
"index_order_summary": {
"table": "`t1`",
"index_provides_order": true,
"order_direction": "desc",
"index": "k1",
"plan_changed": false
} /* index_order_summary */
} /* reconsidering_access_paths_for_index_ordering */
},
{
"reconsidering_access_paths_for_index_ordering": {
"clause": "GROUP BY",
"index_order_summary": {
"table": "`t1`",
"index_provides_order": true,
"order_direction": "desc",
"index": "k1",
"plan_changed": false
} /* index_order_summary */
} /* reconsidering_access_paths_for_index_ordering */
},
{
"clause_processing": {
"clause": "GROUP BY",
"original_clause": "`t1`.`i1` desc",
"items": [
{
"item": "`t1`.`i1`"
}
] /* items */,
"resulting_clause_is_simple": true,
"resulting_clause": "`t1`.`i1` desc"
} /* clause_processing */
},
{
"refine_plan": [
{
"table": "`t1`",
"access_type": "index_scan"
}
] /* refine_plan */
},
{
"reconsidering_access_paths_for_index_ordering": {
"clause": "GROUP BY",
"index_order_summary": {
"table": "`t1`",
"index_provides_order": true,
"order_direction": "desc",
"index": "k1",
"plan_changed": true,
"access_type": "index_scan"
} /* index_order_summary */
} /* reconsidering_access_paths_for_index_ordering */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
DROP TABLE t1;
CREATE TABLE t1 (
pk INT PRIMARY KEY,
i1 INT,
i2 INT,
v varchar(1),
INDEX i1_idx (i1),
INDEX v_idx (v,i1)
) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1, 1, 9,'a'), (2, 2, 8,'b'), (3, 3, 7,'c'),
(4, 4, 6,'d'), (5, 5, 5,'e');
# Covering ROR intersect not chosen: only one scan used
EXPLAIN SELECT v FROM t1 WHERE i1 = 1 AND v = 'a' AND pk < 3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref PRIMARY,i1_idx,v_idx i1_idx 5 const 1 Using index condition; Using where
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT v FROM t1 WHERE i1 = 1 AND v = 'a' AND pk < 3 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t1`.`v` AS `v` from `t1` where ((`t1`.`i1` = 1) and (`t1`.`v` = 'a') and (`t1`.`pk` < 3))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t1`.`i1` = 1) and (`t1`.`v` = 'a') and (`t1`.`pk` < 3))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((`t1`.`pk` < 3) and multiple equal(1, `t1`.`i1`) and multiple equal('a', `t1`.`v`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((`t1`.`pk` < 3) and multiple equal(1, `t1`.`i1`) and multiple equal('a', `t1`.`v`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((`t1`.`pk` < 3) and multiple equal(1, `t1`.`i1`) and multiple equal('a', `t1`.`v`))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
{
"table": "`t1`",
"field": "i1",
"equals": "1",
"null_rejecting": false
},
{
"table": "`t1`",
"field": "v",
"equals": "'a'",
"null_rejecting": false
},
{
"table": "`t1`",
"field": "i1",
"equals": "1",
"null_rejecting": false
}
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 5,
"cost": 4.1
} /* table_scan */,
"potential_range_indices": [
{
"index": "PRIMARY",
"usable": true,
"key_parts": [
"pk"
] /* key_parts */
},
{
"index": "i1_idx",
"usable": true,
"key_parts": [
"i1",
"pk"
] /* key_parts */
},
{
"index": "v_idx",
"usable": true,
"key_parts": [
"v",
"i1",
"pk"
] /* key_parts */
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "v_idx",
"cost": 2.0063,
"chosen": true
} /* best_covering_index_scan */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "PRIMARY",
"ranges": [
"pk < 3"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
"rows": 2,
"cost": 2.41,
"chosen": false,
"cause": "cost"
},
{
"index": "i1_idx",
"ranges": [
"1 <= i1 <= 1 AND pk < 3"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
"rows": 1,
"cost": 2.21,
"chosen": false,
"cause": "cost"
},
{
"index": "v_idx",
"ranges": [
"a <= v <= a AND 1 <= i1 <= 1 AND pk < 3"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
"rows": 1,
"cost": 2.21,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"intersecting_indices": [
{
"index": "v_idx",
"index_scan_cost": 1,
"cumulated_index_scan_cost": 1,
"disk_sweep_cost": 0,
"cumulated_total_cost": 1,
"usable": true,
"matching_rows_now": 1,
"isect_covering_with_this_index": true,
"chosen": true
}
] /* intersecting_indices */,
"clustered_pk": {
"clustered_pk_added_to_intersect": false,
"cause": "roworder_is_covering"
} /* clustered_pk */,
"chosen": false,
"cause": "too_few_indexes_to_merge"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "i1_idx",
"rows": 1,
"cost": 1.2,
"chosen": true
},
{
"access_type": "ref",
"index": "v_idx",
"rows": 1,
"cost": 1.2,
"chosen": false
},
{
"access_type": "scan",
"cost": 2,
"rows": 5,
"cause": "cost",
"chosen": false
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 1.2,
"rows_for_plan": 1,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t1`.`v` = 'a') and (`t1`.`i1` = 1) and (`t1`.`pk` < 3))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "((`t1`.`v` = 'a') and (`t1`.`pk` < 3))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t1`",
"pushed_index_condition": "(`t1`.`pk` < 3)",
"table_condition_attached": "(`t1`.`v` = 'a')"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
DROP INDEX i1_idx ON t1;
CREATE INDEX i1_i2_idx ON t1 (i2,i1);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
# Covering ROR intersect not chosen: cost
EXPLAIN SELECT v FROM t1 WHERE i1 = 1 AND i2 = 1 AND v = 'a' AND pk < 3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref PRIMARY,v_idx,i1_i2_idx v_idx 9 const,const 1 Using index condition; Using where
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT v FROM t1 WHERE i1 = 1 AND i2 = 1 AND v = 'a' AND pk < 3 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t1`.`v` AS `v` from `t1` where ((`t1`.`i1` = 1) and (`t1`.`i2` = 1) and (`t1`.`v` = 'a') and (`t1`.`pk` < 3))"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t1`.`i1` = 1) and (`t1`.`i2` = 1) and (`t1`.`v` = 'a') and (`t1`.`pk` < 3))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((`t1`.`pk` < 3) and multiple equal(1, `t1`.`i1`) and multiple equal(1, `t1`.`i2`) and multiple equal('a', `t1`.`v`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((`t1`.`pk` < 3) and multiple equal(1, `t1`.`i1`) and multiple equal(1, `t1`.`i2`) and multiple equal('a', `t1`.`v`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((`t1`.`pk` < 3) and multiple equal(1, `t1`.`i1`) and multiple equal(1, `t1`.`i2`) and multiple equal('a', `t1`.`v`))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
{
"table": "`t1`",
"field": "v",
"equals": "'a'",
"null_rejecting": false
},
{
"table": "`t1`",
"field": "i1",
"equals": "1",
"null_rejecting": false
},
{
"table": "`t1`",
"field": "i2",
"equals": "1",
"null_rejecting": false
},
{
"table": "`t1`",
"field": "i1",
"equals": "1",
"null_rejecting": false
}
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 5,
"cost": 4.1
} /* table_scan */,
"potential_range_indices": [
{
"index": "PRIMARY",
"usable": true,
"key_parts": [
"pk"
] /* key_parts */
},
{
"index": "v_idx",
"usable": true,
"key_parts": [
"v",
"i1",
"pk"
] /* key_parts */
},
{
"index": "i1_i2_idx",
"usable": true,
"key_parts": [
"i2",
"i1",
"pk"
] /* key_parts */
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "PRIMARY",
"ranges": [
"pk < 3"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
"rows": 2,
"cost": 2.41,
"chosen": true
},
{
"index": "v_idx",
"ranges": [
"a <= v <= a AND 1 <= i1 <= 1 AND pk < 3"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
"rows": 1,
"cost": 2.21,
"chosen": true
},
{
"index": "i1_i2_idx",
"ranges": [
"1 <= i2 <= 1 AND 1 <= i1 <= 1 AND pk < 3"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
"rows": 1,
"cost": 2.21,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"intersecting_indices": [
{
"index": "v_idx",
"index_scan_cost": 1,
"cumulated_index_scan_cost": 1,
"disk_sweep_cost": 0.9031,
"cumulated_total_cost": 1.9031,
"usable": true,
"matching_rows_now": 1,
"isect_covering_with_this_index": false,
"chosen": true
},
{
"index": "i1_i2_idx",
"index_scan_cost": 1,
"cumulated_index_scan_cost": 2,
"disk_sweep_cost": 0,
"cumulated_total_cost": 2,
"usable": true,
"matching_rows_now": 0.2,
"isect_covering_with_this_index": true,
"chosen": false,
"cause": "does_not_reduce_cost"
}
] /* intersecting_indices */,
"clustered_pk": {
"index_scan_cost": 0.1,
"cumulated_index_scan_cost": 1.1,
"disk_sweep_cost": 0,
"clustered_pk_scan_added_to_intersect": true,
"cumulated_cost": 1.1
} /* clustered_pk */,
"rows": 1,
"cost": 1.1,
"covering": false,
"chosen": true
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "index_roworder_intersect",
"rows": 1,
"cost": 1.1,
"covering": false,
"clustered_pk_scan": true,
"intersect_of": [
{
"type": "range_scan",
"index": "v_idx",
"rows": 1,
"ranges": [
"a <= v <= a AND 1 <= i1 <= 1 AND pk < 3"
] /* ranges */
}
] /* intersect_of */
} /* range_access_plan */,
"rows_for_plan": 1,
"cost_for_plan": 1.1,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "v_idx",
"rows": 1,
"cost": 1.2,
"chosen": true
},
{
"access_type": "ref",
"index": "i1_i2_idx",
"rows": 1,
"cost": 1.2,
"chosen": false
},
{
"access_type": "range",
"rows": 1,
"cost": 1.3,
"chosen": false
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 1.2,
"rows_for_plan": 1,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t1`.`v` = 'a') and (`t1`.`i2` = 1) and (`t1`.`i1` = 1) and (`t1`.`pk` < 3))",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "((`t1`.`v` = 'a') and (`t1`.`i2` = 1) and (`t1`.`pk` < 3))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"refine_plan": [
{
"table": "`t1`",
"pushed_index_condition": "((`t1`.`v` = 'a') and (`t1`.`pk` < 3))",
"table_condition_attached": "(`t1`.`i2` = 1)"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
DROP TABLE t1;
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a,b), KEY b (b)) ENGINE=InnoDB STATS_PERSISTENT=0;
INSERT INTO t1 VALUES (1,1),(1,2),(1,0),(1,3);
# Test trace for "access_type_changed 'ref' to 'range'"
EXPLAIN SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY,b PRIMARY 8 NULL 1 Using where; Using index
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select max(`t1`.`b`) AS `MAX(b)`,`t1`.`a` AS `a` from `t1` where ((`t1`.`b` < 2) and (`t1`.`a` = 1)) group by `t1`.`a`"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t1`.`b` < 2) and (`t1`.`a` = 1))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "((`t1`.`b` < 2) and multiple equal(1, `t1`.`a`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "((`t1`.`b` < 2) and multiple equal(1, `t1`.`a`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "((`t1`.`b` < 2) and multiple equal(1, `t1`.`a`))"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
{
"table": "`t1`",
"field": "a",
"equals": "1",
"null_rejecting": false
}
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 4,
"cost": 3.9
} /* table_scan */,
"potential_range_indices": [
{
"index": "PRIMARY",
"usable": true,
"key_parts": [
"a",
"b"
] /* key_parts */
},
{
"index": "b",
"usable": true,
"key_parts": [
"b",
"a"
] /* key_parts */
}
] /* potential_range_indices */,
"best_covering_index_scan": {
"index": "b",
"cost": 1.8044,
"chosen": true
} /* best_covering_index_scan */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"potential_group_range_indices": [
{
"index": "PRIMARY",
"covering": true,
"index_dives_for_eq_ranges": true,
"ranges": [
"1 <= a <= 1 AND b < 2"
] /* ranges */,
"rows": 1,
"cost": 1.3
},
{
"index": "b",
"covering": true,
"usable": false,
"cause": "group_attribute_not_prefix_in_index"
}
] /* potential_group_range_indices */
} /* group_index_range */,
"best_group_range_summary": {
"type": "index_group",
"index": "PRIMARY",
"group_attribute": "b",
"min_aggregate": false,
"max_aggregate": true,
"distinct_aggregate": false,
"rows": 1,
"cost": 1.3,
"key_parts_used_for_access": [
"a"
] /* key_parts_used_for_access */,
"ranges": [
"1 <= a <= 1 AND b < 2"
] /* ranges */,
"chosen": true
} /* best_group_range_summary */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "PRIMARY",
"ranges": [
"1 <= a <= 1 AND b < 2"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
"rows": 1,
"cost": 1.21,
"chosen": true
},
{
"index": "b",
"ranges": [
"b < 2"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": true,
"rows": 2,
"cost": 3.41,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "PRIMARY",
"rows": 1,
"ranges": [
"1 <= a <= 1 AND b < 2"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 1,
"cost_for_plan": 1.21,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "PRIMARY",
"rows": 1,
"cost": 1.2,
"chosen": true
},
{
"access_type": "range",
"rows": 1,
"cost": 1.41,
"chosen": false
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 1.2,
"rows_for_plan": 1,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t1`.`a` = 1) and (`t1`.`b` < 2))",
"attached_conditions_computation": [
{
"access_type_changed": {
"table": "`t1`",
"index": "PRIMARY",
"old_type": "ref",
"new_type": "range",
"cause": "uses_more_keyparts"
} /* access_type_changed */
}
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "((`t1`.`a` = 1) and (`t1`.`b` < 2))"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"clause_processing": {
"clause": "GROUP BY",
"original_clause": "`t1`.`a`",
"items": [
{
"item": "`t1`.`a`",
"equals_constant_in_where": true
}
] /* items */,
"resulting_clause_is_simple": true,
"resulting_clause": ""
} /* clause_processing */
},
{
"refine_plan": [
{
"table": "`t1`",
"access_type": "range"
}
] /* refine_plan */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
drop table t1;
#
# Tracing of when test_if_skip_sort_order() switches to another
# index and we abandon ICP,
# see "disabling_pushed_condition_on_old_index" in trace.
#
CREATE TABLE t1 (
c1 VARCHAR(2) NOT NULL,
i1 INTEGER NOT NULL,
c2 VARCHAR(2) NOT NULL,
KEY k1 (c1),
KEY k2 (c1, i1)
);
INSERT INTO t1 VALUES ('0',3,'0'),('0',2,'1');
EXPLAIN SELECT * FROM t1 WHERE c1 = '1' ORDER BY i1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref k1,k2 k2 4 const 1 Using where
SELECT * FROM information_schema.OPTIMIZER_TRACE;
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
EXPLAIN SELECT * FROM t1 WHERE c1 = '1' ORDER BY i1 {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `t1`.`c1` AS `c1`,`t1`.`i1` AS `i1`,`t1`.`c2` AS `c2` from `t1` where (`t1`.`c1` = '1') order by `t1`.`i1`"
}
] /* steps */
} /* join_preparation */
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "(`t1`.`c1` = '1')",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "multiple equal('1', `t1`.`c1`)"
},
{
"transformation": "constant_propagation",
"resulting_condition": "multiple equal('1', `t1`.`c1`)"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "multiple equal('1', `t1`.`c1`)"
}
] /* steps */
} /* condition_processing */
},
{
"table_dependencies": [
{
"table": "`t1`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
] /* depends_on_map_bits */
}
] /* table_dependencies */
},
{
"ref_optimizer_key_uses": [
{
"table": "`t1`",
"field": "c1",
"equals": "'1'",
"null_rejecting": false
},
{
"table": "`t1`",
"field": "c1",
"equals": "'1'",
"null_rejecting": false
}
] /* ref_optimizer_key_uses */
},
{
"rows_estimation": [
{
"table": "`t1`",
"range_analysis": {
"table_scan": {
"rows": 2,
"cost": 4.5098
} /* table_scan */,
"potential_range_indices": [
{
"index": "k1",
"usable": true,
"key_parts": [
"c1"
] /* key_parts */
},
{
"index": "k2",
"usable": true,
"key_parts": [
"c1",
"i1"
] /* key_parts */
}
] /* potential_range_indices */,
"setup_range_conditions": [
] /* setup_range_conditions */,
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
} /* group_index_range */,
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "k1",
"ranges": [
"1 <= c1 <= 1"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
"rows": 1,
"cost": 2.21,
"chosen": true
},
{
"index": "k2",
"ranges": [
"1 <= c1 <= 1"
] /* ranges */,
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 1,
"cost": 2.21,
"chosen": false,
"cause": "cost"
}
] /* range_scan_alternatives */,
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
} /* analyzing_roworder_intersect */
} /* analyzing_range_alternatives */,
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "k1",
"rows": 1,
"ranges": [
"1 <= c1 <= 1"
] /* ranges */
} /* range_access_plan */,
"rows_for_plan": 1,
"cost_for_plan": 2.21,
"chosen": true
} /* chosen_range_access_summary */
} /* range_analysis */
}
] /* rows_estimation */
},
{
"considered_execution_plans": [
{
"plan_prefix": [
] /* plan_prefix */,
"table": "`t1`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "k1",
"rows": 1,
"cost": 1.2,
"chosen": true
},
{
"access_type": "ref",
"index": "k2",
"rows": 1,
"cost": 1.2,
"chosen": false
},
{
"access_type": "range",
"cause": "heuristic_index_cheaper",
"chosen": false
}
] /* considered_access_paths */
} /* best_access_path */,
"cost_for_plan": 1.2,
"rows_for_plan": 1,
"chosen": true
}
] /* considered_execution_plans */
},
{
"attaching_conditions_to_tables": {
"original_condition": "(`t1`.`c1` = '1')",
"attached_conditions_computation": [
] /* attached_conditions_computation */,
"attached_conditions_summary": [
{
"table": "`t1`",
"attached": "(`t1`.`c1` = '1')"
}
] /* attached_conditions_summary */
} /* attaching_conditions_to_tables */
},
{
"clause_processing": {
"clause": "ORDER BY",
"original_clause": "`t1`.`i1`",
"items": [
{
"item": "`t1`.`i1`"
}
] /* items */,
"resulting_clause_is_simple": true,
"resulting_clause": "`t1`.`i1`"
} /* clause_processing */
},
{
"refine_plan": [
{
"table": "`t1`",
"pushed_index_condition": "(`t1`.`c1` = '1')",
"table_condition_attached": null
}
] /* refine_plan */
},
{
"added_back_ref_condition": "((`t1`.`c1` <=> '1'))"
},
{
"reconsidering_access_paths_for_index_ordering": {
"clause": "ORDER BY",
"index_order_summary": {
"table": "`t1`",
"index_provides_order": true,
"order_direction": "asc",
"disabled_pushed_condition_on_old_index": true,
"index": "k2",
"plan_changed": true,
"access_type": "ref"
} /* index_order_summary */
} /* reconsidering_access_paths_for_index_ordering */
}
] /* steps */
} /* join_optimization */
},
{
"join_explain": {
"select#": 1,
"steps": [
] /* steps */
} /* join_explain */
}
] /* steps */
} 0 0
DROP TABLE t1;