Hello Matthew please find optimizer info below. This is for the slow version.
+----+-------------+--------------+------------+-------+------------------+------------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+--------------+------------+-------+------------------+------------+---------+------+------+----------+-------------+
| 1 | SIMPLE | bobnotif0_ | NULL | index | task_id,task_id2 | delete_old | 5 | NULL | 3465 | 0.00 | Using where |
+----+-------------+--------------+------------+-------+------------------+------------+---------+------+------+----------+-------------+
Query:
select bobnotif0_.id as id1_123_,
bobnotif0_.comment as comment2_123_,
bobnotif0_.created_by as created_3_123_,
bobnotif0_.created_date as created_4_123_,
bobnotif0_.document_id as document5_123_,
bobnotif0_.instance_id as instance6_123_,
bobnotif0_.major_version as major_ve7_123_,
bobnotif0_.message as message8_123_,
bobnotif0_.minor_version as minor_ve9_123_,
bobnotif0_.notification as notific10_123_,
bobnotif0_.notification_type as notific11_123_,
bobnotif0_.object_key as object_12_123_,
bobnotif0_.object_record_id as object_13_123_,
bobnotif0_.recipient_id as recipie14_123_,
bobnotif0_.sender_id as sender_15_123_,
bobnotif0_.status as status16_123_,
bobnotif0_.subject as subject17_123_,
bobnotif0_.task_id as task_id18_123_,
bobnotif0_.template_id as templat19_123_,
bobnotif0_.version as version20_123_,
bobnotif0_.workflow_id as workflo21_123_,
bobnotif0_.workflow_step_id as workflo22_123_
from bob_notification bobnotif0_
where bobnotif0_.instance_id=5429
and bobnotif0_.task_id='17952762'
and bobnotif0_.document_id=2924508
order by bobnotif0_.created_date ASC limit 1;
SELECT * FROM information_schema.OPTIMIZER_TRACE\G
*************************** 1. row ***************************
QUERY: select bobnotif0_.id as id1_123_,
bobnotif0_.comment as comment2_123_,
bobnotif0_.created_by as created_3_123_,
bobnotif0_.created_date as created_4_123_,
bobnotif0_.document_id as document5_123_,
bobnotif0_.instance_id as instance6_123_,
bobnotif0_.major_version as major_ve7_123_,
bobnotif0_.message as message8_123_,
bobnotif0_.minor_version as minor_ve9_123_,
bobnotif0_.notification as notific10_123_,
bobnotif0_.notification_type as notific11_123_,
bobnotif0_.object_key as object_12_123_,
bobnotif0_.object_record_id as object_13_123_,
bobnotif0_.recipient_id as recipie14_123_,
bobnotif0_.sender_id as sender_15_123_,
bobnotif0_.status as status16_123_,
bobnotif0_.subject as subject17_123_,
bobnotif0_.task_id as task_id18_123_,
bobnotif0_.template_id as templat19_123_,
bobnotif0_.version as version20_123_,
bobnotif0_.workflow_id as workflo21_123_,
bobnotif0_.workflow_step_id as workflo22_123_
from bob_notification bobnotif0_
where bobnotif0_.instance_id=5429
and bobnotif0_.task_id='17952762'
and bobnotif0_.document_id=2924508
order by bobnotif0_.created_date ASC limit 1
TRACE: {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `bobnotif0_`.`id` AS `id1_123_`,`bobnotif0_`.`comment` AS `comment2_123_`,`bobnotif0_`.`created_by` AS `created_3_123_`,`bobnotif0_`.`created_date` AS `created_4_123_`,`bobnotif0_`.`document_id` AS `document5_123_`,`bobnotif0_`.`instance_id` AS `instance6_123_`,`bobnotif0_`.`major_version` AS `major_ve7_123_`,`bobnotif0_`.`message` AS `message8_123_`,`bobnotif0_`.`minor_version` AS `minor_ve9_123_`,`bobnotif0_`.`notification` AS `notific10_123_`,`bobnotif0_`.`notification_type` AS `notific11_123_`,`bobnotif0_`.`object_key` AS `object_12_123_`,`bobnotif0_`.`object_record_id` AS `object_13_123_`,`bobnotif0_`.`recipient_id` AS `recipie14_123_`,`bobnotif0_`.`sender_id` AS `sender_15_123_`,`bobnotif0_`.`status` AS `status16_123_`,`bobnotif0_`.`subject` AS `subject17_123_`,`bobnotif0_`.`task_id` AS `task_id18_123_`,`bobnotif0_`.`template_id` AS `templat19_123_`,`bobnotif0_`.`version` AS `version20_123_`,`bobnotif0_`.`workflow_id` AS `workflo21_123_`,`bobnotif0_`.`workflow_step_id` AS `workflo22_123_` from `bob_notification` `bobnotif0_` where ((`bobnotif0_`.`instance_id` = 5429) and (`bobnotif0_`.`task_id` = '17952762') and (`bobnotif0_`.`document_id` = 2924508)) order by `bobnotif0_`.`created_date` limit 1"
}
]
}
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "((`bobnotif0_`.`instance_id` = 5429) and (`bobnotif0_`.`task_id` = '17952762') and (`bobnotif0_`.`document_id` = 2924508))",
"steps": [
{
"transformation": "equality_propagation",
"resulting_condition": "(multiple equal(5429, `bobnotif0_`.`instance_id`) and multiple equal('17952762', `bobnotif0_`.`task_id`) and multiple equal(2924508, `bobnotif0_`.`document_id`))"
},
{
"transformation": "constant_propagation",
"resulting_condition": "(multiple equal(5429, `bobnotif0_`.`instance_id`) and multiple equal('17952762', `bobnotif0_`.`task_id`) and multiple equal(2924508, `bobnotif0_`.`document_id`))"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "(multiple equal(5429, `bobnotif0_`.`instance_id`) and multiple equal('17952762', `bobnotif0_`.`task_id`) and multiple equal(2924508, `bobnotif0_`.`document_id`))"
}
]
}
},
{
"substitute_generated_columns": {
}
},
{
"table_dependencies": [
{
"table": "`bob_notification` `bobnotif0_`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
]
}
]
},
{
"ref_optimizer_key_uses": [
{
"table": "`bob_notification` `bobnotif0_`",
"field": "document_id",
"equals": "2924508",
"null_rejecting": false
},
{
"table": "`bob_notification` `bobnotif0_`",
"field": "task_id",
"equals": "'17952762'",
"null_rejecting": false
},
{
"table": "`bob_notification` `bobnotif0_`",
"field": "task_id",
"equals": "'17952762'",
"null_rejecting": false
}
]
},
{
"rows_estimation": [
{
"table": "`bob_notification` `bobnotif0_`",
"range_analysis": {
"table_scan": {
"rows": 24905118,
"cost": 3.47e7
},
"potential_range_indexes": [
{
"index": "PRIMARY",
"usable": false,
"cause": "not_applicable"
},
{
"index": "workflow_id",
"usable": false,
"cause": "not_applicable"
},
{
"index": "delete_old",
"usable": false,
"cause": "not_applicable"
},
{
"index": "recipient_id",
"usable": false,
"cause": "not_applicable"
},
{
"index": "task_id",
"usable": true,
"key_parts": [
"document_id",
"task_id",
"created_date",
"id"
]
},
{
"index": "task_id2",
"usable": true,
"key_parts": [
"task_id",
"id"
]
},
{
"index": "object_key",
"usable": false,
"cause": "not_applicable"
}
],
"setup_range_conditions": [
],
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
},
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "task_id",
"ranges": [
"2924508 <= document_id <= 2924508 AND 0x0800313739353237363200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 <= task_id <= 0x0800313739353237363200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
],
"index_dives_for_eq_ranges": true,
"rowid_ordered": false,
"using_mrr": false,
"index_only": false,
"rows": 9222,
"cost": 11067,
"chosen": true
},
{
"index": "task_id2",
"ranges": [
"0x0800313739353237363200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 <= task_id <= 0x0800313739353237363200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
],
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": false,
"rows": 7188,
"cost": 8626.6,
"chosen": true
}
],
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
}
},
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "task_id2",
"rows": 7188,
"ranges": [
"0x0800313739353237363200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 <= task_id <= 0x0800313739353237363200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
]
},
"rows_for_plan": 7188,
"cost_for_plan": 8626.6,
"chosen": true
}
}
}
]
},
{
"considered_execution_plans": [
{
"plan_prefix": [
],
"table": "`bob_notification` `bobnotif0_`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "task_id",
"rows": 9222,
"cost": 11066,
"chosen": true
},
{
"access_type": "ref",
"index": "task_id2",
"rows": 7188,
"cost": 8625.6,
"chosen": true
},
{
"access_type": "range",
"range_details": {
"used_index": "task_id2"
},
"chosen": false,
"cause": "heuristic_index_cheaper"
}
]
},
"condition_filtering_pct": 7e-4,
"rows_for_plan": 0.05,
"cost_for_plan": 8625.6,
"chosen": true
}
]
},
{
"attaching_conditions_to_tables": {
"original_condition": "((`bobnotif0_`.`document_id` = 2924508) and (`bobnotif0_`.`task_id` = '17952762') and (`bobnotif0_`.`instance_id` = 5429))",
"attached_conditions_computation": [
],
"attached_conditions_summary": [
{
"table": "`bob_notification` `bobnotif0_`",
"attached": "((`bobnotif0_`.`document_id` = 2924508) and (`bobnotif0_`.`instance_id` = 5429))"
}
]
}
},
{
"clause_processing": {
"clause": "ORDER BY",
"original_clause": "`bobnotif0_`.`created_date`",
"items": [
{
"item": "`bobnotif0_`.`created_date`"
}
],
"resulting_clause_is_simple": true,
"resulting_clause": "`bobnotif0_`.`created_date`"
}
},
{
"added_back_ref_condition": "((`bobnotif0_`.`task_id` <=> '17952762') and ((`bobnotif0_`.`document_id` = 2924508) and (`bobnotif0_`.`instance_id` = 5429)))"
},
{
"reconsidering_access_paths_for_index_ordering": {
"clause": "ORDER BY",
"steps": [
],
"index_order_summary": {
"table": "`bob_notification` `bobnotif0_`",
"index_provides_order": true,
"order_direction": "asc",
"index": "delete_old",
"plan_changed": true,
"access_type": "index"
}
}
},
{
"refine_plan": [
{
"table": "`bob_notification` `bobnotif0_`"
}
]
}
]
}
},
{
"join_execution": {
"select#": 1,
"steps": [
]
}
}
]
}
MISSING_BYTES_BEYOND_MAX_MEM_SIZE: 0
INSUFFICIENT_PRIVILEGES: 0