SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
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!

Más contenido relacionado

Similar a 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
 

Similar a Efficient MySQL Indexing and what's new in MySQL Explain (20)

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
 
Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query Tuning
 

Más de Mydbops

Más de 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
 

Último

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Último (20)

Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptxBT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
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...
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 

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