SlideShare a Scribd company logo
1 of 12
MySQL Index optimization
technique
Kumar Gaurav
k10gaurav@gmail.com
Agenda
 Scenario
 Index Optimization
 Explain
 Explain Types
 Explain Extra
 Optimizer Hints
 Selecting Queries To Optimize
 General Query Log
Scenario
 Poor indexes are same has not having indexes and is the best way to kill the
application.
 Good selectivity on index fields.
 Selectivity= no. of distinct records in the table.
 On multiple column indexes the order fields within the index definitions is
important.
 Over indexing is cumbersome and can be overhead.
 The more index (the data) records can fit into one single block of memory the
faster will be queries.
Index Optimization
 An index on the whole column is not always necessary.
 Composite indexes ca be used for searches on the first column(s) index.
 Instead index just a prefix of a column.
 Prefix indexes take less space and the operations are faster.
 Minimize the size of PRIMARY KEYs that are used as references in other tables.
 Using and auto_increment column can be more optimal.
 A FULLTEXT index is useful for
 Word searches in text
 Searches on several columns
Continue…
 Query execution plan
 With EXPLAIN the query is sent all the way to the optimizer, but not to the storage
engine
 Instead EXPLAIN returns the query execution plan
Explain
 Explain tells about
 In which order tables are read
 What type of read operations are made
 Which indexes could have been used
 How tables refer to each other
 How many rows the optimizer estimates to retrieve from each table
Explain Types
Term Usage
system The table has only one row
const At the most one matching row, treated as a constant
eq_ref One row per row from previous tables
ref Several rows with matching index value
ref_or_null Like ref, plus NULL values
index_merge Several index searches are merged
unique_subquery Same as ref for some subqueries
index_subquery As above for non-unique indexes
range A range index scan
index The whole index is scanned
ALL A full table scan
Explain Extra
Term Usage
Using index The result is created straight from the index
Using where Not all rows are used in the result
Distinct Only a single row is read per row combination
Not exists A LEFT JOIN missing rows optimization is used
Using filesort An extra row sorting step is done
Using temporary A temporary table is used
Range checked for each
record
The read type is optimized individually for each combination of rows from the
previous tables
Optimizer Hints
Term Usage
STRAIGHT_JOIN Forces the optimizer to join the tables in the given order
SQL_BIG_RESULTS Together with GROUP BY or DISTINCT tells the server to use disk-based temp
tables
SQL_BUFFER_RESULTS Tells the server to use a temp table, thus releasing locks early (for table-locks)
USE INDEX Hints to the optimizer to use the given index
FORCE INDEX Forces the optimizer to use the index (if possible)
IGNORE INDEX Forces the optimizer not the use the index
Selecting Queries To Optimize
 The slow query log
 Logs all queries that take longer than long_query_time
 Can also log all queries that don’t use indexes with
--log-queries-not-using-indexes
 To log slow administrative commands use
--log-slow-admin-statements
 To analyze the contents of the slow log use mysqldumpslow
General Query Log
 Reads vs. writes
 Simple queries vs. complex queries
 etc
