SlideShare ist ein Scribd-Unternehmen logo
1 von 49
© 2013 by Markus Winand
Indexes
The Neglected Performance
All-Rounder
Not
always that obvious,
unfortunately!
iStockPhoto
wildpixel
Takeaway #1: Pandemic Scale
It affects you!
(Symbolic image; not real data)
http://upload.wikimedia.org/wikipedia/commons/c/c7/2009_world_subdivisions_flu_pandemic.png
Takeaway #2: Caused by Success
Copyright © 2013 Telerik, Inc. All rights reserved
Takeaway #3: It’s Not Your Fault
http://simpsonswiki.com/wiki/File:I_Didn%27t_Do_It!_Volume_III.png
© 2013 by Markus Winand
The Problem
Improper Index Use
The Problem: Improper Index Use
“A very common cause of performance
problems is lack of proper indexes or the
use of queries that are not using
existing indexes.”
—Buda Consulting
http://www.budaconsulting.com/Portals/52677/docs/top_5_tech_brief.pdf
The Problem: Improper Index Use
“A very common cause of performance
problems is lack of proper indexes or the
use of queries that are not using
existing indexes.”
—Buda Consulting
http://www.budaconsulting.com/Portals/52677/docs/top_5_tech_brief.pdf
Quantifying the Problem
Percona White Paper:
Reasons of performance problems
that caused production downtime:
38% bad SQL
15% schema and indexing
http://www.percona.com/files/white-papers/causes-of-downtime-in-mysql.pdf
Quantifying the Problem
Survey by sqlskills.com:
Root causes of the last few SQL
Server performance problems:
27% T-SQL
19% Poor indexing
http://www.sqlskills.com/blogs/paul/survey-what-are-the-most-common-causes-of-performance-problems/
Quantifying the Problem
Craig S. Mullins (strategist and researcher):
„As much as 75% of poor relational performance
is caused by "bad" SQL and application code.”
Noel Yuhanna (Forrester Research):
„The key difficulties surrounding performance
continue to be poorly written SQL statements,
improper DBMS configuration and a lack of clear
understanding of how to tune databases to solve
performance issues.”
Quantifying the Problem
My observation:
~50% of SQL performance problems
are caused by improper index use
© 2013 by Markus Winand
The Root Cause
© 2013 by Markus Winand
The Root Cause
Admins are Indexing
The Root Cause: DBAs are Indexing
How did databases
work before SQL?
The Root Cause: DBAs are Indexing
Index use was intrinsically
tied to the queries.
The Root Cause: DBAs are Indexing
Example: dBase
Developers had to...
...use indexes explicitly when searching:
!"#$%&'"($#)$*+!#,&+-"
$$$.%&'$/%&+&'
...take care of index maintenance:
!"#$%&'"($#)$*+!#,&+-"0$%'(1
$$$$+22"&'
The Root Cause: DBAs are Indexing
SQL is an abstraction that only
defines the logical view.
The actual SQL implementation
takes care of everything else.
The Root Cause: DBAs are Indexing
Transactions
Constraints
Views
Tables
Data
manipulation
Queries
SQL (language)
has:
SQL Databases (software)
have:
The Root Cause: DBAs are Indexing
Backup
& recovery
Storage
management
Bugs &
patches
Tuning
parameters
Transactions
Constraints
Views
Tables
Data
manipulation
Queries
SQL (language)
has:
SQL Databases (software)
have:
High
Availability
The Root Cause: DBAs are Indexing
Indexes
Backup
& recovery
Storage
management
Bugs &
patches
Tuning
parameters
Transactions
Constraints
Views
Tables
Data
manipulation
Queries
SQL (language)
has:
SQL Databases (software)
have:
High
Availability
The Root Cause: DBAs are Indexing
Indexes
Backup
& recovery
Storage
management
Bugs &
patches
Tuning
parameters
Transactions
Constraints
Views
Tables
Data
manipulation
Queries
SQL Databases (software)
have:
Developers
High
Availability
The Root Cause: DBAs are Indexing
Indexes
Backup
& recovery
Storage
management
Bugs &
patches
Tuning
parameters
Transactions
Constraints
Views
Tables
Data
manipulation
Queries
Developers Administrators
High
Availability
The Root Cause: DBAs are Indexing
Indexing is considered a system
tuning task that belongs to the
administrators responsibilities.
The Root Cause: DBAs are Indexing
A misconception that causes new problems:
The Root Cause: DBAs are Indexing
A misconception that causes new problems:
DBAs don’t know
the queries
Have to “investigate”
to find the queries.
It is time consuming and
almost always incomplete.
by G-10gian82
deviantart.com
The Root Cause: DBAs are Indexing
A misconception that causes new problems:
DBAs don’t know
the queries
Have to “investigate”
to find the queries.
It is time consuming and
almost always incomplete.
DBAs can’t change
the queries
Can make the index
match the query.
Can’t make the query
match the index!
© 2013 by Markus Winand
The Solution
© 2013 by Markus Winand
The Solution
Indexing is a
Development Task
The Solution: It’s a Dev Task
Indexes
Backup
& recovery
Storage
management
Tuning
parameters
Transactions
Constraints
Views
Tables
Data
manipulation
Queries
Developers Administrators
High
Availability
Bugs &
patches
The Solution: It’s a Dev Task
Indexes
Backup
& recovery
Storage
management
Tuning
parameters
Transactions
Constraints
Views
Tables
Data
manipulation
Queries
Developers Administrators
Must match!
High
Availability
Bugs &
patches
Another Problem: It’s not Taught
Indexes are not part of the pure SQL (language) literature
because indexes are not part of the SQL standard.
11 SQL books analyzed: only 1.0% of the pages are
about indexes (70 out of 7330 pages).
Examples:
Oracle SQL by Example: 2.0% (19/960)
Beginning DBs with PostgreSQL: 0.8% (5/664)
Learning SQL: 3.3% (11/336 — highest rate in class)
Another Problem: It’s not Taught
Proper index usage is sometimes covered in database
tuning books but is always buried between hundreds of
pages of HW, OS and DB parameterization topics.
14 database administration books analyzed: 5.1% of the
pages are about indexes (307 out of 6069 pages).
Examples:
Oracle Performance Survival Guide: 5.2% (38/730)
High Performance MySQL: 8% (55/684)
PostgreSQL 9 High Performance: 5.8% (27/468)
Another Problem: It’s not Taught
Consequence:
Developers don’t know how to use
indexes properly.
Another Problem: It’s not Taught
Consequence:
Developers don’t know how to use
indexes properly.
Results of the 3-minute online quiz:
http://use-the-index-luke.com/3-minute-test
5 questions: each about a specific index
usage pattern.
Non-representative!
Q1: Good or Bad? (Function use)
345675$89:5;$#<*,%'($=9$#<*$>!"#$%&'()*+?@
A5B537$#"(#0$'+#",C)*D-&
$$E4=F$#<*
$/G545$,-%./012!"#$%&'()*+0$HIIIIH?$J$H1KLMH@
3-Minute Quiz: Indexing Skills
Q1: Good or Bad? (Function use)
345675$89:5;$#<*,%'($=9$#<*$>!"#$%&'()*+?@
A5B537$#"(#0$'+#",C)*D-&
$$E4=F$#<*
$/G545$,-%./012!"#$%&'()*+0$HIIIIH?$J$H1KLMH@
 


3-Minute Quiz: Indexing Skills
Q1: Good or Bad? (Function use)
345675$89:5;$#*,%'($=9$#*$!#$%'()*+?@
A5B537$#(#0$'+#,C)*D-
$$E4=F$#*
$/G545$,-%./012!#$%'()*+0$HIIIIH?$J$H1KLMH@
3-Minute Quiz: Indexing Skills
3-Minute Quiz: Indexing Skills
Q2: Good or Bad? (Indexed Top-N, no IOS)
345675$89:5;$#*,%'($=9$#*$+0$'+#,C)*?@
A5B537$%'0$+0$'+#,C)*
$$E4=F$#*
$/G545$+$J$NL
$=4:54$OI$'+#,C)*$:5A3
$3454,67@
3-Minute Quiz: Indexing Skills
Q2: Good or Bad? (Indexed Top-N, no IOS)
345675$89:5;$#*,%'($=9$#*$+0$'+#,C)*?@
A5B537$%'0$+0$'+#,C)*
$$E4=F$#*
$/G545$+$J$NL
$=4:54$OI$'+#,C)*$:5A3
$3454,67@

 


Understandable
controversy!
3-Minute Quiz: Indexing Skills
Q3: Good or Bad? (Column order)
CREATE INDEX tbl_idx ON tbl (a, b);
SELECT id, a, b FROM tbl
WHERE a = $1 AND b = $2;
SELECT id, a, b FROM tbl
WHERE b = $1;
3-Minute Quiz: Indexing Skills
Q3: Good or Bad? (Column order)
CREATE INDEX tbl_idx ON tbl (a, b);
SELECT id, a, b FROM tbl
WHERE a = $1 AND b = $2;
SELECT id, a, b FROM tbl
WHERE b = $1;
3-Minute Quiz: Indexing Skills
Q4: Good or Bad? (Indexing LIKE)
CREATE INDEX tbl_idx
ON tbl (text varchar_pattern_ops);
SELECT id, text
FROM tbl
WHERE text LIKE '%TERM%';
3-Minute Quiz: Indexing Skills
Q4: Good or Bad? (Indexing LIKE)
CREATE INDEX tbl_idx
ON tbl (text varchar_pattern_ops);
SELECT id, text
FROM tbl
WHERE text LIKE '%TERM%';
3-Minute Quiz: Indexing Skills
Q5: Good or Bad? (equality vs. ranges)
CREATE INDEX tbl_idx
ON tbl (date_col, state);
SELECT id, date_col, state FROM tbl
WHERE date_col =
CURRENT_DATE - INTERVAL '5' YEAR
AND state = 'X';
3-Minute Quiz: Indexing Skills
Q5: Good or Bad? (equality vs. ranges)
CREATE INDEX tbl_idx
ON tbl (date_col, state);
SELECT id, date_col, state FROM tbl
WHERE date_col =
CURRENT_DATE - INTERVAL '5' YEAR
AND state = 'X';
Indexes: The Neglected All-Rounder
Everybody knows indexing is
important for performance,
yet nobody takes the time to
learn and apply is properly.
Indexes: The Neglected All-Rounder
Index details are hardly known.
! “Details” like column-order or equality vs. range
conditions must be learned and understood.
Only one index capability is used: finding data quickly
! Indexes have three capabilities (powers):
finding data, clustering data, and sorting data.
Indexing is done from single query perspective.
! Should be done from application perspective
(considering all queries). It’s a design task!
Indexes: The Neglected All-Rounder
Are you just adding indexes
or
are you designing indexes?
About Markus Winand
Tuning developers for
high SQL performance
Training  co (one-man show):
winand.at
Geeky blog:
use-the-index-luke.com
Author of:
SQL Performance Explained

Weitere ähnliche Inhalte

Was ist angesagt?

MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
Manikanda kumar
 

Was ist angesagt? (20)

How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, Really
 
검색엔진이 데이터를 다루는 법 김종민
검색엔진이 데이터를 다루는 법 김종민검색엔진이 데이터를 다루는 법 김종민
검색엔진이 데이터를 다루는 법 김종민
 
Flexible Indexing with Postgres
Flexible Indexing with PostgresFlexible Indexing with Postgres
Flexible Indexing with Postgres
 
Percona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationPercona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimization
 
GraphQL Basics
GraphQL BasicsGraphQL Basics
GraphQL Basics
 
Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
 
MySQL Performance for DevOps
MySQL Performance for DevOpsMySQL Performance for DevOps
MySQL Performance for DevOps
 
Redis + Apache Spark = Swiss Army Knife Meets Kitchen Sink
Redis + Apache Spark = Swiss Army Knife Meets Kitchen SinkRedis + Apache Spark = Swiss Army Knife Meets Kitchen Sink
Redis + Apache Spark = Swiss Army Knife Meets Kitchen Sink
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
Indexes in postgres
Indexes in postgresIndexes in postgres
Indexes in postgres
 
MySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsMySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 Tips
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performance
 
Fluentd with MySQL
Fluentd with MySQLFluentd with MySQL
Fluentd with MySQL
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
The PostgreSQL Query Planner
The PostgreSQL Query PlannerThe PostgreSQL Query Planner
The PostgreSQL Query Planner
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDB
 
Introducing ELK
Introducing ELKIntroducing ELK
Introducing ELK
 
Cracking the Interview Skills (Coding, Soft Skills, Product Management) Handouts
Cracking the Interview Skills (Coding, Soft Skills, Product Management) HandoutsCracking the Interview Skills (Coding, Soft Skills, Product Management) Handouts
Cracking the Interview Skills (Coding, Soft Skills, Product Management) Handouts
 
MariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAs
 

Ähnlich wie Indexes: The neglected performance all rounder

Chapter 5 data processing
Chapter 5 data processingChapter 5 data processing
Chapter 5 data processing
UMaine
 
IT 655 Milestone One Guidelines and Rubric Presenta.docx
 IT 655 Milestone One Guidelines and Rubric   Presenta.docx IT 655 Milestone One Guidelines and Rubric   Presenta.docx
IT 655 Milestone One Guidelines and Rubric Presenta.docx
aryan532920
 
Sybase job interview_preparation_guide
Sybase job interview_preparation_guideSybase job interview_preparation_guide
Sybase job interview_preparation_guide
NV Suresh Kumar
 
INTRODUCTION TO DATABASE-SYSTEMS PRESENTATION.pptx
INTRODUCTION TO DATABASE-SYSTEMS PRESENTATION.pptxINTRODUCTION TO DATABASE-SYSTEMS PRESENTATION.pptx
INTRODUCTION TO DATABASE-SYSTEMS PRESENTATION.pptx
renadmajid789
 
Oracle performance project public
Oracle performance project publicOracle performance project public
Oracle performance project public
Carlos Oliveira
 
Term Paper VirtualizationDue Week 10 and worth 210 pointsThis.docx
Term Paper VirtualizationDue Week 10 and worth 210 pointsThis.docxTerm Paper VirtualizationDue Week 10 and worth 210 pointsThis.docx
Term Paper VirtualizationDue Week 10 and worth 210 pointsThis.docx
mattinsonjanel
 

Ähnlich wie Indexes: The neglected performance all rounder (20)

Top-10-Java-Performance-Problems.pdf
Top-10-Java-Performance-Problems.pdfTop-10-Java-Performance-Problems.pdf
Top-10-Java-Performance-Problems.pdf
 
Chapter 5 data processing
Chapter 5 data processingChapter 5 data processing
Chapter 5 data processing
 
Designing for Performance: Database Related Worst Practices
Designing for Performance: Database Related Worst PracticesDesigning for Performance: Database Related Worst Practices
Designing for Performance: Database Related Worst Practices
 
IT 655 Milestone One Guidelines and Rubric Presenta.docx
 IT 655 Milestone One Guidelines and Rubric   Presenta.docx IT 655 Milestone One Guidelines and Rubric   Presenta.docx
IT 655 Milestone One Guidelines and Rubric Presenta.docx
 
Best Laid Plans: Saving Time, Money and Trouble with Optimal Forecasting
Best Laid Plans: Saving Time, Money and Trouble with Optimal ForecastingBest Laid Plans: Saving Time, Money and Trouble with Optimal Forecasting
Best Laid Plans: Saving Time, Money and Trouble with Optimal Forecasting
 
Database Performance Improvements Environment Document Requirement Planning A...
Database Performance Improvements Environment Document Requirement Planning A...Database Performance Improvements Environment Document Requirement Planning A...
Database Performance Improvements Environment Document Requirement Planning A...
 
Best Practices: Data Admin & Data Management
Best Practices: Data Admin & Data ManagementBest Practices: Data Admin & Data Management
Best Practices: Data Admin & Data Management
 
DBA Trainer RESUME
DBA Trainer RESUMEDBA Trainer RESUME
DBA Trainer RESUME
 
Sybase job interview_preparation_guide
Sybase job interview_preparation_guideSybase job interview_preparation_guide
Sybase job interview_preparation_guide
 
Common SQL Performance Issues
Common SQL Performance  IssuesCommon SQL Performance  Issues
Common SQL Performance Issues
 
Ibm web sphere_job_interview_preparation_guide
Ibm web sphere_job_interview_preparation_guideIbm web sphere_job_interview_preparation_guide
Ibm web sphere_job_interview_preparation_guide
 
INTRODUCTION TO DATABASE-SYSTEMS PRESENTATION.pptx
INTRODUCTION TO DATABASE-SYSTEMS PRESENTATION.pptxINTRODUCTION TO DATABASE-SYSTEMS PRESENTATION.pptx
INTRODUCTION TO DATABASE-SYSTEMS PRESENTATION.pptx
 
Data mining (Part I)
Data mining (Part I)Data mining (Part I)
Data mining (Part I)
 
Government and Education Webinar: Simplify Your Database Performance Manageme...
Government and Education Webinar: Simplify Your Database Performance Manageme...Government and Education Webinar: Simplify Your Database Performance Manageme...
Government and Education Webinar: Simplify Your Database Performance Manageme...
 
how-to-become-a-mysql-dba.pdf
how-to-become-a-mysql-dba.pdfhow-to-become-a-mysql-dba.pdf
how-to-become-a-mysql-dba.pdf
 
Oracle performance project public
Oracle performance project publicOracle performance project public
Oracle performance project public
 
Database Management Engineer vs Database Developer
Database Management Engineer vs Database DeveloperDatabase Management Engineer vs Database Developer
Database Management Engineer vs Database Developer
 
Database Administrator: Job Description, Salary and Future Scope
Database Administrator: Job Description, Salary and Future ScopeDatabase Administrator: Job Description, Salary and Future Scope
Database Administrator: Job Description, Salary and Future Scope
 
Term Paper VirtualizationDue Week 10 and worth 210 pointsThis.docx
Term Paper VirtualizationDue Week 10 and worth 210 pointsThis.docxTerm Paper VirtualizationDue Week 10 and worth 210 pointsThis.docx
Term Paper VirtualizationDue Week 10 and worth 210 pointsThis.docx
 
NITIN_DIXIT
NITIN_DIXITNITIN_DIXIT
NITIN_DIXIT
 

Mehr von Markus Winand

Volkskrankheit "Stiefmuetterliche Indizierung"
Volkskrankheit "Stiefmuetterliche Indizierung"Volkskrankheit "Stiefmuetterliche Indizierung"
Volkskrankheit "Stiefmuetterliche Indizierung"
Markus Winand
 
SQL Performance - Vienna System Architects Meetup 20131202
SQL Performance - Vienna System Architects Meetup 20131202SQL Performance - Vienna System Architects Meetup 20131202
SQL Performance - Vienna System Architects Meetup 20131202
Markus Winand
 

Mehr von Markus Winand (9)

Standard SQL features where PostgreSQL beats its competitors
Standard SQL features where PostgreSQL beats its competitorsStandard SQL features where PostgreSQL beats its competitors
Standard SQL features where PostgreSQL beats its competitors
 
Four* Major Database Releases of 2017 in Review
Four* Major Database Releases of 2017 in ReviewFour* Major Database Releases of 2017 in Review
Four* Major Database Releases of 2017 in Review
 
Row Pattern Matching in SQL:2016
Row Pattern Matching in SQL:2016Row Pattern Matching in SQL:2016
Row Pattern Matching in SQL:2016
 
SQL Transactions - What they are good for and how they work
SQL Transactions - What they are good for and how they workSQL Transactions - What they are good for and how they work
SQL Transactions - What they are good for and how they work
 
Backend to Frontend: When database optimization affects the full stack
Backend to Frontend: When database optimization affects the full stackBackend to Frontend: When database optimization affects the full stack
Backend to Frontend: When database optimization affects the full stack
 
Modern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial DatabasesModern SQL in Open Source and Commercial Databases
Modern SQL in Open Source and Commercial Databases
 
Volkskrankheit "Stiefmuetterliche Indizierung"
Volkskrankheit "Stiefmuetterliche Indizierung"Volkskrankheit "Stiefmuetterliche Indizierung"
Volkskrankheit "Stiefmuetterliche Indizierung"
 
SQL Performance - Vienna System Architects Meetup 20131202
SQL Performance - Vienna System Architects Meetup 20131202SQL Performance - Vienna System Architects Meetup 20131202
SQL Performance - Vienna System Architects Meetup 20131202
 
Pagination Done the Right Way
Pagination Done the Right WayPagination Done the Right Way
Pagination Done the Right Way
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Indexes: The neglected performance all rounder

  • 1. © 2013 by Markus Winand Indexes The Neglected Performance All-Rounder Not always that obvious, unfortunately! iStockPhoto wildpixel
  • 2. Takeaway #1: Pandemic Scale It affects you! (Symbolic image; not real data) http://upload.wikimedia.org/wikipedia/commons/c/c7/2009_world_subdivisions_flu_pandemic.png
  • 3. Takeaway #2: Caused by Success Copyright © 2013 Telerik, Inc. All rights reserved
  • 4. Takeaway #3: It’s Not Your Fault http://simpsonswiki.com/wiki/File:I_Didn%27t_Do_It!_Volume_III.png
  • 5. © 2013 by Markus Winand The Problem Improper Index Use
  • 6. The Problem: Improper Index Use “A very common cause of performance problems is lack of proper indexes or the use of queries that are not using existing indexes.” —Buda Consulting http://www.budaconsulting.com/Portals/52677/docs/top_5_tech_brief.pdf
  • 7. The Problem: Improper Index Use “A very common cause of performance problems is lack of proper indexes or the use of queries that are not using existing indexes.” —Buda Consulting http://www.budaconsulting.com/Portals/52677/docs/top_5_tech_brief.pdf
  • 8. Quantifying the Problem Percona White Paper: Reasons of performance problems that caused production downtime: 38% bad SQL 15% schema and indexing http://www.percona.com/files/white-papers/causes-of-downtime-in-mysql.pdf
  • 9. Quantifying the Problem Survey by sqlskills.com: Root causes of the last few SQL Server performance problems: 27% T-SQL 19% Poor indexing http://www.sqlskills.com/blogs/paul/survey-what-are-the-most-common-causes-of-performance-problems/
  • 10. Quantifying the Problem Craig S. Mullins (strategist and researcher): „As much as 75% of poor relational performance is caused by "bad" SQL and application code.” Noel Yuhanna (Forrester Research): „The key difficulties surrounding performance continue to be poorly written SQL statements, improper DBMS configuration and a lack of clear understanding of how to tune databases to solve performance issues.”
  • 11. Quantifying the Problem My observation: ~50% of SQL performance problems are caused by improper index use
  • 12. © 2013 by Markus Winand The Root Cause
  • 13. © 2013 by Markus Winand The Root Cause Admins are Indexing
  • 14. The Root Cause: DBAs are Indexing How did databases work before SQL?
  • 15. The Root Cause: DBAs are Indexing Index use was intrinsically tied to the queries.
  • 16. The Root Cause: DBAs are Indexing Example: dBase Developers had to... ...use indexes explicitly when searching: !"#$%&'"($#)$*+!#,&+-" $$$.%&'$/%&+&' ...take care of index maintenance: !"#$%&'"($#)$*+!#,&+-"0$%'(1 $$$$+22"&'
  • 17. The Root Cause: DBAs are Indexing SQL is an abstraction that only defines the logical view. The actual SQL implementation takes care of everything else.
  • 18. The Root Cause: DBAs are Indexing Transactions Constraints Views Tables Data manipulation Queries SQL (language) has: SQL Databases (software) have:
  • 19. The Root Cause: DBAs are Indexing Backup & recovery Storage management Bugs & patches Tuning parameters Transactions Constraints Views Tables Data manipulation Queries SQL (language) has: SQL Databases (software) have: High Availability
  • 20. The Root Cause: DBAs are Indexing Indexes Backup & recovery Storage management Bugs & patches Tuning parameters Transactions Constraints Views Tables Data manipulation Queries SQL (language) has: SQL Databases (software) have: High Availability
  • 21. The Root Cause: DBAs are Indexing Indexes Backup & recovery Storage management Bugs & patches Tuning parameters Transactions Constraints Views Tables Data manipulation Queries SQL Databases (software) have: Developers High Availability
  • 22. The Root Cause: DBAs are Indexing Indexes Backup & recovery Storage management Bugs & patches Tuning parameters Transactions Constraints Views Tables Data manipulation Queries Developers Administrators High Availability
  • 23. The Root Cause: DBAs are Indexing Indexing is considered a system tuning task that belongs to the administrators responsibilities.
  • 24. The Root Cause: DBAs are Indexing A misconception that causes new problems:
  • 25. The Root Cause: DBAs are Indexing A misconception that causes new problems: DBAs don’t know the queries Have to “investigate” to find the queries. It is time consuming and almost always incomplete. by G-10gian82 deviantart.com
  • 26. The Root Cause: DBAs are Indexing A misconception that causes new problems: DBAs don’t know the queries Have to “investigate” to find the queries. It is time consuming and almost always incomplete. DBAs can’t change the queries Can make the index match the query. Can’t make the query match the index!
  • 27. © 2013 by Markus Winand The Solution
  • 28. © 2013 by Markus Winand The Solution Indexing is a Development Task
  • 29. The Solution: It’s a Dev Task Indexes Backup & recovery Storage management Tuning parameters Transactions Constraints Views Tables Data manipulation Queries Developers Administrators High Availability Bugs & patches
  • 30. The Solution: It’s a Dev Task Indexes Backup & recovery Storage management Tuning parameters Transactions Constraints Views Tables Data manipulation Queries Developers Administrators Must match! High Availability Bugs & patches
  • 31. Another Problem: It’s not Taught Indexes are not part of the pure SQL (language) literature because indexes are not part of the SQL standard. 11 SQL books analyzed: only 1.0% of the pages are about indexes (70 out of 7330 pages). Examples: Oracle SQL by Example: 2.0% (19/960) Beginning DBs with PostgreSQL: 0.8% (5/664) Learning SQL: 3.3% (11/336 — highest rate in class)
  • 32. Another Problem: It’s not Taught Proper index usage is sometimes covered in database tuning books but is always buried between hundreds of pages of HW, OS and DB parameterization topics. 14 database administration books analyzed: 5.1% of the pages are about indexes (307 out of 6069 pages). Examples: Oracle Performance Survival Guide: 5.2% (38/730) High Performance MySQL: 8% (55/684) PostgreSQL 9 High Performance: 5.8% (27/468)
  • 33. Another Problem: It’s not Taught Consequence: Developers don’t know how to use indexes properly.
  • 34. Another Problem: It’s not Taught Consequence: Developers don’t know how to use indexes properly. Results of the 3-minute online quiz: http://use-the-index-luke.com/3-minute-test 5 questions: each about a specific index usage pattern. Non-representative!
  • 35. Q1: Good or Bad? (Function use) 345675$89:5;$#<*,%'($=9$#<*$>!"#$%&'()*+?@ A5B537$#"(#0$'+#",C)*D-& $$E4=F$#<* $/G545$,-%./012!"#$%&'()*+0$HIIIIH?$J$H1KLMH@ 3-Minute Quiz: Indexing Skills
  • 36. Q1: Good or Bad? (Function use) 345675$89:5;$#<*,%'($=9$#<*$>!"#$%&'()*+?@ A5B537$#"(#0$'+#",C)*D-& $$E4=F$#<* $/G545$,-%./012!"#$%&'()*+0$HIIIIH?$J$H1KLMH@ 3-Minute Quiz: Indexing Skills
  • 37. Q1: Good or Bad? (Function use) 345675$89:5;$#*,%'($=9$#*$!#$%'()*+?@ A5B537$#(#0$'+#,C)*D- $$E4=F$#* $/G545$,-%./012!#$%'()*+0$HIIIIH?$J$H1KLMH@ 3-Minute Quiz: Indexing Skills
  • 38. 3-Minute Quiz: Indexing Skills Q2: Good or Bad? (Indexed Top-N, no IOS) 345675$89:5;$#*,%'($=9$#*$+0$'+#,C)*?@ A5B537$%'0$+0$'+#,C)* $$E4=F$#* $/G545$+$J$NL $=4:54$OI$'+#,C)*$:5A3 $3454,67@
  • 39. 3-Minute Quiz: Indexing Skills Q2: Good or Bad? (Indexed Top-N, no IOS) 345675$89:5;$#*,%'($=9$#*$+0$'+#,C)*?@ A5B537$%'0$+0$'+#,C)* $$E4=F$#* $/G545$+$J$NL $=4:54$OI$'+#,C)*$:5A3 $3454,67@ Understandable controversy!
  • 40. 3-Minute Quiz: Indexing Skills Q3: Good or Bad? (Column order) CREATE INDEX tbl_idx ON tbl (a, b); SELECT id, a, b FROM tbl WHERE a = $1 AND b = $2; SELECT id, a, b FROM tbl WHERE b = $1;
  • 41. 3-Minute Quiz: Indexing Skills Q3: Good or Bad? (Column order) CREATE INDEX tbl_idx ON tbl (a, b); SELECT id, a, b FROM tbl WHERE a = $1 AND b = $2; SELECT id, a, b FROM tbl WHERE b = $1;
  • 42. 3-Minute Quiz: Indexing Skills Q4: Good or Bad? (Indexing LIKE) CREATE INDEX tbl_idx ON tbl (text varchar_pattern_ops); SELECT id, text FROM tbl WHERE text LIKE '%TERM%';
  • 43. 3-Minute Quiz: Indexing Skills Q4: Good or Bad? (Indexing LIKE) CREATE INDEX tbl_idx ON tbl (text varchar_pattern_ops); SELECT id, text FROM tbl WHERE text LIKE '%TERM%';
  • 44. 3-Minute Quiz: Indexing Skills Q5: Good or Bad? (equality vs. ranges) CREATE INDEX tbl_idx ON tbl (date_col, state); SELECT id, date_col, state FROM tbl WHERE date_col = CURRENT_DATE - INTERVAL '5' YEAR AND state = 'X';
  • 45. 3-Minute Quiz: Indexing Skills Q5: Good or Bad? (equality vs. ranges) CREATE INDEX tbl_idx ON tbl (date_col, state); SELECT id, date_col, state FROM tbl WHERE date_col = CURRENT_DATE - INTERVAL '5' YEAR AND state = 'X';
  • 46. Indexes: The Neglected All-Rounder Everybody knows indexing is important for performance, yet nobody takes the time to learn and apply is properly.
  • 47. Indexes: The Neglected All-Rounder Index details are hardly known. ! “Details” like column-order or equality vs. range conditions must be learned and understood. Only one index capability is used: finding data quickly ! Indexes have three capabilities (powers): finding data, clustering data, and sorting data. Indexing is done from single query perspective. ! Should be done from application perspective (considering all queries). It’s a design task!
  • 48. Indexes: The Neglected All-Rounder Are you just adding indexes or are you designing indexes?
  • 49. About Markus Winand Tuning developers for high SQL performance Training co (one-man show): winand.at Geeky blog: use-the-index-luke.com Author of: SQL Performance Explained