SlideShare ist ein Scribd-Unternehmen logo
1 von 57
Downloaden Sie, um offline zu lesen
Practical MySQL Practical MySQL 
Performance Performance 
OptimizationOptimization
Marian HackMan MarinovMarian HackMan Marinov
<mm@siteground.com><mm@siteground.com>
Chief System ArchitectChief System Architect
SiteGroundSiteGround
Who am I?Who am I?Who am I?Who am I?
❖ Chief System Architect of Siteground.com
❖ Sysadmin since 1996
❖ Organizer of OpenFest, BG Perl Workshops,
LUG-BG and similar :)
❖ Teaching Network Security and Linux System
Administration at Sofia University
❖ MySQL 5.7
❖ Or its equivalent from MariaDB or Percona
Requirements...Requirements...
❖ Why am I making this presentation?
❖ Where is the information coming from?
MySQL Optimization Documentation
❖ I have skipped the SQL examples as they
made the presentation too big ☹
DISCLAMERDISCLAMER
❖ Manual monitoring
❖ Using Monyog
MonitoringMonitoring
How MySQL uses indexesHow MySQL uses indexes
❖ What type of indexes are there?
How MySQL uses indexesHow MySQL uses indexes
❖ What type of indexes are there?
 B-Tree
 Hash
FULLTEXT
Spatial
❖ What type of indexes are there?
❖ Which is used for what ?
 hash
  used for = or <=>
  can not be used in ORDER BY
  only whole keys can be used for search
How MySQL uses indexesHow MySQL uses indexes
❖ What type of indexes are there?
❖ Which is used for what ?
 hash
How MySQL uses indexesHow MySQL uses indexes
❖ What type of indexes are there?
❖ Which is used for what ?
 b-tree
  can be used for =, >, >=, <, <=, or
BETWEEN comparisons
  can be used with LIKE, only if it doesn't start
with %
  can not be used in the form
column1 LIKE column2
  can limit the size of the index (prefix)
How MySQL uses indexesHow MySQL uses indexes
❖ When is index NOT used
How MySQL uses indexesHow MySQL uses indexes
❖ When is index NOT used
when the index does not cover all the
columns in the where clause
How MySQL uses indexesHow MySQL uses indexes
❖ When is index NOT used
when the index does not cover all the
columns in the where clause
when the types don't match: integer used
for string index(column)
How MySQL uses indexesHow MySQL uses indexes
❖ When is index NOT used
when the index does not cover all the
columns in the where clause
when the types don't match: integer used
for string index(column)
when != is used
How MySQL uses indexesHow MySQL uses indexes
❖ When is index NOT used
when the index does not cover all the
columns in the where clause
when the types don't match: integer used
for string index(column)
when != is used
when you have a multicolumn index but
the column you are referencing is not the
first one and you don't have a separate index
How MySQL uses indexesHow MySQL uses indexes
❖ When is index NOT used
 when you have a Btree index but you use
distinct on the column
How MySQL uses indexesHow MySQL uses indexes
❖ When is index NOT used
 when you have a Btree index but you use
distinct on the column
 when you have a single column indexes
but you are actually referencing multiple
columns in your WHERE/JOIN
How MySQL uses indexesHow MySQL uses indexes
❖ When is index NOT used
 when you have a Btree index but you use
distinct on the column
 when you have a single column indexes
but you are actually referencing multiple
columns in your WHERE/JOIN
 when LIKE is used with % in the begining
e.g. LIKE '%name'
How MySQL uses indexesHow MySQL uses indexes
❖ When is index NOT used
 when you have a Btree index but you use
distinct on the column
 when you have a single column indexes
but you are actually referencing multiple
columns in your WHERE/JOIN
 when LIKE is used with % in the begining
e.g. LIKE '%name'
 order of columns in indexes MATTERS
