SlideShare a Scribd company logo
DATABASE 
OPTIMIZATION 
_by Oleksii Prohonnyi
The degree of normality 
in a database 
is inversely proportional to that 
of its DBA.
Database Optimization (MySQL)
WHEN DO WE OPTIMIZE 
THE DATABASE?
Database Optimization (MySQL)
You should get your home page 
down to 1.5 seconds. 
(Google’s threshold for being 
considered a “fast” website) 
Best Practices for Speeding Up Your Web Site by Yahoo
PROFILE FIRST, 
OPTIMIZE LAST
Database Optimization (MySQL)
The basic rule of optimization is to 
never assume - always verify, 
using actual data.
PEAR_Benchmark 
Stores microtime() values before and after 
the query for later observation, and the 
difference would be the timing of the query 
with good accuracy. 
Package Information: Benchmark by The PHP Group
PEAR_Benchmark 
Example 1: Automatic profiling start, stop, 
and output.
Database Optimization (MySQL)
PEAR_Benchmark 
Example 2: Manual profiling start, stop, 
and output.
Database Optimization (MySQL)
Zend_Db_Profiler 
Built-in support for profiling in Zend 
Framework.
Database Optimization (MySQL)
CWebLogRoute 
Built-in support for profiling in Yii 
Framework.
Database Optimization (MySQL)
Database Optimization (MySQL)
Database Optimization (MySQL)
It's very important to profile using 
a relevant dataset. 
You should create a test machine that 
resembles your live dataset as much as 
possible to get relevant data.
Another important note is to avoid 
looking at cached results. 
- SQL_NO_CACHE 
- MySQL Caches 
- OS Caches 
- Hardware Caches 
Query Profiling with MySQL: Bypassing caches by Peter Zaitsev
The Slow Query Log 
Profiles queries that are used by daemons 
and cron jobs and log the results to a file. 
5.2.5. The Slow Query Log by Oracle Corporation
OPTIMIZING 
PERFORMANCE
Database Optimization (MySQL)
There are 4 basic ways to optimize 
query performance: 
- Rewrite the queries 
- Change indexing strategy 
- Change schema 
- Use an external cache
EXAMINING QUERY 
EXECUTION PLANS
EXPLAIN 
Add the reserved word 'EXPLAIN' at the 
beginning of your query to get the execution 
plan for the query. 
8.2.2. EXPLAIN Output Format by Oracle Corporation
Database Optimization (MySQL)
Database Optimization (MySQL)
EXPLAIN limitations: 
- EXPLAIN can be wrong 
- EXPLAIN works for SELECT only 
- EXPLAIN may take long time 
- Estimated number of rows may be very 
inaccurate 
…. 
MySQL EXPLAIN limits and errors by Peter Zaitsev
COMMON 
OPTIMIZATIONS
Database Optimization (MySQL)
1. Looping queries 
One of the most common mistakes is to 
query in a loop without need. 
Most likely looped SELECT queries can be 
rewritten as a JOIN.
Database Optimization (MySQL)
2. Picking only needed columns 
Picking only the needed columns is a good 
general practice to use, and avoids those 
problems.
Database Optimization (MySQL)
3. Filtering rows correctly and 
using indexes 
Our main goal is to select the smallest 
amount of rows we need and doing so in 
the fastest way possible.
Filtering rows correctly and 
using indexes 
Example - fetching users created in the 
last 4 weeks.
Database Optimization (MySQL)
Filtering rows correctly and 
using indexes 
Example - select the lowest priced fruit from 
several fruit types.
Database Optimization (MySQL)
4. Indexing correctly 
Using more indexes than is necessary can 
have adverse affects - as it slows down 
the operation of INSERT and UPDATE 
queries, while taking up more memory. 
Do you always need index on WHERE column? by Vadim Tkachenko
5. Picking the right engine 
for your data 
MySQL has a pluggable engine design, 
which allows you to use different engine 
types to store your data, each with its own 
advantages and drawbacks. 
Chapter 14. Storage Engines by Oracle Corporation
Database Optimization (MySQL)
CACHING
There are many caching strategies. 
Common options include caching to disk 
(files) or caching to memory (using solutions 
such as memcache or APC). 
Another form of caching is to the database – 
by de-normalizing the schema to store data 
that is the result of expensive to run queries.
S4I8GMA UKRAINE
Oleksii Prohonnyi 
facebook.com/oprohonnyi 
linkedin.com/in/oprohonnyi

More Related Content

PPTX
SQL Operations : Part 3 (Database Restore & Database Shrink) - SLT
PPTX
Application Performance Tuning Techniques
PPTX
Oracle startup phases and concepts
PPTX
Web application penetration using SQLMAP.
PDF
SQL INJECTIONS EVERY TESTER NEEDS TO KNOW
DOCX
45 o gemido de elias
PPTX
Self-Tuning MySQL - a Hosting Provider's Unfair Advantage
PDF
Mentor 2015 Certificate
SQL Operations : Part 3 (Database Restore & Database Shrink) - SLT
Application Performance Tuning Techniques
Oracle startup phases and concepts
Web application penetration using SQLMAP.
SQL INJECTIONS EVERY TESTER NEEDS TO KNOW
45 o gemido de elias
Self-Tuning MySQL - a Hosting Provider's Unfair Advantage
Mentor 2015 Certificate

