Skip to content

Instantly share code, notes, and snippets.

@mdcallag
Created August 13, 2020 17:11
Show Gist options
  • Save mdcallag/689f6ba73d56c883feb514a5cd27a2da to your computer and use it in GitHub Desktop.
Save mdcallag/689f6ba73d56c883feb514a5cd27a2da to your computer and use it in GitHub Desktop.
explain select /*+ SKIP_SCAN(t) */ x,y,z from t where x=1 and z=1\G'
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t
partitions: NULL
type: range
possible_keys: x1
key: x1
key_len: 12
ref: NULL
rows: 10
filtered: 100.00
Extra: Using where; Using index for skip scan
Interesting parts of optimizer trace:
"skip_scan_range": {
"potential_skip_scan_indexes": [
{
"index": "x1",
"tree_travel_cost": 0.4,
"num_groups": 11,
"rows": 10,
"cost": 10.555
}
]
},
"best_skip_scan_summary": {
"type": "skip_scan",
"index": "x1",
"key_parts_used_for_access": [
"x",
"y",
"z"
],
"prefix ranges": [
"1 <= x <= 1"
],
"range": [
"1 <= z <= 1"
],
"chosen": true
},
"chosen_range_access_summary": {
"range_access_plan": {
"type": "skip_scan",
"index": "x1",
"key_parts_used_for_access": [
"x",
"y",
"z"
],
"prefix ranges": [
"1 <= x <= 1"
],
"range": [
"1 <= z <= 1"
]
},
"rows_for_plan": 10,
"cost_for_plan": 10.555,
"chosen": true
}
Full optimizer trace:
trace: {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select /*+ SKIP_SCAN(`t`@`select#1`) */ `t`.`x` AS `x`,`t`.`y` AS `y`,`t`.`z` AS `z` from `t` where ((`t`.`x` = 1) and (`t`.`z` = 1))"
}
]
}
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`t`.`x` = 1) and (`t`.`z` = 1))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(multiple equal(1, `t`.`x`) and multiple equal(1, `t`.`z`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(multiple equal(1, `t`.`x`) and multiple equal(1, `t`.`z`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "(multiple equal(1, `t`.`x`) and multiple equal(1, `t`.`z`))"
}
]
}
},
{
"substitute_generated_columns": {
}
},
{
"table_dependencies": [
{
"table": "`t`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
]
}
]
},
{
"ref_optimizer_key_uses": [
{
"table": "`t`",
"field": "x",
"equals": "1",
"null_rejecting": false
}
]
},
{
"rows_estimation": [
{
"table": "`t`",
"range_analysis": {
"table_scan": {
"rows": 200,
"cost": 23.35
},
"potential_range_indexes": [
{
"index": "x1",
"usable": true,
"key_parts": [
"x",
"y",
"z"
]
}
],
"best_covering_index_scan": {
"index": "x1",
"cost": 20.359,
"chosen": true
},
"setup_range_conditions": [
],
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
},
"skip_scan_range": {
"potential_skip_scan_indexes": [
{
"index": "x1",
"tree_travel_cost": 0.4,
"num_groups": 11,
"rows": 10,
"cost": 10.555
}
]
},
"best_skip_scan_summary": {
"type": "skip_scan",
"index": "x1",
"key_parts_used_for_access": [
"x",
"y",
"z"
],
"prefix ranges": [
"1 <= x <= 1"
],
"range": [
"1 <= z <= 1"
],
"chosen": true
},
"chosen_range_access_summary": {
"range_access_plan": {
"type": "skip_scan",
"index": "x1",
"key_parts_used_for_access": [
"x",
"y",
"z"
],
"prefix ranges": [
"1 <= x <= 1"
],
"range": [
"1 <= z <= 1"
]
},
"rows_for_plan": 10,
"cost_for_plan": 10.555,
"chosen": true
}
}
}
]
},
{
"considered_execution_plans": [
{
"plan_prefix": [
],
"table": "`t`",
"best_access_path": {
"considered_access_paths": [
{
"rows_to_scan": 10,
"filtering_effect": [
],
"final_filtering_effect": 1,
"access_type": "range",
"range_details": {
"used_index": "index_for_skip_scan(x1)"
},
"resulting_rows": 10,
"cost": 11.555,
"chosen": true
}
]
},
"condition_filtering_pct": 100,
"rows_for_plan": 10,
"cost_for_plan": 11.555,
"chosen": true
}
]
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`t`.`z` = 1) and (`t`.`x` = 1))",
"attached_conditions_computation": [
],
"attached_conditions_summary": [
{
"table": "`t`",
"attached": "((`t`.`z` = 1) and (`t`.`x` = 1))"
}
]
}
},
{
"finalizing_table_conditions": [
{
"table": "`t`",
"original_table_condition": "((`t`.`z` = 1) and (`t`.`x` = 1))",
"final_table_condition ": "((`t`.`z` = 1) and (`t`.`x` = 1))"
}
]
},
{
"refine_plan": [
{
"table": "`t`"
}
]
}
]
}
},
{
"join_explain": {
"select#": 1,
"steps": [
]
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment