THINGS EVERY DEVELOPER
ABSOLUTELY, POSITIVELY
NEEDS TO KNOW ABOUT
database indexing
Kai SassnowskiHTTPS://KAI-SASSNOWSKI.COM
HTTPS://GITHUB.COM/KSASSNOWSKI
@WARSH33P
HTTPS://WYCOMCO.IO
WHY indexing?
WHY indexing?
▸ Improve query performance
▸ ...
▸ That's about it
Slow QueriesARE ONE THE MOST COMMON CAUSES OF
POOR PERFORMANCE
DEVELOPERS
DON'T KNOW (ENOUGH)
ABOUT indexing
WHAT WE WILL
LEARN
WHAT WE WILL LEARN
1. What's an index?
2. Understanding the execution plan
3. Common pitfalls
WHAT'S AN
index?
Laracon EU 2018: Things every developer absolutely, positively needs to know about database indexing
Laracon EU 2018: Things every developer absolutely, positively needs to know about database indexing
An index is an ordered representation of
the indexed data
B-TREE
Laracon EU 2018: Things every developer absolutely, positively needs to know about database indexing
Laracon EU 2018: Things every developer absolutely, positively needs to know about database indexing
Laracon EU 2018: Things every developer absolutely, positively needs to know about database indexing
EMPLOYEE_ID NAME
23 Kai
700 Marcel
12 Oliver
1 Taylor
18 Franz
Laracon EU 2018: Things every developer absolutely, positively needs to know about database indexing
Laracon EU 2018: Things every developer absolutely, positively needs to know about database indexing
Laracon EU 2018: Things every developer absolutely, positively needs to know about database indexing
▸ Searching for a value is fast
▸ Logarithmic scalability
NO SILVER BULLETS
INDEXING MAKES
READING faster
BUT WRITING slower
UNDERSTANDING THE
execution plan(MYSQL VERSION)
GETTING AN EXECUTION PLAN
EXPLAIN
SELECT *
FROM users
WHERE id = 1;
mysql> explain select * from users where id = 1 G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: users
partitions: NULL
type: const
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: const
rows: 1
filtered: 100.00
Extra: NULL
ACCESS TYPES
CONST / EQ_REF
▸ Performs a B-Tree traversal to find a single value
▸ Basically binary search
▸ Can only get used if uniqueness is guaranteed
▸ Super fast
REF / RANGE
▸ Also known as an index range scan
▸ Performs a B-Tree traversal to find the starting point
▸ Scans values from that point on
▸ Stops if it finds a value that does not meed the criteria
INDEX
▸ Also known as a Full Index Scan
▸ Starts at the first leaf node
▸ Traverses through the entire index
ALL
▸ Also known as a Full Table Scan
▸ Does not use an index at all
▸ Loads every column of every row from the table
▸ Scans through all of them and emits or discards accordingly
ACCESS TYPES
▸ const / eq_ref
▸ ref /range
▸ index
▸ ALL
COMMON Pitfalls
Functions
SELECT SUM(total)
FROM orders
WHERE YEAR(created_at) = '2012';
SELECT SUM(total)
FROM orders
WHERE YEAR(...) = '2012';
CREATED AT TOTAL USER ID
2008-02-19 00:00:00 1315 4685
2008-02-19 00:00:00 1755 6603
2008-03-06 00:00:00 18313 9266
2008-03-06 00:00:00 18395 5688
2018-02-16 00:00:00 2689 8656
2018-02-16 00:00:00 2692 8657
CREATED AT TOTAL USER ID
2008-02-19 00:00:00 1315 4685
2008-02-19 00:00:00 1755 6603
2008-03-06 00:00:00 18313 9266
2008-03-06 00:00:00 18395 5688
2018-02-16 00:00:00 2689 8656
2018-02-16 00:00:00 2692 8657
CREATED AT TOTAL USER ID
2008-02-19 00:00:00 1315 4685
2008-02-19 00:00:00 1755 6603
2008-03-06 00:00:00 18313 9266
2008-03-06 00:00:00 18395 5688
2018-02-16 00:00:00 2689 8656
2018-02-16 00:00:00 2692 8657
CREATED AT TOTAL USER ID
2008-02-19 00:00:00 1315 4685
2008-02-19 00:00:00 1755 6603
2008-03-06 00:00:00 18313 9266
2008-03-06 00:00:00 18395 5688
2018-02-16 00:00:00 2689 8656
2018-02-16 00:00:00 2692 8657
THE
column order
MATTERS!
Inequality
OPERATORS
THANKS