Viewers also liked (10)

PPT
PDF
Caso de Sucesso WK - Akira - Distribuidora de Cartões Telefônicos
PDF
Poster - Personal Competencies Model
PDF
Resume (2)
DOC
curriculum vitae(Nilesh Thummar)
PPT
HR2020 Mediawijs - Jos Koppelaar
PDF
Desbarajuste farmacológico. amf
PDF
Tswportfolio images
PPTX
Thinking styles in the quran
PPTX
Leptospirosis- Dr Ajay Tyagi
Caso de Sucesso WK - Akira - Distribuidora de Cartões Telefônicos
Poster - Personal Competencies Model
Resume (2)
curriculum vitae(Nilesh Thummar)
HR2020 Mediawijs - Jos Koppelaar
Desbarajuste farmacológico. amf
Tswportfolio images
Thinking styles in the quran
Leptospirosis- Dr Ajay Tyagi
Ad

Similar to Database Optimization (MySQL) (20)

PDF
Optimizing Symfony Application Performance
PDF
Top Ten Mistakes Found in Oracle Database Environments
PDF
Quick And Easy Guide To Speeding Up MySQL for web developers
PPT
High Performance Mysql
PPTX
Data mining and warehousing (uca15 e04)
PDF
Buy ebook Java Performance Tuning Second Edition Jack Shirazi cheap price
DOCX
sample1
PPT
scale_perf_best_practices
PDF
iLeap- Test Automation Framework- Impetus White Paper
PDF
Why Automation is Required in Software Testing - OSSCamp 2014
PDF
[Ebooks PDF] download Java Performance Tuning Second Edition Jack Shirazi ful...
PDF
Java Performance Tuning Second Edition Jack Shirazi
PDF
Java Performance Tuning Second Edition Jack Shirazi
PDF
Java Tuning White Paper
PPT
MySQL Performance Tuning at COSCUP 2014
PDF
Data Driven Framework in Selenium
PDF
Key to a successful Exadata POC
PDF
Drupal Performance : DrupalCamp North
PPT
40179_Bednar.ppt Oracle Database Upgrade Assistant
PDF
Advanced Techniques to Build an Efficient Selenium Framework
Optimizing Symfony Application Performance
Top Ten Mistakes Found in Oracle Database Environments
Quick And Easy Guide To Speeding Up MySQL for web developers
High Performance Mysql
Data mining and warehousing (uca15 e04)
Buy ebook Java Performance Tuning Second Edition Jack Shirazi cheap price
sample1
scale_perf_best_practices
iLeap- Test Automation Framework- Impetus White Paper
Why Automation is Required in Software Testing - OSSCamp 2014
[Ebooks PDF] download Java Performance Tuning Second Edition Jack Shirazi ful...
Java Performance Tuning Second Edition Jack Shirazi
Java Performance Tuning Second Edition Jack Shirazi
Java Tuning White Paper
MySQL Performance Tuning at COSCUP 2014
Data Driven Framework in Selenium
Key to a successful Exadata POC
Drupal Performance : DrupalCamp North
40179_Bednar.ppt Oracle Database Upgrade Assistant
Advanced Techniques to Build an Efficient Selenium Framework
Ad

More from Oleksii Prohonnyi (20)

PPTX
Utility libraries to make your life easier
PPTX
Dive into Angular, part 4: Angular 2.0
PPTX
Dive into Angular, part 5: Experience
PPTX
Dive into Angular, part 3: Performance
PPTX
Dive into Angular, part 2: Architecture
PPTX
Dive into Angular, part 1: Introduction
PPTX
Cycle.js overview
PPTX
Moment.js overview
PPTX
Bower introduction
PPTX
JavaScript Presentation Frameworks and Libraries
PPTX
Introduction to D3.js
PPTX
Conference DotJS 2015 Paris review
PPTX
Asm.js introduction
PPTX
Code review process with JetBrains UpSource
PPTX
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
PPTX
OpenLayer's basics
PPTX
Front-end rich JavaScript application creation (Backbone.js)
PPTX
Как создать сайт за 2 часа? (Wordpress)
PPT
Разработка веб-сайта. Сайт. Зачем он?
PPTX
Google Chrome DevTools features overview
Utility libraries to make your life easier
Dive into Angular, part 4: Angular 2.0
Dive into Angular, part 5: Experience
Dive into Angular, part 3: Performance
Dive into Angular, part 2: Architecture
Dive into Angular, part 1: Introduction
Cycle.js overview
Moment.js overview
Bower introduction
JavaScript Presentation Frameworks and Libraries
Introduction to D3.js
Conference DotJS 2015 Paris review
Asm.js introduction
Code review process with JetBrains UpSource
D3.JS Tips & Tricks (export to svg, crossfilter, maps etc.)
OpenLayer's basics
Front-end rich JavaScript application creation (Backbone.js)
Как создать сайт за 2 часа? (Wordpress)
Разработка веб-сайта. Сайт. Зачем он?
Google Chrome DevTools features overview