How MySQL uses indexesHow MySQL uses indexes
1410864 rows
1 row in set (10.46 sec)
1 row in set (8.33 sec)
1 row in set (6.66 sec)
Index hintsIndex hints
❖ IGNORE INDEX
Index hintsIndex hints
❖ IGNORE INDEX
USE INDEX❖
Index hintsIndex hints
❖ IGNORE INDEX
❖ USE INDEX
❖ FORCE INDEX
Index hintsIndex hints
❖ "Waiting for query cache lock"
Abusing query cacheAbusing query cache
❖ "Waiting for query cache lock"
❖ SELECT *,NOW() FROM TABLE
Abusing query cacheAbusing query cache
❖ "Waiting for query cache lock"
❖ SELECT *,NOW() FROM TABLE
❖ SQL_NO_CACHE
Abusing query cacheAbusing query cache
❖ "Waiting for query cache lock"
❖ SELECT *,NOW() FROM TABLE
❖ SQL_NO_CACHE
❖ SET SESSION query_cache_type = OFF;
Abusing query cacheAbusing query cache
❖ "Waiting for query cache lock"
❖ SELECT *,NOW() FROM TABLE
❖ SQL_NO_CACHE
❖ SET SESSION query_cache_type = OFF;
❖ Аs of MySQL 5.6.8 query cache is now
disabled by default
Abusing query cacheAbusing query cache
❖ Large result sets hammer the network...
Abusing query cacheAbusing query cache
❖ Large result sets hammer the network...
❖ For caching large results move the cache,
closer to the application by caching the results
in ProxySQL
Abusing query cacheAbusing query cache
❖ InooDB uses only a single index per query
Optimizing InnoDB queriesOptimizing InnoDB queries
❖ InooDB uses only a single index per query
❖ If an indexed column cannot contain any
NULL values, declare it as NOT NULL
Optimizing InnoDB queriesOptimizing InnoDB queries
❖ InooDB uses only a single index per query
❖ If an indexed column cannot contain any
NULL values, declare it as NOT NULL
❖ START TRANSACTION READ ONLY
Optimizing InnoDB queriesOptimizing InnoDB queries
❖ use ANALYZE TABLE or myisamchk
--analyze
Optimizing MyISAM queriesOptimizing MyISAM queries
❖ use ANALYZE TABLE or myisamchk
--analyze
❖ myisamchk --sort-index --sort-records=1
Optimizing MyISAM queriesOptimizing MyISAM queries
❖ use ANALYZE TABLE or myisamchk
--analyze
❖ myisamchk --sort-index --sort-records=1
❖ avoid complex SELECT queries on
MyISAM tables that are updated frequently
Optimizing MyISAM queriesOptimizing MyISAM queries
❖ use ANALYZE TABLE or myisamchk
--analyze
❖ myisamchk --sort-index --sort-records=1
❖ avoid complex SELECT queries on
MyISAM tables that are updated frequently
❖ MyISAM supports concurrent inserts
Optimizing MyISAM queriesOptimizing MyISAM queries
❖ use ANALYZE TABLE or myisamchk
--analyze
❖ myisamchk --sort-index --sort-records=1
❖ avoid complex SELECT queries on MyISAM
tables that are updated frequently
❖ MyISAM supports concurrent inserts
concurrent_insert = 0 (disabled)
concurrent_insert = 1 (auto)
concurrent_insert = 1 (always, even with
deleted rows)
Optimizing MyISAM queriesOptimizing MyISAM queries
❖ use ANALYZE TABLE or myisamchk
--analyze
❖ myisamchk --sort-index --sort-records=1
❖ avoid complex SELECT queries on
MyISAM tables that are updated frequently
❖ MyISAM supports concurrent inserts
❖ try to avoid VARCHAR, BLOB, and TEXT in
MyISAM tables
Optimizing MyISAM queriesOptimizing MyISAM queries
❖ use ANALYZE TABLE or myisamchk
--analyze
❖ myisamchk --sort-index --sort-records=1
❖ avoid complex SELECT queries on
MyISAM tables that are updated frequently
❖ MyISAM supports concurrent inserts
❖ try to avoid VARCHAR, BLOB, and TEXT in
MyISAM tables
❖ Don't split large(columns) tables
Optimizing MyISAM queriesOptimizing MyISAM queries
❖ use ANALYZE TABLE or myisamchk
--analyze
❖ myisamchk --sort-index --sort-records=1
❖ avoid complex SELECT queries on MyISAM
tables that are updated frequently
❖ MyISAM supports concurrent inserts
❖ try to avoid VARCHAR, BLOB, and TEXT in
MyISAM tables
❖ Don't split large(columns) tables
❖ use DELAY_KEY_WRITE=1
Optimizing MyISAM queriesOptimizing MyISAM queries
mysql> SELECT @@optimizer_switchG
*************************** 1. row ***************************
@@optimizer_switch: index_merge=on,index_merge_union=on,
index_merge_sort_union=on,
index_merge_intersection=on,
engine_condition_pushdown=on,
index_condition_pushdown=on,
mrr=on,mrr_cost_based=on,
block_nested_loop=on,batched_key_access=off,
materialization=on,semijoin=on,loosescan=on,
firstmatch=on,duplicateweedout=on,
subquery_materialization_cost_based=on,
use_index_extensions=on,
condition_fanout_filter=on,derived_merge=on
Controlling the OptimizerControlling the Optimizer
MySQL 5.7
only
❖ Merging multiple index scans on a SINGLE
table
index_merge=off (default on)
index_merge_union=on
index_merge_sort_union=on
index_merge_intersection=on
low selectivity indexes are very slow with
intersect
Controlling the OptimizerControlling the Optimizer
❖ Selecting different merge algorithms per
table (only for 5.7)
Batched Key Access join /*+ BKA(t1) */
Block Nested-Loop join /*+ BNL(t1, t2) */
Controlling the OptimizerControlling the Optimizer
❖ Optimizing subqueries
Controlling the OptimizerControlling the Optimizer
❖ Optimizing subqueries
Materialization strategy
Controlling the OptimizerControlling the Optimizer
❖ Optimizing subqueries
Materialization strategy
Exists strategy
Controlling the OptimizerControlling the Optimizer
❖ Optimizing subqueries
Materialization strategy
Exists strategy
  (usually preferred when the sub queries
can produce NULL results)
Controlling the OptimizerControlling the Optimizer
❖ Optimizing subqueries
Materialization strategy
Exists strategy
  (usually preferred when the sub queries
can produce NULL results)
subquery_materialization_cost_based
Controlling the OptimizerControlling the Optimizer
❖ use SQL_SMALL_RESUL
❖ If all columns in the index are numeric MySQL will
read only the INDEX
❖ Avoid large amounts of values in IN statements
 values in an IN() list count as a predicates