`
Thank You!

More Related Content

What's hot

How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15oysteing
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingAhmed Farag
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-dbuncleRhyme
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Jaime Crespo
 
Guide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanGuide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanOptimiz DBA
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performanceoysteing
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
Sub query example with advantage and disadvantages
Sub query example with advantage and disadvantagesSub query example with advantage and disadvantages
Sub query example with advantage and disadvantagesSarfaraz Ghanta
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive dataAmrit Kaur
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Achmad Solichin
 

What's hot (18)

How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having
 
SQL(database)
SQL(database)SQL(database)
SQL(database)
 
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
Views, Triggers, Functions, Stored Procedures,  Indexing and JoinsViews, Triggers, Functions, Stored Procedures,  Indexing and Joins
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
 
Guide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution PlanGuide To Mastering The MySQL Query Execution Plan
Guide To Mastering The MySQL Query Execution Plan
 
Not in vs not exists
Not in vs not existsNot in vs not exists
Not in vs not exists
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performance
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
Sub query example with advantage and disadvantages
Sub query example with advantage and disadvantagesSub query example with advantage and disadvantages
Sub query example with advantage and disadvantages
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
 
Sql subquery
Sql subquerySql subquery
Sql subquery
 
7. Using Sub Queries
7. Using Sub Queries7. Using Sub Queries
7. Using Sub Queries
 

Similar to MySQL index optimization techniques

Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008wharrislv
 
Tunning sql query
Tunning sql queryTunning sql query
Tunning sql queryvuhaininh88
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesJavier García Magna
 
Optimized cluster index generation
Optimized cluster index generationOptimized cluster index generation
Optimized cluster index generationRutvik Pensionwar
 
Db performance optimization with indexing
Db performance optimization with indexingDb performance optimization with indexing
Db performance optimization with indexingRajeev Kumar
 
MySQL Performance Secrets
MySQL Performance SecretsMySQL Performance Secrets
MySQL Performance SecretsOSSCube
 
Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Krishan Singh
 
MySQL Performance Tuning - GNUnify 2010
MySQL Performance Tuning - GNUnify 2010MySQL Performance Tuning - GNUnify 2010
MySQL Performance Tuning - GNUnify 2010OSSCube
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09guest9d79e073
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Mark Ginnebaugh
 
Goldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL QueriesGoldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL QueriesDave Stokes
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008paulguerin
 
Indexing Strategies
Indexing StrategiesIndexing Strategies
Indexing Strategiesjlaspada
 

Similar to MySQL index optimization techniques (20)

Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008
 
Tunning sql query
Tunning sql queryTunning sql query
Tunning sql query
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelines
 
Optimized cluster index generation
Optimized cluster index generationOptimized cluster index generation
Optimized cluster index generation
 
Sql performance tuning
Sql performance tuningSql performance tuning
Sql performance tuning
 
Optimizing MySQL queries
Optimizing MySQL queriesOptimizing MySQL queries
Optimizing MySQL queries
 
Db performance optimization with indexing
Db performance optimization with indexingDb performance optimization with indexing
Db performance optimization with indexing
 
San diegophp
San diegophpSan diegophp
San diegophp
 
Django orm-tips
Django orm-tipsDjango orm-tips
Django orm-tips
 
MySQL Performance Secrets
MySQL Performance SecretsMySQL Performance Secrets
MySQL Performance Secrets
 
Windows azure table storage – deep dive
Windows azure table storage – deep diveWindows azure table storage – deep dive
Windows azure table storage – deep dive
 
Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager Db2 sql tuning and bmc catalog manager
Db2 sql tuning and bmc catalog manager
 
MySQL Performance Tuning - GNUnify 2010
MySQL Performance Tuning - GNUnify 2010MySQL Performance Tuning - GNUnify 2010
MySQL Performance Tuning - GNUnify 2010
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
Goldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL QueriesGoldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL Queries
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
 
Mysql For Developers
Mysql For DevelopersMysql For Developers
Mysql For Developers
 
Indexing Strategies
Indexing StrategiesIndexing Strategies
Indexing Strategies
 
Indexes overview
Indexes overviewIndexes overview
Indexes overview
 

More from kumar gaurav

Need Of Enterprise Integration
Need Of Enterprise IntegrationNeed Of Enterprise Integration
Need Of Enterprise Integrationkumar gaurav
 
Mulesoft file connector
Mulesoft file connectorMulesoft file connector
Mulesoft file connectorkumar gaurav
 
Mulesoft http connector
Mulesoft http connectorMulesoft http connector
Mulesoft http connectorkumar gaurav
 
Reason to connect with Mulesoft
Reason to connect with MulesoftReason to connect with Mulesoft
Reason to connect with Mulesoftkumar gaurav
 
Mulesoft idempotent Message Filter
Mulesoft idempotent Message FilterMulesoft idempotent Message Filter
Mulesoft idempotent Message Filterkumar gaurav
 
Mulesoft Using Groovy Component
Mulesoft Using Groovy ComponentMulesoft Using Groovy Component
Mulesoft Using Groovy Componentkumar gaurav
 
Mulesoft vm transport reference
Mulesoft vm transport referenceMulesoft vm transport reference
Mulesoft vm transport referencekumar gaurav
 
Mulesoft Calling Flow of Other Applications
Mulesoft Calling Flow of Other ApplicationsMulesoft Calling Flow of Other Applications
Mulesoft Calling Flow of Other Applicationskumar gaurav
 
Mulesoft Solutions for Mobile
Mulesoft Solutions for MobileMulesoft Solutions for Mobile
Mulesoft Solutions for Mobilekumar gaurav
 
Mulesoft Solutions for SOA
Mulesoft Solutions for SOAMulesoft Solutions for SOA
Mulesoft Solutions for SOAkumar gaurav
 
Mulesoft Solutions for IoT
Mulesoft Solutions for IoTMulesoft Solutions for IoT
Mulesoft Solutions for IoTkumar gaurav
 
Mulesoft Anypoint platform for APIs
Mulesoft Anypoint platform for APIsMulesoft Anypoint platform for APIs
Mulesoft Anypoint platform for APIskumar gaurav
 
Oracle Managed Files Transfer- Key based authentication
Oracle Managed Files Transfer- Key based authenticationOracle Managed Files Transfer- Key based authentication
Oracle Managed Files Transfer- Key based authenticationkumar gaurav
 
Java collections concept
Java collections conceptJava collections concept
Java collections conceptkumar gaurav
 
Struggle that counts
Struggle that countsStruggle that counts
Struggle that countskumar gaurav
 
Security guidelines for web development
Security guidelines for web developmentSecurity guidelines for web development
Security guidelines for web developmentkumar gaurav
 
Oracle web center suit
Oracle web center suitOracle web center suit
Oracle web center suitkumar gaurav
 

More from kumar gaurav (20)

Need Of Enterprise Integration
Need Of Enterprise IntegrationNeed Of Enterprise Integration
Need Of Enterprise Integration
 
Mulesoft file connector
Mulesoft file connectorMulesoft file connector
Mulesoft file connector
 
Mulesoft http connector
Mulesoft http connectorMulesoft http connector
Mulesoft http connector
 
Reason to connect with Mulesoft
Reason to connect with MulesoftReason to connect with Mulesoft
Reason to connect with Mulesoft
 
Mulesoft idempotent Message Filter
Mulesoft idempotent Message FilterMulesoft idempotent Message Filter
Mulesoft idempotent Message Filter
 
Mulesoft Using Groovy Component
Mulesoft Using Groovy ComponentMulesoft Using Groovy Component
Mulesoft Using Groovy Component
 
Mulesoft vm transport reference
Mulesoft vm transport referenceMulesoft vm transport reference
Mulesoft vm transport reference
 
Mulesoft Calling Flow of Other Applications
Mulesoft Calling Flow of Other ApplicationsMulesoft Calling Flow of Other Applications
Mulesoft Calling Flow of Other Applications
 
Mulesoft Solutions for Mobile
Mulesoft Solutions for MobileMulesoft Solutions for Mobile
Mulesoft Solutions for Mobile
 
Mulesoft Solutions for SOA
Mulesoft Solutions for SOAMulesoft Solutions for SOA
Mulesoft Solutions for SOA
 
Mulesoft Solutions for IoT
Mulesoft Solutions for IoTMulesoft Solutions for IoT
Mulesoft Solutions for IoT
 
Mulesoft Anypoint platform for APIs
Mulesoft Anypoint platform for APIsMulesoft Anypoint platform for APIs
Mulesoft Anypoint platform for APIs
 
Oracle Managed Files Transfer- Key based authentication
Oracle Managed Files Transfer- Key based authenticationOracle Managed Files Transfer- Key based authentication
Oracle Managed Files Transfer- Key based authentication
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Struggle that counts
Struggle that countsStruggle that counts
Struggle that counts
 
Team Work
Team WorkTeam Work
Team Work
 
Security guidelines for web development
Security guidelines for web developmentSecurity guidelines for web development
Security guidelines for web development
 
Java web services
Java web servicesJava web services
Java web services
 
Oracle web center suit
Oracle web center suitOracle web center suit
Oracle web center suit
 
jQuery Beginner
jQuery BeginnerjQuery Beginner
jQuery Beginner
 

Recently uploaded

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Recently uploaded (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

MySQL index optimization techniques

  • 1. MySQL Index optimization technique Kumar Gaurav k10gaurav@gmail.com
  • 2. Agenda  Scenario  Index Optimization  Explain  Explain Types  Explain Extra  Optimizer Hints  Selecting Queries To Optimize  General Query Log
  • 3. Scenario  Poor indexes are same has not having indexes and is the best way to kill the application.  Good selectivity on index fields.  Selectivity= no. of distinct records in the table.  On multiple column indexes the order fields within the index definitions is important.  Over indexing is cumbersome and can be overhead.  The more index (the data) records can fit into one single block of memory the faster will be queries.
  • 4. Index Optimization  An index on the whole column is not always necessary.  Composite indexes ca be used for searches on the first column(s) index.  Instead index just a prefix of a column.  Prefix indexes take less space and the operations are faster.  Minimize the size of PRIMARY KEYs that are used as references in other tables.  Using and auto_increment column can be more optimal.  A FULLTEXT index is useful for  Word searches in text  Searches on several columns
  • 5. Continue…  Query execution plan  With EXPLAIN the query is sent all the way to the optimizer, but not to the storage engine  Instead EXPLAIN returns the query execution plan
  • 6. Explain  Explain tells about  In which order tables are read  What type of read operations are made  Which indexes could have been used  How tables refer to each other  How many rows the optimizer estimates to retrieve from each table
  • 7. Explain Types Term Usage system The table has only one row const At the most one matching row, treated as a constant eq_ref One row per row from previous tables ref Several rows with matching index value ref_or_null Like ref, plus NULL values index_merge Several index searches are merged unique_subquery Same as ref for some subqueries index_subquery As above for non-unique indexes range A range index scan index The whole index is scanned ALL A full table scan
  • 8. Explain Extra Term Usage Using index The result is created straight from the index Using where Not all rows are used in the result Distinct Only a single row is read per row combination Not exists A LEFT JOIN missing rows optimization is used Using filesort An extra row sorting step is done Using temporary A temporary table is used Range checked for each record The read type is optimized individually for each combination of rows from the previous tables
  • 9. Optimizer Hints Term Usage STRAIGHT_JOIN Forces the optimizer to join the tables in the given order SQL_BIG_RESULTS Together with GROUP BY or DISTINCT tells the server to use disk-based temp tables SQL_BUFFER_RESULTS Tells the server to use a temp table, thus releasing locks early (for table-locks) USE INDEX Hints to the optimizer to use the given index FORCE INDEX Forces the optimizer to use the index (if possible) IGNORE INDEX Forces the optimizer not the use the index
  • 10. Selecting Queries To Optimize  The slow query log  Logs all queries that take longer than long_query_time  Can also log all queries that don’t use indexes with --log-queries-not-using-indexes  To log slow administrative commands use --log-slow-admin-statements  To analyze the contents of the slow log use mysqldumpslow
  • 11. General Query Log  Reads vs. writes  Simple queries vs. complex queries  etc