More Related Content

DOCX
POB SBA on Production
PPTX
Sole trader.pptx
DOCX
Social Studies School Based Assignments (SBA)
DOCX
Principles of business school based assessment
DOCX
It sba 2015
PPTX
My SQL Skills Killed the Server
PPTX
Sql killedserver
PPTX
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
POB SBA on Production
Sole trader.pptx
Social Studies School Based Assignments (SBA)
Principles of business school based assessment
It sba 2015
My SQL Skills Killed the Server
Sql killedserver
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...

Similar to Laracon EU 2018: Things every developer absolutely, positively needs to know about database indexing (20)

PPT
Myth busters - performance tuning 101 2007
PPTX
Call Report management
ODP
MySQL Monitoring Mechanisms
ODP
MySQL Monitoring Mechanisms
PDF
12 things Oracle DBAs must know about SQL
PPT
15 Ways to Kill Your Mysql Application Performance
PDF
Scaling MySQL Strategies for Developers
ODP
Performance tuning
PDF
Noinject
PDF
MySQL Performance Optimization
PDF
Flexible Indexing with Postgres
 
PDF
Kill mysql-performance
PPTX
MySQL performance tuning
PPTX
Sql and PL/SQL Best Practices I
PPTX
MySQL Optimizer: What's New in 8.0
PPTX
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
PPTX
53 SQL Questions-Answers12121212121212.pptx
PPT
Sydney Oracle Meetup - indexes
PPTX
Oracle_Audit_APEX IOUG Collaborate 14
PDF
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
Myth busters - performance tuning 101 2007
Call Report management
MySQL Monitoring Mechanisms
MySQL Monitoring Mechanisms
12 things Oracle DBAs must know about SQL
15 Ways to Kill Your Mysql Application Performance
Scaling MySQL Strategies for Developers
Performance tuning
Noinject
MySQL Performance Optimization
Flexible Indexing with Postgres
 
Kill mysql-performance
MySQL performance tuning
Sql and PL/SQL Best Practices I
MySQL Optimizer: What's New in 8.0
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
53 SQL Questions-Answers12121212121212.pptx
Sydney Oracle Meetup - indexes
Oracle_Audit_APEX IOUG Collaborate 14
SQL Performance Solutions: Refactor Mercilessly, Index Wisely
Ad

Recently uploaded (20)

PPTX
Introduction to Windows Operating System
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PPTX
"Secure File Sharing Solutions on AWS".pptx
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PPTX
Full-Stack Developer Courses That Actually Land You Jobs
PDF
Visual explanation of Dijkstra's Algorithm using Python
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
novaPDF Pro 11.9.482 Crack + License Key [Latest 2025]
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PPTX
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
PDF
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
PDF
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
PDF
MCP Security Tutorial - Beginner to Advanced
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
PDF
Topaz Photo AI Crack New Download (Latest 2025)
Introduction to Windows Operating System
Wondershare Recoverit Full Crack New Version (Latest 2025)
Autodesk AutoCAD Crack Free Download 2025
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
"Secure File Sharing Solutions on AWS".pptx
Weekly report ppt - harsh dattuprasad patel.pptx
DNT Brochure 2025 – ISV Solutions @ D365
Full-Stack Developer Courses That Actually Land You Jobs
Visual explanation of Dijkstra's Algorithm using Python
CCleaner 6.39.11548 Crack 2025 License Key
novaPDF Pro 11.9.482 Crack + License Key [Latest 2025]
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
Cybersecurity-and-Fraud-Protecting-Your-Digital-Life.pptx
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
MCP Security Tutorial - Beginner to Advanced
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
Topaz Photo AI Crack New Download (Latest 2025)
Ad

Laracon EU 2018: Things every developer absolutely, positively needs to know about database indexing