combined with OR
use eq_range_index_dive_limit to control the index
dives in range comparisons(IN) 5.7
range optimization can't be used with NOT IN()
 /*+ NO_RANGE_OPTIMIZATION(t4 PRIMARY) */
❖ Index Condition Pushdown 5.7
General optimizationGeneral optimization
❖ Avoid full table scans
--max-seeks-for-key=1000
SSD or NVMe
General optimizationGeneral optimization
# Turn tracing on (it's off by default):
SET optimizer_trace="enabled=on";
SELECT ...; # your query here
SELECT * FROM
INFORMATION_SCHEMA.OPTIMIZER_TRACE;
# possibly more queries...
# When done with tracing, disable it:
SET optimizer_trace="enabled=off";
Using the tracerUsing the tracer
"filesort_summary": {
"rows": 100,
"examined_rows": 100,
"number_of_tmp_files": 0,
"sort_buffer_size": 25192,
"sort_mode": "<sort_key,
packed_additional_fields>"
}
Using the tracerUsing the tracer
❖ Consider using INSERT with multiple VALUES
lists
❖ Updates on tables with many indexes may
become slow
❖ Updates with selects in them may block
because of query cache lock contention
❖ Deletes also suffer from the above problems
Changing dataChanging data
❖ Splitting less frequently used columns from
large(column) tables using foreign keys
Optimizing architectureOptimizing architecture
ACID RainACID Rain
Concurrency-Related Attacks onConcurrency-Related Attacks on
Database-Backed Web ApplicationsDatabase-Backed Web Applications
ACID RainACID Rain
Concurrency-Related Attacks onConcurrency-Related Attacks on
Database-Backed Web ApplicationsDatabase-Backed Web Applications
Marian HackMan Marinov
<mm@siteground.com>
THANK YOUTHANK YOUTHANK YOUTHANK YOU
Marian HackMan Marinov
<mm@siteground.com>

Weitere ähnliche Inhalte

Andere mochten auch

Io t introduction to electronics
Io t   introduction to electronicsIo t   introduction to electronics
Io t introduction to electronicsMarian Marinov
 
Securing the network for VMs or Containers
Securing the network for VMs or ContainersSecuring the network for VMs or Containers
Securing the network for VMs or ContainersMarian Marinov
 
Computer vision for your projects
Computer vision for your projectsComputer vision for your projects
Computer vision for your projectsMarian Marinov
 
Lxd the proper way of runing containers
Lxd   the proper way of runing containersLxd   the proper way of runing containers
Lxd the proper way of runing containersMarian Marinov
 
Moving your router inside container
Moving your router inside container Moving your router inside container
Moving your router inside container Marian Marinov
 
Gluster.community.day.2013
Gluster.community.day.2013Gluster.community.day.2013
Gluster.community.day.2013Udo Seidel
 
LUG-BG 2017 - Rangel Ivanov - Spread some butter - BTRFS
LUG-BG 2017 - Rangel Ivanov - Spread some butter - BTRFSLUG-BG 2017 - Rangel Ivanov - Spread some butter - BTRFS
LUG-BG 2017 - Rangel Ivanov - Spread some butter - BTRFSMarian Marinov
 