Recently uploaded (20)

PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Digital Strategies for Manufacturing Companies
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
L1 - Introduction to python Backend.pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Nekopoi APK 2025 free lastest update
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
top salesforce developer skills in 2025.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
ai tools demonstartion for schools and inter college
How to Migrate SBCGlobal Email to Yahoo Easily
Digital Strategies for Manufacturing Companies
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Which alternative to Crystal Reports is best for small or large businesses.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Navsoft: AI-Powered Business Solutions & Custom Software Development
Upgrade and Innovation Strategies for SAP ERP Customers
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
L1 - Introduction to python Backend.pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
VVF-Customer-Presentation2025-Ver1.9.pptx
Odoo Companies in India – Driving Business Transformation.pdf
Nekopoi APK 2025 free lastest update
How to Choose the Right IT Partner for Your Business in Malaysia
Operating system designcfffgfgggggggvggggggggg
top salesforce developer skills in 2025.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
ai tools demonstartion for schools and inter college

Database Optimization (MySQL)

  • 1. DATABASE OPTIMIZATION _by Oleksii Prohonnyi
  • 2. The degree of normality in a database is inversely proportional to that of its DBA.
  • 4. WHEN DO WE OPTIMIZE THE DATABASE?
  • 6. You should get your home page down to 1.5 seconds. (Google’s threshold for being considered a “fast” website) Best Practices for Speeding Up Your Web Site by Yahoo
  • 9. The basic rule of optimization is to never assume - always verify, using actual data.
  • 10. PEAR_Benchmark Stores microtime() values before and after the query for later observation, and the difference would be the timing of the query with good accuracy. Package Information: Benchmark by The PHP Group
  • 11. PEAR_Benchmark Example 1: Automatic profiling start, stop, and output.
  • 13. PEAR_Benchmark Example 2: Manual profiling start, stop, and output.
  • 15. Zend_Db_Profiler Built-in support for profiling in Zend Framework.
  • 17. CWebLogRoute Built-in support for profiling in Yii Framework.
  • 21. It's very important to profile using a relevant dataset. You should create a test machine that resembles your live dataset as much as possible to get relevant data.
  • 22. Another important note is to avoid looking at cached results. - SQL_NO_CACHE - MySQL Caches - OS Caches - Hardware Caches Query Profiling with MySQL: Bypassing caches by Peter Zaitsev
  • 23. The Slow Query Log Profiles queries that are used by daemons and cron jobs and log the results to a file. 5.2.5. The Slow Query Log by Oracle Corporation
  • 26. There are 4 basic ways to optimize query performance: - Rewrite the queries - Change indexing strategy - Change schema - Use an external cache
  • 28. EXPLAIN Add the reserved word 'EXPLAIN' at the beginning of your query to get the execution plan for the query. 8.2.2. EXPLAIN Output Format by Oracle Corporation
  • 31. EXPLAIN limitations: - EXPLAIN can be wrong - EXPLAIN works for SELECT only - EXPLAIN may take long time - Estimated number of rows may be very inaccurate …. MySQL EXPLAIN limits and errors by Peter Zaitsev
  • 34. 1. Looping queries One of the most common mistakes is to query in a loop without need. Most likely looped SELECT queries can be rewritten as a JOIN.
  • 36. 2. Picking only needed columns Picking only the needed columns is a good general practice to use, and avoids those problems.
  • 38. 3. Filtering rows correctly and using indexes Our main goal is to select the smallest amount of rows we need and doing so in the fastest way possible.
  • 39. Filtering rows correctly and using indexes Example - fetching users created in the last 4 weeks.
  • 41. Filtering rows correctly and using indexes Example - select the lowest priced fruit from several fruit types.
  • 43. 4. Indexing correctly Using more indexes than is necessary can have adverse affects - as it slows down the operation of INSERT and UPDATE queries, while taking up more memory. Do you always need index on WHERE column? by Vadim Tkachenko
  • 44. 5. Picking the right engine for your data MySQL has a pluggable engine design, which allows you to use different engine types to store your data, each with its own advantages and drawbacks. Chapter 14. Storage Engines by Oracle Corporation
  • 47. There are many caching strategies. Common options include caching to disk (files) or caching to memory (using solutions such as memcache or APC). Another form of caching is to the database – by de-normalizing the schema to store data that is the result of expensive to run queries.
  • 49. Oleksii Prohonnyi facebook.com/oprohonnyi linkedin.com/in/oprohonnyi