This document discusses indexing in MySQL databases to improve query performance. It begins by defining an index as a data structure that speeds up data retrieval from databases. It then covers various types of indexes like primary keys, unique indexes, and different indexing algorithms like B-Tree, hash, and full text. The document discusses when to create indexes, such as on columns frequently used in queries like WHERE clauses. It also covers multi-column indexes, partial indexes, and indexes to support sorting, joining tables, and avoiding full table scans. The concepts of cardinality and selectivity are introduced. The document concludes with a discussion of index overhead and using EXPLAIN to view query execution plans and index usage.
MySQL Indexing : Improving Query Performance Using Index (Covering Index)Hemant Kumar Singh
Query performance can be enhanced by a major factor if Database Indexed are used properly. The main aim of this slide was to explain the benefits of Covering Index, but ended up writing everything I knew.
Here is the summary of what I have covered in this slide:-
1. What affects Database performance
2. What is Database Index
3. Types Of Database Index
4. Column Index
5. Composite Index
6. Covering Index
7. Indexing Guidelines
It would be interesting to know these as well -
Best practices for Indexing in Database(RDBMS)
Best practices for Indexing in MySQL
Best practices for Indexing in PostgreSQL
Best practices for Database Modeling
Best practices for SQL Query Construction
Performance impact of Indexing on Query Performance
Performance impact of Indexing on INSERT Queries
Consolidate all these knowledge and you should be happy to see the overall performance gain in your SQL Query and hence overall application will run faster.
How to Analyze and Tune MySQL Queries for Better Performanceoysteing
Tutorial at Oracle Open World 2015:
Performance of SQL queries plays a big role in application performance. If some queries execute slowly, these queries or the database schema may need tuning. This tutorial covers query processing, optimization methods, and how the MySQL optimizer chooses a specific plan to execute SQL. See demonstrations on how to use tools such as EXPLAIN (including the JSON-based variant), optimizer trace, and performance schema to analyze query plans. See how the Visual Explain functionality in MySQL Workbench helps you to visualize these plans. Based on the analysis, the tutorial covers how to take the next steps for performance tuning. It might mean forcing a particular index, changing the schema, or modifying configuration parameters.
Adrian Hardy's slides from PHPNW08
Once you have your query returning the correct results, speed becomes an important factor. Speed can either be an issue from the outset, or can creep in as your dataset grows. Understanding the EXPLAIN command is essential to helping you solve and even anticipate slow queries.
Associated video: http://blip.tv/file/1791781
Advanced MySQL Query Tuning - talk at Percona Live and MySQL Meetup tour.
Tuning Queries and Schema/Indexes can significantly increase performance of your application and decrease response times.
This year I will cover new MySQL 5.6 and 5.7 algorithms that has been designed to improve query performance and simply tuning.
Topics:
1. Group by and order by optimizations
2. MySQL temporary tables and filesort
3. Using covered indexes to optimize your queries
4. Loose and tight index scan in MySQL
5. Using summary tables to optimize your reporting queries
6. New MySQL 5.6 and 5.7 Optimizer features and improvements
MySQL Indexing : Improving Query Performance Using Index (Covering Index)Hemant Kumar Singh
Query performance can be enhanced by a major factor if Database Indexed are used properly. The main aim of this slide was to explain the benefits of Covering Index, but ended up writing everything I knew.
Here is the summary of what I have covered in this slide:-
1. What affects Database performance
2. What is Database Index
3. Types Of Database Index
4. Column Index
5. Composite Index
6. Covering Index
7. Indexing Guidelines
It would be interesting to know these as well -
Best practices for Indexing in Database(RDBMS)
Best practices for Indexing in MySQL
Best practices for Indexing in PostgreSQL
Best practices for Database Modeling
Best practices for SQL Query Construction
Performance impact of Indexing on Query Performance
Performance impact of Indexing on INSERT Queries
Consolidate all these knowledge and you should be happy to see the overall performance gain in your SQL Query and hence overall application will run faster.
How to Analyze and Tune MySQL Queries for Better Performanceoysteing
Tutorial at Oracle Open World 2015:
Performance of SQL queries plays a big role in application performance. If some queries execute slowly, these queries or the database schema may need tuning. This tutorial covers query processing, optimization methods, and how the MySQL optimizer chooses a specific plan to execute SQL. See demonstrations on how to use tools such as EXPLAIN (including the JSON-based variant), optimizer trace, and performance schema to analyze query plans. See how the Visual Explain functionality in MySQL Workbench helps you to visualize these plans. Based on the analysis, the tutorial covers how to take the next steps for performance tuning. It might mean forcing a particular index, changing the schema, or modifying configuration parameters.
Adrian Hardy's slides from PHPNW08
Once you have your query returning the correct results, speed becomes an important factor. Speed can either be an issue from the outset, or can creep in as your dataset grows. Understanding the EXPLAIN command is essential to helping you solve and even anticipate slow queries.
Associated video: http://blip.tv/file/1791781
Advanced MySQL Query Tuning - talk at Percona Live and MySQL Meetup tour.
Tuning Queries and Schema/Indexes can significantly increase performance of your application and decrease response times.
This year I will cover new MySQL 5.6 and 5.7 algorithms that has been designed to improve query performance and simply tuning.
Topics:
1. Group by and order by optimizations
2. MySQL temporary tables and filesort
3. Using covered indexes to optimize your queries
4. Loose and tight index scan in MySQL
5. Using summary tables to optimize your reporting queries
6. New MySQL 5.6 and 5.7 Optimizer features and improvements
The JSON data type and functions that support it comprise one of the most interesting features introduced in MySQL 5.7 for application developers. But no feature is a Golden Hammer. We need to apply a little expertise to get the best of it, and avoid misusing it. I’ll show practical examples that work well with JSON, and other scenarios where conventional columns would perform better. Questions addressed in this presentation: How much space does JSON data use, compared to conventional data? What is the performance of querying JSON vs. conventional data? How do I create indexes for JSON data? What kind of data is best to store in JSON? How do I get the best of both worlds?
Data Definition Language (DDL), Data Definition Language (DDL), Data Manipulation Language (DML) , Transaction Control Language (TCL) , Data Control Language (DCL) - , SQL Constraints
A presentation about MySQL for beginners. It includes the following topics:
- Introduction
- Installation
- Executing SQL statements
- SQL Language Syntax
- The most important SQL commands
- MySQL Data Types
- Operators
- Basic Syntax
- SQL Joins
- Some Exercise
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Jaime Crespo
Tutorial delivered at Percona MySQL Conference Live London 2013.
It doesn't matter what new SSD technologies appear, or what are the latest breakthroughs in flushing algorithms: the number one cause for MySQL applications being slow is poor execution plan of SQL queries. While the latest GA version provided a huge amount of transparent optimizations -specially for JOINS and subqueries- it is still the developer's responsibility to take advantage of all new MySQL 5.6 features.
In this tutorial we will propose the attendants a sample PHP application with bad response time. Through practical examples, we will suggest step-by-step strategies to improve its performance, including:
* Checking MySQL & InnoDB configuration
* Internal (performance_schema) and external tools for profiling (pt-query-digest)
* New EXPLAIN tools
* Simple and multiple column indexing
* Covering index technique
* Index condition pushdown
* Batch key access
* Subquery optimization
This presentation is on SQL constraints. This presentation was used by me in my YouTube vlog on SQL constraints. Vlog link: https://youtu.be/E94YFmATqb4
This presentation was presented at Percona Live UK.
Although a DBMS hides the internal mechanics of indexing. But to be able to create efficient indexes, you need to know how they work. This talk will help you understand the mechanics of the data structure used to store indexes and as to how it applies to InnoDB. At the end of the talk you will be able to learn how to use cost-analysis to pick and choose correct index definitions and will learn how to create indexes that will work efficiently with InnoDB.
MySQL users commonly ask: Here's my table, what indexes do I need? Why aren't my indexes helping me? Don't indexes cause overhead? This talk gives you some practical answers, with a step by step method for finding the queries you need to optimize, and choosing the best indexes for them.
The JSON data type and functions that support it comprise one of the most interesting features introduced in MySQL 5.7 for application developers. But no feature is a Golden Hammer. We need to apply a little expertise to get the best of it, and avoid misusing it. I’ll show practical examples that work well with JSON, and other scenarios where conventional columns would perform better. Questions addressed in this presentation: How much space does JSON data use, compared to conventional data? What is the performance of querying JSON vs. conventional data? How do I create indexes for JSON data? What kind of data is best to store in JSON? How do I get the best of both worlds?
Data Definition Language (DDL), Data Definition Language (DDL), Data Manipulation Language (DML) , Transaction Control Language (TCL) , Data Control Language (DCL) - , SQL Constraints
A presentation about MySQL for beginners. It includes the following topics:
- Introduction
- Installation
- Executing SQL statements
- SQL Language Syntax
- The most important SQL commands
- MySQL Data Types
- Operators
- Basic Syntax
- SQL Joins
- Some Exercise
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Jaime Crespo
Tutorial delivered at Percona MySQL Conference Live London 2013.
It doesn't matter what new SSD technologies appear, or what are the latest breakthroughs in flushing algorithms: the number one cause for MySQL applications being slow is poor execution plan of SQL queries. While the latest GA version provided a huge amount of transparent optimizations -specially for JOINS and subqueries- it is still the developer's responsibility to take advantage of all new MySQL 5.6 features.
In this tutorial we will propose the attendants a sample PHP application with bad response time. Through practical examples, we will suggest step-by-step strategies to improve its performance, including:
* Checking MySQL & InnoDB configuration
* Internal (performance_schema) and external tools for profiling (pt-query-digest)
* New EXPLAIN tools
* Simple and multiple column indexing
* Covering index technique
* Index condition pushdown
* Batch key access
* Subquery optimization
This presentation is on SQL constraints. This presentation was used by me in my YouTube vlog on SQL constraints. Vlog link: https://youtu.be/E94YFmATqb4
This presentation was presented at Percona Live UK.
Although a DBMS hides the internal mechanics of indexing. But to be able to create efficient indexes, you need to know how they work. This talk will help you understand the mechanics of the data structure used to store indexes and as to how it applies to InnoDB. At the end of the talk you will be able to learn how to use cost-analysis to pick and choose correct index definitions and will learn how to create indexes that will work efficiently with InnoDB.
MySQL users commonly ask: Here's my table, what indexes do I need? Why aren't my indexes helping me? Don't indexes cause overhead? This talk gives you some practical answers, with a step by step method for finding the queries you need to optimize, and choosing the best indexes for them.
The History and Future of the MySQL ecosystemRonald Bradford
The history and future of the MySQL Ecosystem. This talk sub-titled “Spaghetti and MySQLBalls (with a side of greens)” detailed the beginnings of MySQL, the MySQL acquisition history, described the state of current MySQL versions/variants/forks, storage engines, related vendors, NoSQL and much more.
A video of the presentations is available on YouTube at http://www.youtube.com/watch?v=9mKwkbaB5X8&feature=youtu.be
Lessons Learned Managing Large AWS EnvironmentsRonald Bradford
How to you optimize management of 500+ AWS servers? In this presentation I share my experiences using Amazon Web Servers covering techniques for webscale. Learn how to optimized your cost, handle security, automate and be prepared for handling failure.
MySQL Performance - SydPHP October 2011Graham Weldon
A talk on optimisations around MySQL on the server side, and through the use of PHP extensions to reduce disk writes to provide for more IO access for MySQL. This was presented at SydPHP in October 2011
Introduction to Databases - query optimizations for MySQLMárton Kodok
This was module 6 part of a course of Web technologies. We cover relational databases, advantages/disadvantages. How to leverage MySQL index usage, and query optimizations. In the final part also mention NoSQL databases.
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...Mydbops
Performance improvement, debugging, and monitoring are essential parts of the DBE(Database Engineering Team) role. The presentation present intriguing strategies, techniques, and tools that can be used to address or circumvent the majority of performance-related problems in this MongoDB Performance.
Whether you're a MongoDB professional or totally new to document databases, our MongoDB performance success factors & evaluation framework has something for you,
Curious about MongoDB performance?
Mydbops CTO, Manosh Malai illustrates the secret sauce for MongoDB performance best practices & analysis tool.
15 Ways to Kill Your Mysql Application Performanceguest9912e5
Jay is the North American Community Relations Manager at MySQL. Author of Pro MySQL, Jay has also written articles for Linux Magazine and regularly assists software developers in identifying how to make the most effective use of MySQL. He has given sessions on performance tuning at the MySQL Users Conference, RedHat Summit, NY PHP Conference, OSCON and Ohio LinuxFest, among others.In his abundant free time, when not being pestered by his two needy cats and two noisy dogs, he daydreams in PHP code and ponders the ramifications of __clone().
This presentation is an INTRODUCTION to intermediate MySQL query optimization for the Audience of PHP World 2017. It covers some of the more intricate features in a cursory overview.
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteGoogle
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-pilot-review/
AI Pilot Review: Key Features
✅Deploy AI expert bots in Any Niche With Just A Click
✅With one keyword, generate complete funnels, websites, landing pages, and more.
✅More than 85 AI features are included in the AI pilot.
✅No setup or configuration; use your voice (like Siri) to do whatever you want.
✅You Can Use AI Pilot To Create your version of AI Pilot And Charge People For It…
✅ZERO Manual Work With AI Pilot. Never write, Design, Or Code Again.
✅ZERO Limits On Features Or Usages
✅Use Our AI-powered Traffic To Get Hundreds Of Customers
✅No Complicated Setup: Get Up And Running In 2 Minutes
✅99.99% Up-Time Guaranteed
✅30 Days Money-Back Guarantee
✅ZERO Upfront Cost
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
Keep tabs on your field staff effortlessly with Informap Technology Centre LLC. Real-time tracking, task assignment, and smart features for efficient management. Request a live demo today!
For more details, visit us : https://informapuae.com/field-staff-tracking/
Navigating the Metaverse: A Journey into Virtual Evolution"Donna Lenk
Join us for an exploration of the Metaverse's evolution, where innovation meets imagination. Discover new dimensions of virtual events, engage with thought-provoking discussions, and witness the transformative power of digital realms."
In software engineering, the right architecture is essential for robust, scalable platforms. Wix has undergone a pivotal shift from event sourcing to a CRUD-based model for its microservices. This talk will chart the course of this pivotal journey.
Event sourcing, which records state changes as immutable events, provided robust auditing and "time travel" debugging for Wix Stores' microservices. Despite its benefits, the complexity it introduced in state management slowed development. Wix responded by adopting a simpler, unified CRUD model. This talk will explore the challenges of event sourcing and the advantages of Wix's new "CRUD on steroids" approach, which streamlines API integration and domain event management while preserving data integrity and system resilience.
Participants will gain valuable insights into Wix's strategies for ensuring atomicity in database updates and event production, as well as caching, materialization, and performance optimization techniques within a distributed system.
Join us to discover how Wix has mastered the art of balancing simplicity and extensibility, and learn how the re-adoption of the modest CRUD has turbocharged their development velocity, resilience, and scalability in a high-growth environment.
Listen to the keynote address and hear about the latest developments from Rachana Ananthakrishnan and Ian Foster who review the updates to the Globus Platform and Service, and the relevance of Globus to the scientific community as an automation platform to accelerate scientific discovery.
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
First Steps with Globus Compute Multi-User EndpointsGlobus
In this presentation we will share our experiences around getting started with the Globus Compute multi-user endpoint. Working with the Pharmacology group at the University of Auckland, we have previously written an application using Globus Compute that can offload computationally expensive steps in the researcher's workflows, which they wish to manage from their familiar Windows environments, onto the NeSI (New Zealand eScience Infrastructure) cluster. Some of the challenges we have encountered were that each researcher had to set up and manage their own single-user globus compute endpoint and that the workloads had varying resource requirements (CPUs, memory and wall time) between different runs. We hope that the multi-user endpoint will help to address these challenges and share an update on our progress here.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
In this slide, we show the simulation example and the way to compile this solver.
In this solver, the Helmholtz equation can be solved by helmholtzFoam. Also, the Helmholtz equation with uniformly dispersed bubbles can be simulated by helmholtzBubbleFoam.
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
Games are powerful teaching tools, fostering hands-on engagement and fun. But they require careful consideration to succeed. Join me to explore factors in running and selecting games, ensuring they serve as effective teaching tools. Learn to maintain focus on learning objectives while playing, and how to measure the ROI of gaming in education. Discover strategies for pitching gaming to leadership. This session offers insights, tips, and examples for coaches, team leads, and enterprise leaders seeking to teach from simple to complex concepts.
Accelerate Enterprise Software Engineering with PlatformlessWSO2
Key takeaways:
Challenges of building platforms and the benefits of platformless.
Key principles of platformless, including API-first, cloud-native middleware, platform engineering, and developer experience.
How Choreo enables the platformless experience.
How key concepts like application architecture, domain-driven design, zero trust, and cell-based architecture are inherently a part of Choreo.
Demo of an end-to-end app built and deployed on Choreo.
2. Jehad Keriaki 2014
What is an Index
Data structure to improve the speed of data
retrieval from DBs.
MySQL: Indexing for Better Performance2
3. Jehad Keriaki 2014
Why Would We Use Indexes
Speed, Speed, and Speed
Constraints (Uniqueness)
IO Optimization
MAX, MIN
Sorting, Grouping
MySQL: Indexing for Better Performance3
4. Jehad Keriaki 2014
Index Types
Primary Key (PK), Unique, Key
Primary Key vs Unique
Unique can be NULL
InnoDB is clustered based on PK
MySQL: Indexing for Better Performance4
5. Jehad Keriaki 2014
Types (Algorithm)
B-Tree, R-Tree, Hash, Full text
R-Tree: Geo-spatial
Hash: Memory only, fast for equality, whole key is used,
no range
Full-text:
For MyISAM, and as of 5.6 for InnoDB too.
SELECT * WHERE MATCH(description) AGAINST ('toshiba')
boolean , with query expansion, stop words, short words,
50% rule
A better choice would be to use a search server like Sphinx
MySQL: Indexing for Better Performance5
6. Jehad Keriaki 2014
Types (Algorithm) [cont'd]
B-Tree:
For comparison operations (<>=..etc)
Range (Between)
Like, which is a special case of range when used with %
It is the DEFAULT in MySQL
In B-Tree, data are stored in the leaf nodes
MySQL: Indexing for Better Performance6
7. Jehad Keriaki 2014
Types (Structure)
One column
Multi-Column [composite]
Partial [prefix]
Any one of them can be "Covering Index", except
'partial'
MySQL: Indexing for Better Performance7
8. Jehad Keriaki 2014
What Indexes to Create?
PK is a must
Best to be unsigned [smallest int] auto increment
PK and InnoDB (Clustered)
InnoDB tables are clustered based on PKs
Each secondary index has the PK in it. example:
INDEX(name) is in fact (name, id)
AVOID long PKs. Why?
AVOID md5(), uuid(), etc.
MySQL: Indexing for Better Performance8
9. Jehad Keriaki 2014
MyISAM and InnoDB
In MyISAM:
Index entry tells the physical offset of the row in the
data file
In InnoDB:
PK index has the data. Secondary indexes store PK as
a pointer. Key on field F is (F, PK) - good for sorting
and covering index
MySQL: Indexing for Better Performance9
10. Jehad Keriaki 2014
Cardinality and Selectivity
Cardinality: Number of distinct values
Selectivity: Cardinality / total number of rows
What values are better
Optimize Stats Update
MySQL: Indexing for Better Performance10
11. Jehad Keriaki 2014
One Column Index
This index is on one column only
Query example:
SELECT * FROM employee WHERE first_name LIKE 'stephane';
Index solution:
ALTER TABLE employee ADD INDEX (first_name);
Notes:
Index the first n char of the char/varchar/text fields
Do not use a function. i.e.
WHERE md5(field)='1bc29b36f623ba82aaf6724fd3b16718'
MySQL: Indexing for Better Performance11
12. Jehad Keriaki 2014
Multi Column Index
What is it:
Index that involves more than one column.
Higher cardinality field goes first, with exceptions.
What 'left most' term is. [INDEX (A, B, C)]
Query example:
SELECT * FROM employee
WHERE department = 5 AND last_name LIKE 'tran';
Index solution:
ALTER TABLE employee ADD INDEX (last_name, department);
{WHY NOT (department, last_name)??}
MySQL: Indexing for Better Performance12
13. Jehad Keriaki 2014
Multi Column Index [Cont’d]
Query example:
SELECT * FROM employee WHERE department = 5 and
hiring_date>='2014-01-01';
Index solution:
ALTER TABLE employee ADD INDEX (department, hiring_date);
Notes
Should it be (hiring_date, department)? Is this an
exception?
Order of columns IS important
WILL NOT USE THE INDEX:
SELECT * FROM employee WHERE hiring_date>='2014-01-01';
MySQL: Indexing for Better Performance13
14. Jehad Keriaki 2014
Partial Index
What is it: Index on the first n char of a field.
Query example:
email: varchar(255);
SELECT * FROM users WHERE email like 'richardmelo@yahoo.com';
Index solution
ALTER TABLE users ADD INDEX (email(12));
vs
ALTER TABLE users ADD INDEX (email);
Notes:
Save space, efficient writing, same performance
SELECT COUNT(DISTINCT(LEFT(field, 20))) FROM table
85% threshold? 90% maybe?
MySQL: Indexing for Better Performance14
15. Jehad Keriaki 2014
Joins and Indexes
Linking two or more tables to get related rows
Query example:
SELECT employee.first_name, employee.last_name,
FROM department
INNER JOIN employee ON departmant.id = employee.department
WHERE department.location='MTL';
Index solution:
ALTER TABLE department ADD INDEX (location);
ALTER TABLE employee ADD INDEX (department);
Notes: The join could be on a non-indexed field on
department, but an index has to exist on "employee's field"
MySQL: Indexing for Better Performance15
16. Jehad Keriaki 2014
Multiple Indexes OR Multi-Col Index
What is it:
ALTER TABLE ADD INDEX(field1), ADD INDEX(field2)
ALTER TABLE ADD INDEX(field1, field2)
Query example:
WHERE field1=1 OR field2=2 [multiple indexes]
WHERE field1=1 AND field2=2 [multi-col index]
MySQL: Indexing for Better Performance16
17. Jehad Keriaki 2014
Covering Index
When the index has the required data, no need to
read data from table’s data!
Example:
employee(id, first_name, last_name, email, phone, hiring_date)
SELECT email FROM employee WHERE phone='123456789';
ALTER TABLE employee ADD INDEX(phone, email);
min(), max() functions use the index only.
MySQL: Indexing for Better Performance17
18. Jehad Keriaki 2014
Covering Index - Note
only in InnoDB:
myindex(col1,col2)
SELECT col1 FROM table1 WHERE col2 = 200 <<-- will use index
SELECT * FROM table1 where col2 = 200 <<-- will NOT use index.
MySQL: Indexing for Better Performance18
19. Jehad Keriaki 2014
ICP (Index Condition Pushdown) [5.6]
Lets the optimizer check in the index instead of checking in the
table's data.
employee(id, first_name, last_name, department, phone, email, address)
INDEX(department, email)
SELECT * FROM employee
WHERE department=5
AND email LIKE '%@beta.example%'
[and address LIKE '%montreal%'];
Instead of stopping at department and then use where to check for
email in the table's data, it will actually check in the index to see if
the 2nd condition is satisfied, and then if yes, it will fetch the data
from the table
MySQL: Indexing for Better Performance19
20. Jehad Keriaki 2014
Using Index for Sorting
ORDER BY x (index on x)
WHERE x ORDER BY y (index on x, y)
WHERE x ORDER BY x DESC, y DESC (index on x, y)
WHERE x ORDER BY x ASC, y DESC (Can't use index)
MySQL: Indexing for Better Performance20
21. Jehad Keriaki 2014
Exceptions
E.g. Date index with other less cardinal field.
Status or Gender special cases
MySQL: Indexing for Better Performance21
22. Jehad Keriaki 2014
Overhead of indexing
IO: Each DML operation will modify the indexes
Disk space
More indexes => Higher possibility of deadlock
MySQL: Indexing for Better Performance22
23. Jehad Keriaki 2014
ABOUT EXPLAIN
It lets us know the plan of query execution
What index would be used, if any
Rows to be scanned
MySQL: Indexing for Better Performance23