Protecting your home and office in the era of IoT
Protecting your home and office in the era of IoTProtecting your home and office in the era of IoT
Protecting your home and office in the era of IoTMarian Marinov
 
Why we are migrating to Slackware
Why we are migrating to SlackwareWhy we are migrating to Slackware
Why we are migrating to SlackwareMarian Marinov
 
Performance comparison of Distributed File Systems on 1Gbit networks
Performance comparison of Distributed File Systems on 1Gbit networksPerformance comparison of Distributed File Systems on 1Gbit networks
Performance comparison of Distributed File Systems on 1Gbit networksMarian Marinov
 
nftables - the evolution of Linux Firewall
nftables - the evolution of Linux Firewallnftables - the evolution of Linux Firewall
nftables - the evolution of Linux FirewallMarian Marinov
 

Andere mochten auch (12)

Io t introduction to electronics
Io t   introduction to electronicsIo t   introduction to electronics
Io t introduction to electronics
 
Securing the network for VMs or Containers
Securing the network for VMs or ContainersSecuring the network for VMs or Containers
Securing the network for VMs or Containers
 
Computer vision for your projects
Computer vision for your projectsComputer vision for your projects
Computer vision for your projects
 
Lxd the proper way of runing containers
Lxd   the proper way of runing containersLxd   the proper way of runing containers
Lxd the proper way of runing containers
 
Moving your router inside container
Moving your router inside container Moving your router inside container
Moving your router inside container
 
Gluster.community.day.2013
Gluster.community.day.2013Gluster.community.day.2013
Gluster.community.day.2013
 
LUG-BG 2017 - Rangel Ivanov - Spread some butter - BTRFS
LUG-BG 2017 - Rangel Ivanov - Spread some butter - BTRFSLUG-BG 2017 - Rangel Ivanov - Spread some butter - BTRFS
LUG-BG 2017 - Rangel Ivanov - Spread some butter - BTRFS
 
4 Sessions
4 Sessions4 Sessions
4 Sessions
 
Protecting your home and office in the era of IoT
Protecting your home and office in the era of IoTProtecting your home and office in the era of IoT
Protecting your home and office in the era of IoT
 
Why we are migrating to Slackware
Why we are migrating to SlackwareWhy we are migrating to Slackware
Why we are migrating to Slackware
 
Performance comparison of Distributed File Systems on 1Gbit networks
Performance comparison of Distributed File Systems on 1Gbit networksPerformance comparison of Distributed File Systems on 1Gbit networks
Performance comparison of Distributed File Systems on 1Gbit networks
 
nftables - the evolution of Linux Firewall
nftables - the evolution of Linux Firewallnftables - the evolution of Linux Firewall
nftables - the evolution of Linux Firewall
 

Ähnlich wie Practical my sql performance optimization

Mysql query optimization
Mysql query optimizationMysql query optimization
Mysql query optimizationBaohua Cai
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL ServerRajesh Gunasundaram
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index TuningManikanda kumar
 
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
 
Optimizing MySQL Queries
Optimizing MySQL QueriesOptimizing MySQL Queries
Optimizing MySQL QueriesAchievers Tech
 
How oracle query works (The SQL Optimizers)
How oracle query works (The SQL Optimizers)How oracle query works (The SQL Optimizers)
How oracle query works (The SQL Optimizers)Hosein Zare
 
Basics on SQL queries
Basics on SQL queriesBasics on SQL queries
Basics on SQL queriesKnoldus Inc.
 
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)Hemant Kumar Singh
 
Search and analyze your data with elasticsearch
Search and analyze your data with elasticsearchSearch and analyze your data with elasticsearch
Search and analyze your data with elasticsearchAnton Udovychenko
 
MySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMahesh Salaria
 
Optimized cluster index generation
Optimized cluster index generationOptimized cluster index generation
Optimized cluster index generationRutvik Pensionwar
 
Sphinx new
Sphinx newSphinx new
Sphinx newrit2010
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server DatabasesColdFusionConference
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sSveta Smirnova
 

Ähnlich wie Practical my sql performance optimization (20)

Mysql query optimization
Mysql query optimizationMysql query optimization
Mysql query optimization
 
Optimizing MySQL queries
Optimizing MySQL queriesOptimizing MySQL queries
Optimizing MySQL queries
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
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
 
Optimizing MySQL Queries
Optimizing MySQL QueriesOptimizing MySQL Queries
Optimizing MySQL Queries
 
