Embed presentation
Download as PDF, PPTX


























![ALTER TABLE Country ADD INDEX p (population);EXPLAIN FORMAT=JSONSELECT * FROM Country WHERE continent='Asia' and population > 5000000;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "25.40"},"table": {"table_name": "Country","access_type": "ALL","possible_keys": ["p"],"rows_examined_per_scan": 239,"rows_produced_per_join": 15,"filtered": "6.46",.."attached_condition": "((`world`.`country`.`Continent` = 'Asia') and(`world`.`country`.`Population` > 5000000))"..](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-27-320.jpg&f=jpg&w=240)



![ALTER TABLE Country ADD INDEX p (population);EXPLAIN FORMAT=JSONSELECT * FROM Country WHERE continent='Asia' and population > 5000000;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "25.40"},"table": {"table_name": "Country","access_type": "ALL","possible_keys": ["p"],"rows_examined_per_scan": 239,"rows_produced_per_join": 15,"filtered": "6.46","cost_info": {"read_cost": "23.86","eval_cost": "1.54","prefix_cost": "25.40","data_read_per_join": "3K"},.."attached_condition": "((`world`.`country`.`Continent` = 'Asia') and(`world`.`country`.`Population` > 5000000))"..It’s available but notused. Why?](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-31-320.jpg&f=jpg&w=240)
![SET optimizer_trace="enabled=on";SELECT * FROM Country WHERE continent='Asia' and population > 5000000;SELECT * FROM information_schema.optimizer_trace;{"steps": [{"join_preparation": {"select#": 1,"steps": [{"expanded_query": "/* select#1 */ select `country`.`Code` AS `Code`,`country`.`Name` AS`Name`,`country`.`Continent` AS `Continent`,`country`.`Region` AS `Region`,`country`.`SurfaceArea` AS`SurfaceArea`,`country`.`IndepYear` AS `IndepYear`,`country`.`Population` AS`Population`,`country`.`LifeExpectancy` AS `LifeExpectancy`,`country`.`GNP` AS`GNP`,`country`.`GNPOld` AS `GNPOld`,`country`.`LocalName` AS `LocalName`,`country`.`GovernmentForm`AS `GovernmentForm`,`country`.`HeadOfState` AS `HeadOfState`,`country`.`Capital` AS`Capital`,`country`.`Code2` AS `Code2` from `country` where ((`country`.`Continent` = 'Asia') and(`country`.`Population` > 5000000))"}]}},{"join_optimization": {"select#": 1,"steps": [{"condition_processing": {"condition": "WHERE",Page 1 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-32-320.jpg&f=jpg&w=240)
!["original_condition": "((`country`.`Continent` = 'Asia') and (`country`.`Population` > 5000000))","steps": [{"transformation": "equality_propagation","resulting_condition": "((`country`.`Population` > 5000000) and multiple equal('Asia',`country`.`Continent`))"},{"transformation": "constant_propagation","resulting_condition": "((`country`.`Population` > 5000000) and multiple equal('Asia',`country`.`Continent`))"},{"transformation": "trivial_condition_removal","resulting_condition": "((`country`.`Population` > 5000000) and multiple equal('Asia',`country`.`Continent`))"}]}},{"substitute_generated_columns": {}},{"table_dependencies": [{"table": "`country`","row_may_be_null": false,"map_bit": 0,Page 2 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-33-320.jpg&f=jpg&w=240)
!["depends_on_map_bits": []}]},{"ref_optimizer_key_uses": []},{"rows_estimation": [{"table": "`country`","range_analysis": {"table_scan": {"rows": 239,"cost": 27.5},"potential_range_indexes": [{"index": "PRIMARY","usable": false,"cause": "not_applicable"},{"index": "p","usable": true,"key_parts": ["Population","Code"]Page 3 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-34-320.jpg&f=jpg&w=240)
![}],"setup_range_conditions": [],"group_index_range": {"chosen": false,"cause": "not_group_by_or_distinct"},"analyzing_range_alternatives": {"range_scan_alternatives": [{"index": "p","ranges": ["5000000 < Population"],"index_dives_for_eq_ranges": true,"rowid_ordered": false,"using_mrr": false,"index_only": false,"rows": 108,"cost": 38.06,"chosen": false,"cause": "cost"}],"analyzing_roworder_intersect": {"usable": false,"cause": "too_few_roworder_scans"}}}Aha! It was tooexpensive.Page 4 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-35-320.jpg&f=jpg&w=240)
![}]},{"considered_execution_plans": [{"plan_prefix": [],"table": "`country`","best_access_path": {"considered_access_paths": [{"rows_to_scan": 239,"access_type": "scan","resulting_rows": 239,"cost": 25.4,"chosen": true}]},"condition_filtering_pct": 100,"rows_for_plan": 239,"cost_for_plan": 25.4,"chosen": true}]},{"attaching_conditions_to_tables": {"original_condition": "((`country`.`Continent` =
'Asia') and (`country`.`Population` > 5000000))",Prefer to table scaninsteadPage 5 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-36-320.jpg&f=jpg&w=240)
!["attached_conditions_computation": [],"attached_conditions_summary": [{"table": "`country`","attached": "((`country`.`Continent` = 'Asia') and (`country`.`Population` > 5000000))"}]}},{"refine_plan": [{"table": "`country`"}]}]}},{"join_execution": {"select#": 1,"steps": []}}]}Page 6 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-37-320.jpg&f=jpg&w=240)
![Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 38Why would an index not be used?"analyzing_range_alternatives": {"range_scan_alternatives": [{"index": "p","ranges": ["5000000 < Population"],"index_dives_for_eq_ranges": true,"rowid_ordered": false,"using_mrr": false,"index_only": false,"rows": 108,"cost": 38.06,"chosen": false,"cause": "cost"}],OPTIMIZER TRACE:.."query_block": {"select_id": 1,"cost_info": {"query_cost": "48.86"},"table": {"table_name": "Country","access_type": "range","possible_keys": ["p"],"key": "p",..FORCE INDEX (p):](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-38-320.jpg&f=jpg&w=240)



















![{"query_block": {"select_id": 1,"cost_info": {"query_cost": "25.40"},"table": {"table_name": "country","access_type": "ALL","possible_keys": ["p"],.."cost_info": {"read_cost": "23.86","eval_cost": "1.54","prefix_cost": "25.40","data_read_per_join": "3K"},..CPU CostIO CostTotal Cost](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-58-320.jpg&f=jpg&w=240)













![ALTER TABLE Country ADD INDEX c (continent);EXPLAIN FORMAT=JSON # 50M
SELECT * FROM Country WHERE population > 50000000 AND continent=‘Asia';{"query_block": {"select_id": 1,"cost_info": {"query_cost": "9.60"},"table": {"table_name": "Country","access_type": "ref","possible_keys": ["p","c"],"key": "c","used_key_parts": ["Continent"],"key_length": "1","ref": ["const"],.."attached_condition": "(`world`.`country`.`Population` > 50000000)"..Continent isdetermined to be lowercost.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-72-320.jpg&f=jpg&w=240)
![EXPLAIN FORMAT=JSON # 500MSELECT * FROM Country WHERE continent='Asia' and population > 500000000;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "1.16"},"table": {"table_name": "Country","access_type": "range","possible_keys": ["p","c"],"key": "p","used_key_parts": ["Population"],"key_length": "4",.."attached_condition": "(`world`.`country`.`Continent` = ‘Asia')"..Change the predicate,the query plan changes.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-73-320.jpg&f=jpg&w=240)





![ALTER TABLE Country ADD INDEX p_c (Population, Continent);EXPLAIN FORMAT=JSONSELECT * FROM Country FORCE INDEX (p_c) WHERE continent='Asia' and population >5000000;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "48.86"},"table": {"table_name": "Country","access_type": "range","possible_keys": ["p_c"],"key": "p_c","used_key_parts": ["Population"],"key_length": "4",..Only part of the key isused!](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-79-320.jpg&f=jpg&w=240)

![ALTER TABLE Country ADD INDEX c_p (Continent, Population);
EXPLAIN FORMAT=JSON
SELECT * FROM Country WHERE continent='Asia' and population > 5000000;
{"query_block": {"select_id": 1,"cost_info": {"query_cost": "7.91"},"table": {"table_name": "Country","access_type": "range","possible_keys": ["p","c","p_c","c_p"],"key": "c_p","used_key_parts": ["Continent","Population"],"key_length": “5”,
..All of the key isused](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-81-320.jpg&f=jpg&w=240)




![ALTER TABLE Country ADD INDEX c_p_n (Continent,Population,Name);EXPLAIN FORMAT=JSONSELECT Name FROM Country WHERE continent='Asia' and population > 5000000;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "3.72"},"table": {"table_name": "Country","access_type": "range","possible_keys": [.."c_p_n"],"key": "c_p_n","used_key_parts": ["Continent","Population"],"key_length": "5",.."filtered": "100.00","using_index": true,..Cost is reduced by53%Using index means"covering index"](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-86-320.jpg&f=jpg&w=240)











![ALTER TABLE city ADD INDEX n (name);EXPLAIN FORMAT=JSONSELECT * FROM Country WHERE Code = (SELECT CountryCode FROM City WHERE name=‘Toronto’);{"query_block": {"select_id": 1,"cost_info": {"query_cost": "1.00"},"table": {"table_name": "Country","access_type": "const",.."key": "PRIMARY",..},"optimized_away_subqueries": [{"dependent": false,"cacheable": true,"query_block": {"select_id": 2,"cost_info": {"query_cost": "0.35"},"table": {"table_name": "City","access_type": "ref","possible_keys": ["n"],"key": “n",..First query + itscostSecond query +its cost(misleadingvisualization)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-98-320.jpg&f=jpg&w=240)

![EXPLAIN FORMAT=JSONSELECT * FROM City WHERE CountryCode IN
(SELECT Code FROM Country WHERE Continent = 'Asia');{"query_block": {"select_id": 1,"cost_info": {"query_cost": "327.58"},"nested_loop": [{"table": {"table_name": "Country","access_type": "ref",.."key": "c",.."using_index": true,.."used_columns": ["Code","Continent"..{"table": {"table_name": "City","access_type": "ref","possible_keys": ["CountryCode"],"key": "CountryCode",.."ref": ["world.Country.Code"],..](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-100-320.jpg&f=jpg&w=240)

![ALTER TABLE CountryLanguage ADD INDEX i (isOfficial);EXPLAIN FORMAT=JSON SELECT * FROM Country WHERE Code IN(SELECT CountryCode FROM CountryLanguage WHERE isOfficial=1);{"query_block": {"select_id": 1,"cost_info": {"query_cost": "98.39"},"nested_loop": [{"table": {"table_name": "Country","access_type": "ALL","possible_keys": ["PRIMARY"],.."filtered": "100.00",.."table": {"table_name": "<subquery2>","access_type": "eq_ref","key": "<auto_key>","key_length": "3","ref": ["world.Country.Code"],"rows_examined_per_scan": 1,"materialized_from_subquery": {"using_temporary_table": true,"query_block": {"table": {"table_name": "CountryLanguage","access_type": "ref",.."key": "i",.."using_index": true,..](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-102-320.jpg&f=jpg&w=240)


![ALTER TABLE country ADD INDEX c_n (continent, name);CREATE VIEW vCountry_Asia AS SELECT * FROM Country WHERE Continent='Asia';EXPLAIN FORMAT=JSONSELECT * FROM vCountry_Asia WHERE Name='China';{"query_block": {"select_id": 1,"cost_info": {"query_cost": "0.35"},"table": {"table_name": "country","access_type": "ref","possible_keys": [.."c_n"],"key": "c_n","used_key_parts": ["Continent","Name"],"key_length": "53","ref": ["const","const"],..This is the base tablePredicates from the viewdefinition and querycombined](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-105-320.jpg&f=jpg&w=240)

![CREATE VIEW vCountrys_Per_Continent ASSELECT Continent, COUNT(*) as Count FROM CountryGROUP BY Continent;EXPLAIN FORMAT=JSONSELECT * FROM vCountrys_Per_Continent WHERE Continent='Asia';{"query_block": {"select_id": 1,"cost_info": {"query_cost": "3.64"},"table": {"table_name": "vCountrys_Per_Continent","access_type": "ref","possible_keys": ["<auto_key0>"],"key": "<auto_key0>","used_key_parts": ["Continent"],"key_length": "1","ref": ["const"],.."used_columns": ["Continent","Count"],..This is the view name.."materialized_from_subquery": {"using_temporary_table": true,"dependent": false,"cacheable": true,"query_block": {"select_id": 2,"cost_info": {"query_cost": "25.40"},This is only the cost ofaccessing the materialized tableThis step happens first.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-107-320.jpg&f=jpg&w=240)





![{"query_block": {"select_id": 1,"cost_info": {"query_cost": "2.84"},"table": {"table_name": "my_cte","access_type": "ALL",.."used_columns": ["n"],"materialized_from_subquery": {"using_temporary_table": true,"dependent": false,"cacheable": true,"query_block": {"union_result": {"using_temporary_table": false,....{"dependent": false,"cacheable": true,"query_block": {"select_id": 3,"recursive": true,"cost_info": {"query_cost": "2.72"},"table": {"table_name": "my_cte","access_type": "ALL",.."used_columns": ["n"],"attached_condition":
"(`my_cte`.`n` < 10)"}..Requires atemporary table forintermediate resultsCost per iteration](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-113-320.jpg&f=jpg&w=240)











![EXPLAIN FORMAT=JSONSELECT * FROM City WHERE CountryCode = 'CAN'UNIONSELECT * FROM City WHERE CountryCode = 'USA'{"union_result": {"using_temporary_table": true,"table_name": "<union1,2>","access_type": "ALL","query_specifications": [{"dependent": false,"cacheable": true,"query_block": {"select_id": 1,"cost_info": {"query_cost": "17.15"},"table": {"table_name": "City","access_type": "ref",.."key": "CountryCode",..Temporary table tode-duplicate{"dependent": false,"cacheable": true,"query_block": {"select_id": 2,"cost_info": {"query_cost": "46.15"},"table": {"table_name": "City","access_type": "ref","possible_keys": ["CountryCode"],"key": "CountryCode","used_key_parts": ["CountryCode"],"key_length": "3","ref": ["const"],..](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-125-320.jpg&f=jpg&w=240)

![EXPLAIN FORMAT=JSONSELECT * FROM City WHERE CountryCode = 'CAN'UNION ALLSELECT * FROM City WHERE CountryCode = 'USA'{"query_block": {"union_result": {"using_temporary_table": false,"query_specifications": [{"dependent": false,"cacheable": true,"query_block": {"select_id": 1,"cost_info": {"query_cost": "17.15"},"table": {"table_name": "City","access_type": "ref",.."key": "CountryCode",..{"dependent": false,"cacheable": true,"query_block": {"select_id": 2,"cost_info": {"query_cost": "46.15"},"table": {"table_name": "City","access_type": "ref","possible_keys": ["CountryCode"],"key": "CountryCode","used_key_parts": ["CountryCode"],"key_length": "3","ref": ["const"],..No temporary table](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-127-320.jpg&f=jpg&w=240)




![ALTER TABLE Country DROP INDEX c_p, DROP INDEX c_p_n,ADD INDEX c_p_desc (continent ASC, population DESC);EXPLAIN FORMAT=JSONSELECT * FROM Country WHERE continent IN ('Asia', 'Oceania') AND population > 5000000ORDER BY continent ASC, population DESC;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "15.36"},"ordering_operation": {"using_filesort": false,"table": {"table_name": "Country","access_type": "range",.."key": "c_p_desc","used_key_parts": ["Continent","Population"],"key_length": "5",..TIP: The optimizer does not consider sort cost inevaluating plans. You may need to FORCE INDEX orDROP similar ascending indexes to use it.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-132-320.jpg&f=jpg&w=240)




!["select#": 1,"steps": [{"filesort_information": [{"direction": "asc","table": "`country` IGNORE INDEX (`p_c`) IGNORE INDEX (`p`)","field": "Population"}],"filesort_priority_queue_optimization": {"limit": 10,"chosen": true},"filesort_execution": [],"filesort_summary": {"memory_available": 262144,"key_size": 4,"row_size": 272,"max_rows_per_buffer": 11,"num_rows_estimate": 587,"num_rows_found": 11,"num_examined_rows": 239,"num_tmp_files": 0,"sort_buffer_size": 3080,"sort_algorithm": "std::sort","unpacked_addon_fields": "using_priority_queue","sort_mode": "<fixed_sort_key, additional_fields>”..OPTIMIZER TRACEshowing Priority Queue forsort](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-137-320.jpg&f=jpg&w=240)

!["select#": 1,"steps": [{"filesort_information": [{"direction": "asc","table": "`country` IGNORE INDEX (`p_c`) IGNORE INDEX (`p`)","field": "Population"}],"filesort_priority_queue_optimization": {"usable": false,"cause": "not applicable (no LIMIT)"},"filesort_execution": [],"filesort_summary": {"memory_available": 262144,"key_size": 4,"row_size": 274,"max_rows_per_buffer": 587,"num_rows_estimate": 587,"num_rows_found": 239,"num_examined_rows": 239,"num_tmp_files": 0,"sort_buffer_size": 165536,"sort_algorithm": "std::stable_sort","sort_mode": "<fixed_sort_key, packed_additional_fields>"..Not Using Priority Sort](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-139-320.jpg&f=jpg&w=240)




![EXPLAIN FORMAT=JSONSELECT * FROM CountryLanguage WHERE isOfficial='T' ANDCountryCode='CAN';{"query_block": {"select_id": 1,"cost_info": {"query_cost": "2.40"},"table": {"table_name": "CountryLanguage","partitions": ["pOfficial"],"access_type": "ref",.."key": "PRIMARY",..Only accesses onepartition](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-144-320.jpg&f=jpg&w=240)














![Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 159No, due to clustered Index!FORCE INDEX (a) WHERE a=‘1234' AND id=1234;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "0.35"},"table": {"table_name": "t1","access_type": "const","possible_keys": ["a"],"key": "a","used_key_parts": ["a","id"],..FORCE INDEX (ab) WHERE a='1234' AND id=1234;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "11.80"},"table": {"table_name": "t1","access_type": "ref","possible_keys": ["ab"],"key": "ab","used_key_parts": ["a"],..](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-159-320.jpg&f=jpg&w=240)









![ALTER TABLE CountryJSON ADD Name char(52) AS (doc->>"$.Name"),ADD INDEX n (Name);EXPLAIN FORMAT=JSONSELECT * FROM CountryJSON where doc->>"$.Name" = ‘Canada';{"query_block": {"select_id": 1,"cost_info": {"query_cost": "1.20"},"table": {"table_name": "CountryJSON","access_type": "ref",.."key": "n",.."key_length": "53","ref": ["const"],..Key from virtual columnMatches expression fromindexed virtual column](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-169-320.jpg&f=jpg&w=240)




![{"query_block": {"select_id": 1,"cost_info": {"query_cost": "0.35"},"table": {"table_name": "Country","access_type": "ref","possible_keys": ["n"],"key": "n","used_key_parts": ["Name"],"key_length": "52",.."rows_examined_per_scan": 1,"rows_produced_per_join": 1,"filtered": "100.00","cost_info": {"read_cost": "0.25","eval_cost": "0.10","prefix_cost": "0.35","data_read_per_join": "264"},..{"query_block": {"select_id": 1,"cost_info": {"query_cost": "0.35"},"table": {"table_name": "Country","access_type": "ref","possible_keys": ["n"],"key": "n","used_key_parts": ["Name"],"key_length": "208",.."rows_examined_per_scan": 1,"rows_produced_per_join": 1,"filtered": "100.00","cost_info": {"read_cost": "0.25","eval_cost": "0.10","prefix_cost": "0.35","data_read_per_join": "968"},..Key length as latin1 Key length as utf8](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-174-320.jpg&f=jpg&w=240)



The document is an introduction to the MySQL 8.0 optimizer guide. It includes a safe harbor statement noting that the guide outlines Oracle's general product direction but not commitments. The agenda lists 25 topics to be covered related to query optimization, diagnostic commands, examples from the "World Schema" sample database, and a companion website with more details.


























![ALTER TABLE Country ADD INDEX p (population);EXPLAIN FORMAT=JSONSELECT * FROM Country WHERE continent='Asia' and population > 5000000;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "25.40"},"table": {"table_name": "Country","access_type": "ALL","possible_keys": ["p"],"rows_examined_per_scan": 239,"rows_produced_per_join": 15,"filtered": "6.46",.."attached_condition": "((`world`.`country`.`Continent` = 'Asia') and(`world`.`country`.`Population` > 5000000))"..](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-27-320.jpg&f=jpg&w=240)



![ALTER TABLE Country ADD INDEX p (population);EXPLAIN FORMAT=JSONSELECT * FROM Country WHERE continent='Asia' and population > 5000000;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "25.40"},"table": {"table_name": "Country","access_type": "ALL","possible_keys": ["p"],"rows_examined_per_scan": 239,"rows_produced_per_join": 15,"filtered": "6.46","cost_info": {"read_cost": "23.86","eval_cost": "1.54","prefix_cost": "25.40","data_read_per_join": "3K"},.."attached_condition": "((`world`.`country`.`Continent` = 'Asia') and(`world`.`country`.`Population` > 5000000))"..It’s available but notused. Why?](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-31-320.jpg&f=jpg&w=240)
![SET optimizer_trace="enabled=on";SELECT * FROM Country WHERE continent='Asia' and population > 5000000;SELECT * FROM information_schema.optimizer_trace;{"steps": [{"join_preparation": {"select#": 1,"steps": [{"expanded_query": "/* select#1 */ select `country`.`Code` AS `Code`,`country`.`Name` AS`Name`,`country`.`Continent` AS `Continent`,`country`.`Region` AS `Region`,`country`.`SurfaceArea` AS`SurfaceArea`,`country`.`IndepYear` AS `IndepYear`,`country`.`Population` AS`Population`,`country`.`LifeExpectancy` AS `LifeExpectancy`,`country`.`GNP` AS`GNP`,`country`.`GNPOld` AS `GNPOld`,`country`.`LocalName` AS `LocalName`,`country`.`GovernmentForm`AS `GovernmentForm`,`country`.`HeadOfState` AS `HeadOfState`,`country`.`Capital` AS`Capital`,`country`.`Code2` AS `Code2` from `country` where ((`country`.`Continent` = 'Asia') and(`country`.`Population` > 5000000))"}]}},{"join_optimization": {"select#": 1,"steps": [{"condition_processing": {"condition": "WHERE",Page 1 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-32-320.jpg&f=jpg&w=240)
!["original_condition": "((`country`.`Continent` = 'Asia') and (`country`.`Population` > 5000000))","steps": [{"transformation": "equality_propagation","resulting_condition": "((`country`.`Population` > 5000000) and multiple equal('Asia',`country`.`Continent`))"},{"transformation": "constant_propagation","resulting_condition": "((`country`.`Population` > 5000000) and multiple equal('Asia',`country`.`Continent`))"},{"transformation": "trivial_condition_removal","resulting_condition": "((`country`.`Population` > 5000000) and multiple equal('Asia',`country`.`Continent`))"}]}},{"substitute_generated_columns": {}},{"table_dependencies": [{"table": "`country`","row_may_be_null": false,"map_bit": 0,Page 2 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-33-320.jpg&f=jpg&w=240)
!["depends_on_map_bits": []}]},{"ref_optimizer_key_uses": []},{"rows_estimation": [{"table": "`country`","range_analysis": {"table_scan": {"rows": 239,"cost": 27.5},"potential_range_indexes": [{"index": "PRIMARY","usable": false,"cause": "not_applicable"},{"index": "p","usable": true,"key_parts": ["Population","Code"]Page 3 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-34-320.jpg&f=jpg&w=240)
![}],"setup_range_conditions": [],"group_index_range": {"chosen": false,"cause": "not_group_by_or_distinct"},"analyzing_range_alternatives": {"range_scan_alternatives": [{"index": "p","ranges": ["5000000 < Population"],"index_dives_for_eq_ranges": true,"rowid_ordered": false,"using_mrr": false,"index_only": false,"rows": 108,"cost": 38.06,"chosen": false,"cause": "cost"}],"analyzing_roworder_intersect": {"usable": false,"cause": "too_few_roworder_scans"}}}Aha! It was tooexpensive.Page 4 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-35-320.jpg&f=jpg&w=240)
![}]},{"considered_execution_plans": [{"plan_prefix": [],"table": "`country`","best_access_path": {"considered_access_paths": [{"rows_to_scan": 239,"access_type": "scan","resulting_rows": 239,"cost": 25.4,"chosen": true}]},"condition_filtering_pct": 100,"rows_for_plan": 239,"cost_for_plan": 25.4,"chosen": true}]},{"attaching_conditions_to_tables": {"original_condition": "((`country`.`Continent` =
'Asia') and (`country`.`Population` > 5000000))",Prefer to table scaninsteadPage 5 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-36-320.jpg&f=jpg&w=240)
!["attached_conditions_computation": [],"attached_conditions_summary": [{"table": "`country`","attached": "((`country`.`Continent` = 'Asia') and (`country`.`Population` > 5000000))"}]}},{"refine_plan": [{"table": "`country`"}]}]}},{"join_execution": {"select#": 1,"steps": []}}]}Page 6 of 6](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-37-320.jpg&f=jpg&w=240)
![Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 38Why would an index not be used?"analyzing_range_alternatives": {"range_scan_alternatives": [{"index": "p","ranges": ["5000000 < Population"],"index_dives_for_eq_ranges": true,"rowid_ordered": false,"using_mrr": false,"index_only": false,"rows": 108,"cost": 38.06,"chosen": false,"cause": "cost"}],OPTIMIZER TRACE:.."query_block": {"select_id": 1,"cost_info": {"query_cost": "48.86"},"table": {"table_name": "Country","access_type": "range","possible_keys": ["p"],"key": "p",..FORCE INDEX (p):](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-38-320.jpg&f=jpg&w=240)



















![{"query_block": {"select_id": 1,"cost_info": {"query_cost": "25.40"},"table": {"table_name": "country","access_type": "ALL","possible_keys": ["p"],.."cost_info": {"read_cost": "23.86","eval_cost": "1.54","prefix_cost": "25.40","data_read_per_join": "3K"},..CPU CostIO CostTotal Cost](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-58-320.jpg&f=jpg&w=240)













![ALTER TABLE Country ADD INDEX c (continent);EXPLAIN FORMAT=JSON # 50M
SELECT * FROM Country WHERE population > 50000000 AND continent=‘Asia';{"query_block": {"select_id": 1,"cost_info": {"query_cost": "9.60"},"table": {"table_name": "Country","access_type": "ref","possible_keys": ["p","c"],"key": "c","used_key_parts": ["Continent"],"key_length": "1","ref": ["const"],.."attached_condition": "(`world`.`country`.`Population` > 50000000)"..Continent isdetermined to be lowercost.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-72-320.jpg&f=jpg&w=240)
![EXPLAIN FORMAT=JSON # 500MSELECT * FROM Country WHERE continent='Asia' and population > 500000000;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "1.16"},"table": {"table_name": "Country","access_type": "range","possible_keys": ["p","c"],"key": "p","used_key_parts": ["Population"],"key_length": "4",.."attached_condition": "(`world`.`country`.`Continent` = ‘Asia')"..Change the predicate,the query plan changes.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-73-320.jpg&f=jpg&w=240)





![ALTER TABLE Country ADD INDEX p_c (Population, Continent);EXPLAIN FORMAT=JSONSELECT * FROM Country FORCE INDEX (p_c) WHERE continent='Asia' and population >5000000;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "48.86"},"table": {"table_name": "Country","access_type": "range","possible_keys": ["p_c"],"key": "p_c","used_key_parts": ["Population"],"key_length": "4",..Only part of the key isused!](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-79-320.jpg&f=jpg&w=240)

![ALTER TABLE Country ADD INDEX c_p (Continent, Population);
EXPLAIN FORMAT=JSON
SELECT * FROM Country WHERE continent='Asia' and population > 5000000;
{"query_block": {"select_id": 1,"cost_info": {"query_cost": "7.91"},"table": {"table_name": "Country","access_type": "range","possible_keys": ["p","c","p_c","c_p"],"key": "c_p","used_key_parts": ["Continent","Population"],"key_length": “5”,
..All of the key isused](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-81-320.jpg&f=jpg&w=240)




![ALTER TABLE Country ADD INDEX c_p_n (Continent,Population,Name);EXPLAIN FORMAT=JSONSELECT Name FROM Country WHERE continent='Asia' and population > 5000000;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "3.72"},"table": {"table_name": "Country","access_type": "range","possible_keys": [.."c_p_n"],"key": "c_p_n","used_key_parts": ["Continent","Population"],"key_length": "5",.."filtered": "100.00","using_index": true,..Cost is reduced by53%Using index means"covering index"](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-86-320.jpg&f=jpg&w=240)











![ALTER TABLE city ADD INDEX n (name);EXPLAIN FORMAT=JSONSELECT * FROM Country WHERE Code = (SELECT CountryCode FROM City WHERE name=‘Toronto’);{"query_block": {"select_id": 1,"cost_info": {"query_cost": "1.00"},"table": {"table_name": "Country","access_type": "const",.."key": "PRIMARY",..},"optimized_away_subqueries": [{"dependent": false,"cacheable": true,"query_block": {"select_id": 2,"cost_info": {"query_cost": "0.35"},"table": {"table_name": "City","access_type": "ref","possible_keys": ["n"],"key": “n",..First query + itscostSecond query +its cost(misleadingvisualization)](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-98-320.jpg&f=jpg&w=240)

![EXPLAIN FORMAT=JSONSELECT * FROM City WHERE CountryCode IN
(SELECT Code FROM Country WHERE Continent = 'Asia');{"query_block": {"select_id": 1,"cost_info": {"query_cost": "327.58"},"nested_loop": [{"table": {"table_name": "Country","access_type": "ref",.."key": "c",.."using_index": true,.."used_columns": ["Code","Continent"..{"table": {"table_name": "City","access_type": "ref","possible_keys": ["CountryCode"],"key": "CountryCode",.."ref": ["world.Country.Code"],..](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-100-320.jpg&f=jpg&w=240)

![ALTER TABLE CountryLanguage ADD INDEX i (isOfficial);EXPLAIN FORMAT=JSON SELECT * FROM Country WHERE Code IN(SELECT CountryCode FROM CountryLanguage WHERE isOfficial=1);{"query_block": {"select_id": 1,"cost_info": {"query_cost": "98.39"},"nested_loop": [{"table": {"table_name": "Country","access_type": "ALL","possible_keys": ["PRIMARY"],.."filtered": "100.00",.."table": {"table_name": "<subquery2>","access_type": "eq_ref","key": "<auto_key>","key_length": "3","ref": ["world.Country.Code"],"rows_examined_per_scan": 1,"materialized_from_subquery": {"using_temporary_table": true,"query_block": {"table": {"table_name": "CountryLanguage","access_type": "ref",.."key": "i",.."using_index": true,..](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-102-320.jpg&f=jpg&w=240)


![ALTER TABLE country ADD INDEX c_n (continent, name);CREATE VIEW vCountry_Asia AS SELECT * FROM Country WHERE Continent='Asia';EXPLAIN FORMAT=JSONSELECT * FROM vCountry_Asia WHERE Name='China';{"query_block": {"select_id": 1,"cost_info": {"query_cost": "0.35"},"table": {"table_name": "country","access_type": "ref","possible_keys": [.."c_n"],"key": "c_n","used_key_parts": ["Continent","Name"],"key_length": "53","ref": ["const","const"],..This is the base tablePredicates from the viewdefinition and querycombined](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-105-320.jpg&f=jpg&w=240)

![CREATE VIEW vCountrys_Per_Continent ASSELECT Continent, COUNT(*) as Count FROM CountryGROUP BY Continent;EXPLAIN FORMAT=JSONSELECT * FROM vCountrys_Per_Continent WHERE Continent='Asia';{"query_block": {"select_id": 1,"cost_info": {"query_cost": "3.64"},"table": {"table_name": "vCountrys_Per_Continent","access_type": "ref","possible_keys": ["<auto_key0>"],"key": "<auto_key0>","used_key_parts": ["Continent"],"key_length": "1","ref": ["const"],.."used_columns": ["Continent","Count"],..This is the view name.."materialized_from_subquery": {"using_temporary_table": true,"dependent": false,"cacheable": true,"query_block": {"select_id": 2,"cost_info": {"query_cost": "25.40"},This is only the cost ofaccessing the materialized tableThis step happens first.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-107-320.jpg&f=jpg&w=240)





![{"query_block": {"select_id": 1,"cost_info": {"query_cost": "2.84"},"table": {"table_name": "my_cte","access_type": "ALL",.."used_columns": ["n"],"materialized_from_subquery": {"using_temporary_table": true,"dependent": false,"cacheable": true,"query_block": {"union_result": {"using_temporary_table": false,....{"dependent": false,"cacheable": true,"query_block": {"select_id": 3,"recursive": true,"cost_info": {"query_cost": "2.72"},"table": {"table_name": "my_cte","access_type": "ALL",.."used_columns": ["n"],"attached_condition":
"(`my_cte`.`n` < 10)"}..Requires atemporary table forintermediate resultsCost per iteration](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-113-320.jpg&f=jpg&w=240)











![EXPLAIN FORMAT=JSONSELECT * FROM City WHERE CountryCode = 'CAN'UNIONSELECT * FROM City WHERE CountryCode = 'USA'{"union_result": {"using_temporary_table": true,"table_name": "<union1,2>","access_type": "ALL","query_specifications": [{"dependent": false,"cacheable": true,"query_block": {"select_id": 1,"cost_info": {"query_cost": "17.15"},"table": {"table_name": "City","access_type": "ref",.."key": "CountryCode",..Temporary table tode-duplicate{"dependent": false,"cacheable": true,"query_block": {"select_id": 2,"cost_info": {"query_cost": "46.15"},"table": {"table_name": "City","access_type": "ref","possible_keys": ["CountryCode"],"key": "CountryCode","used_key_parts": ["CountryCode"],"key_length": "3","ref": ["const"],..](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-125-320.jpg&f=jpg&w=240)

![EXPLAIN FORMAT=JSONSELECT * FROM City WHERE CountryCode = 'CAN'UNION ALLSELECT * FROM City WHERE CountryCode = 'USA'{"query_block": {"union_result": {"using_temporary_table": false,"query_specifications": [{"dependent": false,"cacheable": true,"query_block": {"select_id": 1,"cost_info": {"query_cost": "17.15"},"table": {"table_name": "City","access_type": "ref",.."key": "CountryCode",..{"dependent": false,"cacheable": true,"query_block": {"select_id": 2,"cost_info": {"query_cost": "46.15"},"table": {"table_name": "City","access_type": "ref","possible_keys": ["CountryCode"],"key": "CountryCode","used_key_parts": ["CountryCode"],"key_length": "3","ref": ["const"],..No temporary table](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-127-320.jpg&f=jpg&w=240)




![ALTER TABLE Country DROP INDEX c_p, DROP INDEX c_p_n,ADD INDEX c_p_desc (continent ASC, population DESC);EXPLAIN FORMAT=JSONSELECT * FROM Country WHERE continent IN ('Asia', 'Oceania') AND population > 5000000ORDER BY continent ASC, population DESC;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "15.36"},"ordering_operation": {"using_filesort": false,"table": {"table_name": "Country","access_type": "range",.."key": "c_p_desc","used_key_parts": ["Continent","Population"],"key_length": "5",..TIP: The optimizer does not consider sort cost inevaluating plans. You may need to FORCE INDEX orDROP similar ascending indexes to use it.](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-132-320.jpg&f=jpg&w=240)




!["select#": 1,"steps": [{"filesort_information": [{"direction": "asc","table": "`country` IGNORE INDEX (`p_c`) IGNORE INDEX (`p`)","field": "Population"}],"filesort_priority_queue_optimization": {"limit": 10,"chosen": true},"filesort_execution": [],"filesort_summary": {"memory_available": 262144,"key_size": 4,"row_size": 272,"max_rows_per_buffer": 11,"num_rows_estimate": 587,"num_rows_found": 11,"num_examined_rows": 239,"num_tmp_files": 0,"sort_buffer_size": 3080,"sort_algorithm": "std::sort","unpacked_addon_fields": "using_priority_queue","sort_mode": "<fixed_sort_key, additional_fields>”..OPTIMIZER TRACEshowing Priority Queue forsort](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-137-320.jpg&f=jpg&w=240)

!["select#": 1,"steps": [{"filesort_information": [{"direction": "asc","table": "`country` IGNORE INDEX (`p_c`) IGNORE INDEX (`p`)","field": "Population"}],"filesort_priority_queue_optimization": {"usable": false,"cause": "not applicable (no LIMIT)"},"filesort_execution": [],"filesort_summary": {"memory_available": 262144,"key_size": 4,"row_size": 274,"max_rows_per_buffer": 587,"num_rows_estimate": 587,"num_rows_found": 239,"num_examined_rows": 239,"num_tmp_files": 0,"sort_buffer_size": 165536,"sort_algorithm": "std::stable_sort","sort_mode": "<fixed_sort_key, packed_additional_fields>"..Not Using Priority Sort](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-139-320.jpg&f=jpg&w=240)




![EXPLAIN FORMAT=JSONSELECT * FROM CountryLanguage WHERE isOfficial='T' ANDCountryCode='CAN';{"query_block": {"select_id": 1,"cost_info": {"query_cost": "2.40"},"table": {"table_name": "CountryLanguage","partitions": ["pOfficial"],"access_type": "ref",.."key": "PRIMARY",..Only accesses onepartition](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-144-320.jpg&f=jpg&w=240)














![Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 159No, due to clustered Index!FORCE INDEX (a) WHERE a=‘1234' AND id=1234;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "0.35"},"table": {"table_name": "t1","access_type": "const","possible_keys": ["a"],"key": "a","used_key_parts": ["a","id"],..FORCE INDEX (ab) WHERE a='1234' AND id=1234;{"query_block": {"select_id": 1,"cost_info": {"query_cost": "11.80"},"table": {"table_name": "t1","access_type": "ref","possible_keys": ["ab"],"key": "ab","used_key_parts": ["a"],..](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-159-320.jpg&f=jpg&w=240)









![ALTER TABLE CountryJSON ADD Name char(52) AS (doc->>"$.Name"),ADD INDEX n (Name);EXPLAIN FORMAT=JSONSELECT * FROM CountryJSON where doc->>"$.Name" = ‘Canada';{"query_block": {"select_id": 1,"cost_info": {"query_cost": "1.20"},"table": {"table_name": "CountryJSON","access_type": "ref",.."key": "n",.."key_length": "53","ref": ["const"],..Key from virtual columnMatches expression fromindexed virtual column](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-169-320.jpg&f=jpg&w=240)




![{"query_block": {"select_id": 1,"cost_info": {"query_cost": "0.35"},"table": {"table_name": "Country","access_type": "ref","possible_keys": ["n"],"key": "n","used_key_parts": ["Name"],"key_length": "52",.."rows_examined_per_scan": 1,"rows_produced_per_join": 1,"filtered": "100.00","cost_info": {"read_cost": "0.25","eval_cost": "0.10","prefix_cost": "0.35","data_read_per_join": "264"},..{"query_block": {"select_id": 1,"cost_info": {"query_cost": "0.35"},"table": {"table_name": "Country","access_type": "ref","possible_keys": ["n"],"key": "n","used_key_parts": ["Name"],"key_length": "208",.."rows_examined_per_scan": 1,"rows_produced_per_join": 1,"filtered": "100.00","cost_info": {"read_cost": "0.25","eval_cost": "0.10","prefix_cost": "0.35","data_read_per_join": "968"},..Key length as latin1 Key length as utf8](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fmysql8-170424163345%2f85%2fMySQL-8-0-Optimizer-Guide-174-320.jpg&f=jpg&w=240)

