SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
Efficient MySQL Indexing &
What's New in MySQL Explain
Presented by
Jebashalomie Immanuel
Mydbops
Mydbops MyWebinar - 32
May 11th, 2024
Consulting
Services
Consulting
Services
Managed
Services
● Database Management and
consultancy provider
● Founded in 2016
● Assisted 800+ happy customers
● AWS partners
● PCI & ISO certified
About Us
Agenda
❏ Index Overview
❏ Types of Indexes
❏ Increasing Indexing Efficiency
❏ Example
❏ Before Optimization
❏ Optimization
❏ After Optimization
❏ New Features
❏ Capturing EXPLAIN FORMAT=JSON Output
❏ explain_json_format_version
Index Overview
Index Overview
❏ Enhances data retrieval speed, uses extra space.
❏ Created on table columns, choosing the right index is vital.
❏ Needs regular updates to stay efficient.
❏ Index types: Includes primary, unique, composite, and full-text.
Types of Indexes
Types of Indexes
Increasing Index Efficiency
Increasing Index Efficiency
❏ Analysing the queries
❏ Avoid over indexing
❏ Analyze the cardinality
❏ Pick the correct columns
❏ Pick the suitable index
❏ Regular maintenance
Example
Example
Datatype:
column1 - text
Query:
SELECT * FROM test_function WHERE column1 LIKE
'flexibility';
Total rows: 96
Before Optimization
Before Optimization
mysql> explain SELECT * FROM test_function WHERE column1 LIKE 'flexibility'G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: test_function
partitions: NULL
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 96
filtered: 11.11
Extra: Using where
Optimization
Index creation:
mysql> Alter table test_function add fulltext index idx_column1(column1);
Query OK, 0 rows affected, 1 warning (0.20 sec)
mysql> explain SELECT * FROM test_function WHERE column1 LIKE 'flexibility';
+----+-------------+---------------+------------+------+---------------+------+---------+------+-
-----+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref |
rows | filtered | Extra |
+----+-------------+---------------+------------+------+---------------+------+---------+------+-
-----+----------+-------------+
| 1 | SIMPLE | test_function | NULL | ALL | idx_column1 | NULL | NULL | NULL |
96 | 11.11 | Using where |
+----+-------------+---------------+------------+------+---------------+------+---------+------+-
-----+----------+-------------+
After Optimization
After Optimization
mysql> EXPLAIN SELECT * FROM test_function WHERE MATCH(column1) AGAINST
('flexibility')G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: test_function
partitions: NULL
type: fulltext
possible_keys: idx_column1
key: idx_column1
key_len: 0
ref: const
rows: 1
filtered: 100.00
Extra: Using where; Ft_hints: sorted
1 row in set, 1 warning (0.00 sec)
mysql> EXPLAIN SELECT * FROM test_function WHERE MATCH(column1) AGAINST ('flexibility')G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: test_function
partitions: NULL
type: fulltext
possible_keys: idx_column1
key: idx_column1
key_len: 0
ref: const
rows: 1
filtered: 100.00
Extra: Using where; Ft_hints: sorted
1 row in set, 1 warning (0.00 sec)
New Features
❏ Capturing EXPLAIN FORMAT=JSON output (MySQL 8.1.0)
❏ explain_json_format_version (MySQL 8.3.0)
Capturing EXPLAIN FORMAT=JSON Output
Query:
mysql> EXPLAIN FORMAT=JSON INTO @myvar SELECT * FROM city WHERE
District='Texas';
Query OK, 0 rows affected (0.00 sec)
mysql> EXPLAIN FORMAT=JSON INTO @myvar SELECT * FROM city WHERE
District='Texas';
Query OK, 0 rows affected (0.00 sec)
mysql> select @myvarG
*************************** 1. row ***************************
@myvar: {
"query_block": {
"select_id": 1,
"cost_info": {
"query_cost": "428.50"
},
"table": {
"table_name": "city",
"access_type": "ALL",
"rows_examined_per_scan": 4035,
"rows_produced_per_join": 403,
"filtered": "10.00",
"cost_info": {
"read_cost": "388.15",
"eval_cost": "40.35",
"prefix_cost": "428.50",
"data_read_per_join": "97K"
},
"used_columns": [
"ID",
"Name",
"CountryCode",
"District",
"Population"
],
"attached_condition": "(`world`.`city`.`District` = 'Texas')"}}
1 row in set (0.00 sec)
explain_json_format_version variable
● Two versions available for EXPLAIN FORMAT=JSON.
● Version 2 reveals optimizer access paths.
● Ensures compatibility with upcoming MySQL Optimizer.
● Supports the JSON output format for EXPLAIN statements.
Version 1
Validation of the variable:
mysql> select @@explain_json_format_version;
+-------------------------------+
| @@explain_json_format_version |
+-------------------------------+
| 1 |
+-------------------------------+
mysql> select @@explain_json_format_version;
+-------------------------------+
| @@explain_json_format_version |
+-------------------------------+
| 1 |
+-------------------------------+
mysql> Explain format = JSON select ID, Name, CountryCode, District,
Population from city where Population between 127800 and 137500G
*************************** 1. row ***************************
EXPLAIN: {
"query_block": {
"select_id": 1,
"cost_info": {
"query_cost": "409.75"
},
"table": {
"table_name": "city",
"access_type": "ALL",
"rows_examined_per_scan": 4035,
"rows_produced_per_join": 448,
"filtered": "11.11",
"cost_info": {
"read_cost": "364.92",
"eval_cost": "44.83",
"prefix_cost": "409.75",
"data_read_per_join": "108K"
},
"used_columns": [
"ID", "Name","CountryCode", "District",
"Population"
],
"attached_condition": "(`world`.`city`.`Population` between 127800 and 137500)”} } }
Version 2
Setting the variable:
mysql> SET @@explain_json_format_version = 2;
Query OK, 0 rows affected (0.00 sec)
mysql> Explain format = JSON select ID, Name, CountryCode, District, Population
from city where Population between 127800 and 137500G
*************************** 1. row ***************************
EXPLAIN: {
"query": "/* select#1 */ select `world`.`city`.`ID` AS `ID`,`world`.`city`.`Name` AS
`Name`,`world`.`city`.`CountryCode` AS `CountryCode`,`world`.`city`.`District` AS
`District`,`world`.`city`.`Population` AS `Population` from `world`.`city` where (`world`.`city`.`Population`
between 127800 and 137500)",
"inputs": [
{
"operation": "Table scan on city",
"table_name": "city",
"access_type": "table",
"schema_name": "world",
"used_columns": [
"ID",
"Name",
"CountryCode",
"District",
"Population"
],
"estimated_rows": 4035.0,
"estimated_total_cost": 409.75
}
],
"condition": "(city.Population between 127800 and 137500)",
"operation": "Filter: (city.Population between 127800 and 137500)",
"access_type": "filter",
"estimated_rows": 448.28851260244846,
"estimated_total_cost": 409.75
}
Demo
Consulting
Services
Consulting
Services
Connect with us !
Reach us at : info@mydbops.com
Thank You!

Weitere ähnliche Inhalte

Ähnlich wie Efficient MySQL Indexing and what's new in MySQL Explain

15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
Joshua Thijssen
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 

Ähnlich wie Efficient MySQL Indexing and what's new in MySQL Explain (20)

4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.ppt
 
Upgrade to MySQL 5.7 and latest news planned for MySQL 8
Upgrade to MySQL 5.7 and latest news planned for MySQL 8Upgrade to MySQL 5.7 and latest news planned for MySQL 8
Upgrade to MySQL 5.7 and latest news planned for MySQL 8
 
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
 
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
 
MySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queriesMySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queries
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
 
Window functions in MySQL 8.0
Window functions in MySQL 8.0Window functions in MySQL 8.0
Window functions in MySQL 8.0
 
New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Explain
ExplainExplain
Explain
 
MySQL Tech Tour 2015 - 5.7 Whats new
MySQL Tech Tour 2015 - 5.7 Whats newMySQL Tech Tour 2015 - 5.7 Whats new
MySQL Tech Tour 2015 - 5.7 Whats new
 
16 MySQL Optimization #burningkeyboards
16 MySQL Optimization #burningkeyboards16 MySQL Optimization #burningkeyboards
16 MySQL Optimization #burningkeyboards
 
Query Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksQuery Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New Tricks
 
MariaDB 10.0 Query Optimizer
MariaDB 10.0 Query OptimizerMariaDB 10.0 Query Optimizer
MariaDB 10.0 Query Optimizer
 
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
DATA BASE || INTRODUCTION OF DATABASE \\ SQL 2018
 

Mehr von Mydbops

Mehr von Mydbops (20)

Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
 
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
 
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster RecoveryMastering Aurora PostgreSQL Clusters for Disaster Recovery
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
 
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
 
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
AWS RDS in MySQL 2023 Vinoth Kanna @ Mydbops OpenSource Database Meetup 15
 
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE EventData-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
Data-at-scale-with-TIDB Mydbops Co-Founder Kabilesh PR at LSPE Event
 
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
MySQL Transformation Case Study: 80% Cost Savings & Uninterrupted Availabilit...
 
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
Scaling-MongoDB-with-Horizontal-and-Vertical-Sharding Mydbops Opensource Data...
 
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
Mastering MongoDB Atlas: Essentials of Diagnostics and Debugging in the Cloud...
 
Data Organisation: Table Partitioning in PostgreSQL
Data Organisation: Table Partitioning in PostgreSQLData Organisation: Table Partitioning in PostgreSQL
Data Organisation: Table Partitioning in PostgreSQL
 
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - MydbopsNavigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
Navigating MongoDB's Queryable Encryption for Ultimate Security - Mydbops
 
Data High Availability With TIDB
Data High Availability With TIDBData High Availability With TIDB
Data High Availability With TIDB
 
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
Mastering Database Migration_ Native replication (8.0) to InnoDB Cluster (8.0...
 
Enhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificatesEnhancing Security of MySQL Connections using SSL certificates
Enhancing Security of MySQL Connections using SSL certificates
 
Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops
 
Time series in MongoDB - Mydbops
Time series in MongoDB - Mydbops Time series in MongoDB - Mydbops
Time series in MongoDB - Mydbops
 
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - MydbopsTiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
TiDB in a Nutshell - Power of Open-Source Distributed SQL Database - Mydbops
 
Achieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQLAchieving High Availability in PostgreSQL
Achieving High Availability in PostgreSQL
 
Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding Scaling MongoDB with Horizontal and Vertical Sharding
Scaling MongoDB with Horizontal and Vertical Sharding
 

Kürzlich hochgeladen

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Kürzlich hochgeladen (20)

Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptx
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 

Efficient MySQL Indexing and what's new in MySQL Explain

  • 1. Efficient MySQL Indexing & What's New in MySQL Explain Presented by Jebashalomie Immanuel Mydbops Mydbops MyWebinar - 32 May 11th, 2024
  • 2. Consulting Services Consulting Services Managed Services ● Database Management and consultancy provider ● Founded in 2016 ● Assisted 800+ happy customers ● AWS partners ● PCI & ISO certified About Us
  • 3. Agenda ❏ Index Overview ❏ Types of Indexes ❏ Increasing Indexing Efficiency ❏ Example ❏ Before Optimization ❏ Optimization ❏ After Optimization ❏ New Features ❏ Capturing EXPLAIN FORMAT=JSON Output ❏ explain_json_format_version
  • 5. Index Overview ❏ Enhances data retrieval speed, uses extra space. ❏ Created on table columns, choosing the right index is vital. ❏ Needs regular updates to stay efficient. ❏ Index types: Includes primary, unique, composite, and full-text.
  • 9. Increasing Index Efficiency ❏ Analysing the queries ❏ Avoid over indexing ❏ Analyze the cardinality ❏ Pick the correct columns ❏ Pick the suitable index ❏ Regular maintenance
  • 11. Example Datatype: column1 - text Query: SELECT * FROM test_function WHERE column1 LIKE 'flexibility'; Total rows: 96
  • 13. Before Optimization mysql> explain SELECT * FROM test_function WHERE column1 LIKE 'flexibility'G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: test_function partitions: NULL type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 96 filtered: 11.11 Extra: Using where
  • 14. Optimization Index creation: mysql> Alter table test_function add fulltext index idx_column1(column1); Query OK, 0 rows affected, 1 warning (0.20 sec) mysql> explain SELECT * FROM test_function WHERE column1 LIKE 'flexibility'; +----+-------------+---------------+------------+------+---------------+------+---------+------+- -----+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+---------------+------------+------+---------------+------+---------+------+- -----+----------+-------------+ | 1 | SIMPLE | test_function | NULL | ALL | idx_column1 | NULL | NULL | NULL | 96 | 11.11 | Using where | +----+-------------+---------------+------------+------+---------------+------+---------+------+- -----+----------+-------------+
  • 16. After Optimization mysql> EXPLAIN SELECT * FROM test_function WHERE MATCH(column1) AGAINST ('flexibility')G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: test_function partitions: NULL type: fulltext possible_keys: idx_column1 key: idx_column1 key_len: 0 ref: const rows: 1 filtered: 100.00 Extra: Using where; Ft_hints: sorted 1 row in set, 1 warning (0.00 sec) mysql> EXPLAIN SELECT * FROM test_function WHERE MATCH(column1) AGAINST ('flexibility')G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: test_function partitions: NULL type: fulltext possible_keys: idx_column1 key: idx_column1 key_len: 0 ref: const rows: 1 filtered: 100.00 Extra: Using where; Ft_hints: sorted 1 row in set, 1 warning (0.00 sec)
  • 17. New Features ❏ Capturing EXPLAIN FORMAT=JSON output (MySQL 8.1.0) ❏ explain_json_format_version (MySQL 8.3.0)
  • 18. Capturing EXPLAIN FORMAT=JSON Output Query: mysql> EXPLAIN FORMAT=JSON INTO @myvar SELECT * FROM city WHERE District='Texas'; Query OK, 0 rows affected (0.00 sec) mysql> EXPLAIN FORMAT=JSON INTO @myvar SELECT * FROM city WHERE District='Texas'; Query OK, 0 rows affected (0.00 sec)
  • 19. mysql> select @myvarG *************************** 1. row *************************** @myvar: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "428.50" }, "table": { "table_name": "city", "access_type": "ALL", "rows_examined_per_scan": 4035, "rows_produced_per_join": 403, "filtered": "10.00", "cost_info": { "read_cost": "388.15", "eval_cost": "40.35", "prefix_cost": "428.50", "data_read_per_join": "97K" }, "used_columns": [ "ID", "Name", "CountryCode", "District", "Population" ], "attached_condition": "(`world`.`city`.`District` = 'Texas')"}} 1 row in set (0.00 sec)
  • 20. explain_json_format_version variable ● Two versions available for EXPLAIN FORMAT=JSON. ● Version 2 reveals optimizer access paths. ● Ensures compatibility with upcoming MySQL Optimizer. ● Supports the JSON output format for EXPLAIN statements.
  • 21. Version 1 Validation of the variable: mysql> select @@explain_json_format_version; +-------------------------------+ | @@explain_json_format_version | +-------------------------------+ | 1 | +-------------------------------+ mysql> select @@explain_json_format_version; +-------------------------------+ | @@explain_json_format_version | +-------------------------------+ | 1 | +-------------------------------+
  • 22. mysql> Explain format = JSON select ID, Name, CountryCode, District, Population from city where Population between 127800 and 137500G *************************** 1. row *************************** EXPLAIN: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "409.75" }, "table": { "table_name": "city", "access_type": "ALL", "rows_examined_per_scan": 4035, "rows_produced_per_join": 448, "filtered": "11.11", "cost_info": { "read_cost": "364.92", "eval_cost": "44.83", "prefix_cost": "409.75", "data_read_per_join": "108K" }, "used_columns": [ "ID", "Name","CountryCode", "District", "Population" ], "attached_condition": "(`world`.`city`.`Population` between 127800 and 137500)”} } }
  • 23. Version 2 Setting the variable: mysql> SET @@explain_json_format_version = 2; Query OK, 0 rows affected (0.00 sec)
  • 24. mysql> Explain format = JSON select ID, Name, CountryCode, District, Population from city where Population between 127800 and 137500G *************************** 1. row *************************** EXPLAIN: { "query": "/* select#1 */ select `world`.`city`.`ID` AS `ID`,`world`.`city`.`Name` AS `Name`,`world`.`city`.`CountryCode` AS `CountryCode`,`world`.`city`.`District` AS `District`,`world`.`city`.`Population` AS `Population` from `world`.`city` where (`world`.`city`.`Population` between 127800 and 137500)", "inputs": [ { "operation": "Table scan on city", "table_name": "city", "access_type": "table", "schema_name": "world", "used_columns": [ "ID", "Name", "CountryCode", "District", "Population" ], "estimated_rows": 4035.0, "estimated_total_cost": 409.75 } ], "condition": "(city.Population between 127800 and 137500)", "operation": "Filter: (city.Population between 127800 and 137500)", "access_type": "filter", "estimated_rows": 448.28851260244846, "estimated_total_cost": 409.75 }
  • 25. Demo