How oracle query works (The SQL Optimizers)
How oracle query works (The SQL Optimizers)How oracle query works (The SQL Optimizers)
How oracle query works (The SQL Optimizers)
 
Sql performance tuning
Sql performance tuningSql performance tuning
Sql performance tuning
 
Basics on SQL queries
Basics on SQL queriesBasics on SQL queries
Basics on SQL queries
 
Mysql For Developers
Mysql For DevelopersMysql For Developers
Mysql For Developers
 
Indexes overview
Indexes overviewIndexes overview
Indexes overview
 
MySQL JOIN & UNION
MySQL JOIN & UNIONMySQL JOIN & UNION
MySQL JOIN & UNION
 
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
 
Search and analyze your data with elasticsearch
Search and analyze your data with elasticsearchSearch and analyze your data with elasticsearch
Search and analyze your data with elasticsearch
 
MySQL: Know more about open Source Database
MySQL: Know more about open Source DatabaseMySQL: Know more about open Source Database
MySQL: Know more about open Source Database
 
Optimized cluster index generation
Optimized cluster index generationOptimized cluster index generation
Optimized cluster index generation
 
Sphinx new
Sphinx newSphinx new
Sphinx new
 
Sql db optimization
Sql db optimizationSql db optimization
Sql db optimization
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]s
 

Mehr von Marian Marinov

Dev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingDev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingMarian Marinov
 
Basic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsBasic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsMarian Marinov
 
Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Marian Marinov
 
Introduction and replication to DragonflyDB
Introduction and replication to DragonflyDBIntroduction and replication to DragonflyDB
Introduction and replication to DragonflyDBMarian Marinov
 
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMessage Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMarian Marinov
 
How to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfHow to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfMarian Marinov
 
How to survive in the work from home era
How to survive in the work from home eraHow to survive in the work from home era
How to survive in the work from home eraMarian Marinov
 
Improve your storage with bcachefs
Improve your storage with bcachefsImprove your storage with bcachefs
Improve your storage with bcachefsMarian Marinov
 
Control your service resources with systemd
 Control your service resources with systemd  Control your service resources with systemd
Control your service resources with systemd Marian Marinov
 
Comparison of-foss-distributed-storage
Comparison of-foss-distributed-storageComparison of-foss-distributed-storage
Comparison of-foss-distributed-storageMarian Marinov
 
Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Marian Marinov
 
Securing your MySQL server
Securing your MySQL serverSecuring your MySQL server
Securing your MySQL serverMarian Marinov
 
DoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKDoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKMarian Marinov
 
Challenges with high density networks
Challenges with high density networksChallenges with high density networks
Challenges with high density networksMarian Marinov
 
SiteGround building automation
SiteGround building automationSiteGround building automation
SiteGround building automationMarian Marinov
 
Preventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingPreventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingMarian Marinov
 
Managing a lot of servers
Managing a lot of serversManaging a lot of servers
Managing a lot of serversMarian Marinov
 
Let's Encrypt failures
Let's Encrypt failuresLet's Encrypt failures
Let's Encrypt failuresMarian Marinov
 

Mehr von Marian Marinov (20)

Dev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & LoggingDev.bg DevOps March 2024 Monitoring & Logging
Dev.bg DevOps March 2024 Monitoring & Logging
 
Basic presentation of cryptography mechanisms
Basic presentation of cryptography mechanismsBasic presentation of cryptography mechanisms
Basic presentation of cryptography mechanisms
 
Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?Microservices: Benefits, drawbacks and are they for me?
Microservices: Benefits, drawbacks and are they for me?
 
Introduction and replication to DragonflyDB
Introduction and replication to DragonflyDBIntroduction and replication to DragonflyDB
Introduction and replication to DragonflyDB
 
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQMessage Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
 
How to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdfHow to successfully migrate to DevOps .pdf
How to successfully migrate to DevOps .pdf
 
How to survive in the work from home era
How to survive in the work from home eraHow to survive in the work from home era
How to survive in the work from home era
 
Managing sysadmins
Managing sysadminsManaging sysadmins
Managing sysadmins
 
Improve your storage with bcachefs
Improve your storage with bcachefsImprove your storage with bcachefs
Improve your storage with bcachefs
 
Control your service resources with systemd
 Control your service resources with systemd  Control your service resources with systemd
Control your service resources with systemd
 
Comparison of-foss-distributed-storage
Comparison of-foss-distributed-storageComparison of-foss-distributed-storage
Comparison of-foss-distributed-storage
 
Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?Защо и как да обогатяваме знанията си?
Защо и как да обогатяваме знанията си?
 
Securing your MySQL server
Securing your MySQL serverSecuring your MySQL server
Securing your MySQL server
 
Sysadmin vs. dev ops
Sysadmin vs. dev opsSysadmin vs. dev ops
Sysadmin vs. dev ops
 
DoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKDoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDK
 
Challenges with high density networks
Challenges with high density networksChallenges with high density networks
Challenges with high density networks
 
SiteGround building automation
SiteGround building automationSiteGround building automation
SiteGround building automation
 
Preventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel trackingPreventing cpu side channel attacks with kernel tracking
Preventing cpu side channel attacks with kernel tracking
 
Managing a lot of servers
Managing a lot of serversManaging a lot of servers
Managing a lot of servers
 
Let's Encrypt failures
Let's Encrypt failuresLet's Encrypt failures
Let's Encrypt failures
 

Kürzlich hochgeladen

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 

Kürzlich hochgeladen (20)

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 

Practical my sql performance optimization

  • 1. Practical MySQL Practical MySQL  Performance Performance  OptimizationOptimization Marian HackMan MarinovMarian HackMan Marinov <mm@siteground.com><mm@siteground.com> Chief System ArchitectChief System Architect SiteGroundSiteGround
  • 2. Who am I?Who am I?Who am I?Who am I? ❖ Chief System Architect of Siteground.com ❖ Sysadmin since 1996 ❖ Organizer of OpenFest, BG Perl Workshops, LUG-BG and similar :) ❖ Teaching Network Security and Linux System Administration at Sofia University
  • 3. ❖ MySQL 5.7 ❖ Or its equivalent from MariaDB or Percona Requirements...Requirements...
  • 4. ❖ Why am I making this presentation? ❖ Where is the information coming from? MySQL Optimization Documentation ❖ I have skipped the SQL examples as they made the presentation too big ☹ DISCLAMERDISCLAMER
  • 5. ❖ Manual monitoring ❖ Using Monyog MonitoringMonitoring
  • 6. How MySQL uses indexesHow MySQL uses indexes ❖ What type of indexes are there?
  • 7. How MySQL uses indexesHow MySQL uses indexes ❖ What type of indexes are there?  B-Tree  Hash FULLTEXT Spatial
  • 8. ❖ What type of indexes are there? ❖ Which is used for what ?  hash   used for = or <=>   can not be used in ORDER BY   only whole keys can be used for search How MySQL uses indexesHow MySQL uses indexes
  • 9. ❖ What type of indexes are there? ❖ Which is used for what ?  hash How MySQL uses indexesHow MySQL uses indexes
  • 10. ❖ What type of indexes are there? ❖ Which is used for what ?  b-tree   can be used for =, >, >=, <, <=, or BETWEEN comparisons   can be used with LIKE, only if it doesn't start with %   can not be used in the form column1 LIKE column2   can limit the size of the index (prefix) How MySQL uses indexesHow MySQL uses indexes
  • 11. ❖ When is index NOT used How MySQL uses indexesHow MySQL uses indexes
  • 12. ❖ When is index NOT used when the index does not cover all the columns in the where clause How MySQL uses indexesHow MySQL uses indexes
  • 13. ❖ When is index NOT used when the index does not cover all the columns in the where clause when the types don't match: integer used for string index(column) How MySQL uses indexesHow MySQL uses indexes
  • 14. ❖ When is index NOT used when the index does not cover all the columns in the where clause when the types don't match: integer used for string index(column) when != is used How MySQL uses indexesHow MySQL uses indexes
  • 15. ❖ When is index NOT used when the index does not cover all the columns in the where clause when the types don't match: integer used for string index(column) when != is used when you have a multicolumn index but the column you are referencing is not the first one and you don't have a separate index How MySQL uses indexesHow MySQL uses indexes
  • 16. ❖ When is index NOT used  when you have a Btree index but you use distinct on the column How MySQL uses indexesHow MySQL uses indexes
  • 17. ❖ When is index NOT used  when you have a Btree index but you use distinct on the column  when you have a single column indexes but you are actually referencing multiple columns in your WHERE/JOIN How MySQL uses indexesHow MySQL uses indexes
  • 18. ❖ When is index NOT used  when you have a Btree index but you use distinct on the column  when you have a single column indexes but you are actually referencing multiple columns in your WHERE/JOIN  when LIKE is used with % in the begining e.g. LIKE '%name' How MySQL uses indexesHow MySQL uses indexes
  • 19. ❖ When is index NOT used  when you have a Btree index but you use distinct on the column  when you have a single column indexes but you are actually referencing multiple columns in your WHERE/JOIN  when LIKE is used with % in the begining e.g. LIKE '%name'  order of columns in indexes MATTERS How MySQL uses indexesHow MySQL uses indexes
  • 20. 1410864 rows 1 row in set (10.46 sec) 1 row in set (8.33 sec) 1 row in set (6.66 sec) Index hintsIndex hints
  • 21. ❖ IGNORE INDEX Index hintsIndex hints
  • 22. ❖ IGNORE INDEX USE INDEX❖ Index hintsIndex hints
  • 23. ❖ IGNORE INDEX ❖ USE INDEX ❖ FORCE INDEX Index hintsIndex hints
  • 24. ❖ "Waiting for query cache lock" Abusing query cacheAbusing query cache
  • 25. ❖ "Waiting for query cache lock" ❖ SELECT *,NOW() FROM TABLE Abusing query cacheAbusing query cache
  • 26. ❖ "Waiting for query cache lock" ❖ SELECT *,NOW() FROM TABLE ❖ SQL_NO_CACHE Abusing query cacheAbusing query cache
  • 27. ❖ "Waiting for query cache lock" ❖ SELECT *,NOW() FROM TABLE ❖ SQL_NO_CACHE ❖ SET SESSION query_cache_type = OFF; Abusing query cacheAbusing query cache
  • 28. ❖ "Waiting for query cache lock" ❖ SELECT *,NOW() FROM TABLE ❖ SQL_NO_CACHE ❖ SET SESSION query_cache_type = OFF; ❖ Аs of MySQL 5.6.8 query cache is now disabled by default Abusing query cacheAbusing query cache
  • 29. ❖ Large result sets hammer the network... Abusing query cacheAbusing query cache
  • 30. ❖ Large result sets hammer the network... ❖ For caching large results move the cache, closer to the application by caching the results in ProxySQL Abusing query cacheAbusing query cache
  • 31. ❖ InooDB uses only a single index per query Optimizing InnoDB queriesOptimizing InnoDB queries
  • 32. ❖ InooDB uses only a single index per query ❖ If an indexed column cannot contain any NULL values, declare it as NOT NULL Optimizing InnoDB queriesOptimizing InnoDB queries
  • 33. ❖ InooDB uses only a single index per query ❖ If an indexed column cannot contain any NULL values, declare it as NOT NULL ❖ START TRANSACTION READ ONLY Optimizing InnoDB queriesOptimizing InnoDB queries
  • 34. ❖ use ANALYZE TABLE or myisamchk --analyze Optimizing MyISAM queriesOptimizing MyISAM queries
  • 35. ❖ use ANALYZE TABLE or myisamchk --analyze ❖ myisamchk --sort-index --sort-records=1 Optimizing MyISAM queriesOptimizing MyISAM queries
  • 36. ❖ use ANALYZE TABLE or myisamchk --analyze ❖ myisamchk --sort-index --sort-records=1 ❖ avoid complex SELECT queries on MyISAM tables that are updated frequently Optimizing MyISAM queriesOptimizing MyISAM queries
  • 37. ❖ use ANALYZE TABLE or myisamchk --analyze ❖ myisamchk --sort-index --sort-records=1 ❖ avoid complex SELECT queries on MyISAM tables that are updated frequently ❖ MyISAM supports concurrent inserts Optimizing MyISAM queriesOptimizing MyISAM queries
  • 38. ❖ use ANALYZE TABLE or myisamchk --analyze ❖ myisamchk --sort-index --sort-records=1 ❖ avoid complex SELECT queries on MyISAM tables that are updated frequently ❖ MyISAM supports concurrent inserts concurrent_insert = 0 (disabled) concurrent_insert = 1 (auto) concurrent_insert = 1 (always, even with deleted rows) Optimizing MyISAM queriesOptimizing MyISAM queries
  • 39. ❖ use ANALYZE TABLE or myisamchk --analyze ❖ myisamchk --sort-index --sort-records=1 ❖ avoid complex SELECT queries on MyISAM tables that are updated frequently ❖ MyISAM supports concurrent inserts ❖ try to avoid VARCHAR, BLOB, and TEXT in MyISAM tables Optimizing MyISAM queriesOptimizing MyISAM queries
  • 40. ❖ use ANALYZE TABLE or myisamchk --analyze ❖ myisamchk --sort-index --sort-records=1 ❖ avoid complex SELECT queries on MyISAM tables that are updated frequently ❖ MyISAM supports concurrent inserts ❖ try to avoid VARCHAR, BLOB, and TEXT in MyISAM tables ❖ Don't split large(columns) tables Optimizing MyISAM queriesOptimizing MyISAM queries
  • 41. ❖ use ANALYZE TABLE or myisamchk --analyze ❖ myisamchk --sort-index --sort-records=1 ❖ avoid complex SELECT queries on MyISAM tables that are updated frequently ❖ MyISAM supports concurrent inserts ❖ try to avoid VARCHAR, BLOB, and TEXT in MyISAM tables ❖ Don't split large(columns) tables ❖ use DELAY_KEY_WRITE=1 Optimizing MyISAM queriesOptimizing MyISAM queries
  • 42. mysql> SELECT @@optimizer_switchG *************************** 1. row *************************** @@optimizer_switch: index_merge=on,index_merge_union=on, index_merge_sort_union=on, index_merge_intersection=on, engine_condition_pushdown=on, index_condition_pushdown=on, mrr=on,mrr_cost_based=on, block_nested_loop=on,batched_key_access=off, materialization=on,semijoin=on,loosescan=on, firstmatch=on,duplicateweedout=on, subquery_materialization_cost_based=on, use_index_extensions=on, condition_fanout_filter=on,derived_merge=on Controlling the OptimizerControlling the Optimizer MySQL 5.7 only
  • 43. ❖ Merging multiple index scans on a SINGLE table index_merge=off (default on) index_merge_union=on index_merge_sort_union=on index_merge_intersection=on low selectivity indexes are very slow with intersect Controlling the OptimizerControlling the Optimizer
  • 44. ❖ Selecting different merge algorithms per table (only for 5.7) Batched Key Access join /*+ BKA(t1) */ Block Nested-Loop join /*+ BNL(t1, t2) */ Controlling the OptimizerControlling the Optimizer
  • 45. ❖ Optimizing subqueries Controlling the OptimizerControlling the Optimizer
  • 46. ❖ Optimizing subqueries Materialization strategy Controlling the OptimizerControlling the Optimizer
  • 47. ❖ Optimizing subqueries Materialization strategy Exists strategy Controlling the OptimizerControlling the Optimizer
  • 48. ❖ Optimizing subqueries Materialization strategy Exists strategy   (usually preferred when the sub queries can produce NULL results) Controlling the OptimizerControlling the Optimizer
  • 49. ❖ Optimizing subqueries Materialization strategy Exists strategy   (usually preferred when the sub queries can produce NULL results) subquery_materialization_cost_based Controlling the OptimizerControlling the Optimizer
  • 50. ❖ use SQL_SMALL_RESUL ❖ If all columns in the index are numeric MySQL will read only the INDEX ❖ Avoid large amounts of values in IN statements  values in an IN() list count as a predicates combined with OR use eq_range_index_dive_limit to control the index dives in range comparisons(IN) 5.7 range optimization can't be used with NOT IN()  /*+ NO_RANGE_OPTIMIZATION(t4 PRIMARY) */ ❖ Index Condition Pushdown 5.7 General optimizationGeneral optimization
  • 51. ❖ Avoid full table scans --max-seeks-for-key=1000 SSD or NVMe General optimizationGeneral optimization
  • 52. # Turn tracing on (it's off by default): SET optimizer_trace="enabled=on"; SELECT ...; # your query here SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE; # possibly more queries... # When done with tracing, disable it: SET optimizer_trace="enabled=off"; Using the tracerUsing the tracer
  • 53. "filesort_summary": { "rows": 100, "examined_rows": 100, "number_of_tmp_files": 0, "sort_buffer_size": 25192, "sort_mode": "<sort_key, packed_additional_fields>" } Using the tracerUsing the tracer
  • 54. ❖ Consider using INSERT with multiple VALUES lists ❖ Updates on tables with many indexes may become slow ❖ Updates with selects in them may block because of query cache lock contention ❖ Deletes also suffer from the above problems Changing dataChanging data
  • 55. ❖ Splitting less frequently used columns from large(column) tables using foreign keys Optimizing architectureOptimizing architecture
  • 56. ACID RainACID Rain Concurrency-Related Attacks onConcurrency-Related Attacks on Database-Backed Web ApplicationsDatabase-Backed Web Applications ACID RainACID Rain Concurrency-Related Attacks onConcurrency-Related Attacks on Database-Backed Web ApplicationsDatabase-Backed Web Applications Marian HackMan Marinov <mm@siteground.com>
  • 57. THANK YOUTHANK YOUTHANK YOUTHANK YOU Marian HackMan Marinov <mm@siteground.com>