SlideShare a Scribd company logo
1 of 19
Download to read offline
MySQL INDEXES
Why we need INDEXes
 Searching for single record in a
large table. The usual method
of searching the record in the
table is to start from the
beginning record by record, till
we get the record. But it is not
feasible when table is large.
1
What is an INDEX
 Index is usually created
to enhance the
performance of retrieval
of records in huge tables.
 Primary key itself acts as
an index in a table.
2
 An index in a database is very similar to an index in the
back of a book.
INDEX advantages and disadvantages
Advantages
Speed up
 SELECT queries
 WHERE clauses
Disadvantages
 Slows down transactions like INSERT/DELETE/UPDATE.
3
CREATE INDEX
 Creating an index depends on the table access frequency, the
columns(combination of columns) which are used for fetching
the records etc. Indexes involving two or more columns
should be ordered from most frequently accessed columns to
less frequently accessed columns.
 The basic syntax of a CREATE INDEX is as follows
 CREATE INDEX index_name ON table_name;
4
DROP INDEX
 Drop the indexes, if they are no more
required in the database. Unwanted
and unused indexes always lead to bad
performance of a query. An index can
be dropped using DROP command.
The basic syntax is as follows
 DROP INDEX index_name;
5
RENAME INDEX
 Index can be renamed too
 ALTER INDEX index_name RENAME TO new_index_name;
6
INDEX types
 Single-Column index is created based on only one table column. The basic
syntax is as follows
 CREATE INDEX index_name ON table_name (column_name);
 Unique indexes are used not only for performance, but also for data
integrity. A unique index does not allow any duplicate values to be inserted
into the table. The basic syntax is as follows.
 CREATE UNIQUE INDEX index_name ON table_name (column_name);
7
INDEX types
 Composite (concatenated) index is an index on two or more columns of
a table. Its basic syntax is as follows
 CREATE INDEX index_name ON table_name (column1, column2);
 Implicit indexes are the one which are indexes by default. That means
database considers them as index when the table is created. Primary key
and unique key columns are implicit indexes.
7
When should INDEXES be avoided?
The following guidelines indicate when the use of an index should be
reconsidered
Indexes should not be used on small tables.
Tables that have frequent, large batch updates or insert/delete
operations.
Indexes should not be used on columns that contain a high number of
NULL values.
Columns that are frequently manipulated should not be indexed.
8
Creating a simple INDEX
ID First Name Last Name Class
1 James Bond 6A
2 Chris Smith 6A
3 Jane Eyre 6B
4 Dave Smith 6B
In this example, we will be working with a table of students
at an extraordinarily large school. This is quite a large table
as we have 100,000 studentsin our school. The first few
rows of the table look like this
9
Queries used
The ` was created using the following query
10
Requirements
Our web application performs 3 queries against this table
 Look up a student by ID
 Search for students by last name
 List all students in a class
Each of these queries searches for data from a single
column, so we should ensure that each of these columns
has its own index.
11
The First Query
The first query is a special case because it is looking up a row
using its PRIMARY KEY. Because we already know exactly
which row we want, no further optimization is required.
SELECT * FROM students WHERE id = 1;
12
ID First Name Last Name Class
1 James Bond 6A
The Second Query
The second query will be searching a column which does not
currently have an index and this is exactly the type of query that
will search the whole table unless we do something about it
SELECT * FROM students WHERE last_name = `Smith`;
Lets go right ahead and create an index on that column
CREATE INDEX by_last_name ON students(`last_name`);
Exactly the same principle can be applied to the class column
CREATE INDEX by_class ON students (`class`);
13
The Third Query
The third query will be searching a column which has an index
SELECT * FROM students
WHERE class = `6A` AND last_name = `Smith`;
14
ID First Name Last Name Class
2 Chris Smith 6A
Choosing Columns to Index15
Rather than looking at your queries, it is quite possible to index your
database simply by looking through your tables and indexing columns
that will obviously be searched on. Here are some examples of
columns that should almost always be indexed
Columns that join with other tables (they usually end _id).
Usernames and/or email addresses, these are looked up every time a
user logs in.
Any field used in a URL.
Remember that id should already be a primary key.
Summary16
If you find your SELECT queries are taking a long time to run, you are
most likely missing an index on your table. Look at which columns are
searching on, and create an index on each one using the following
syntax
CREATE INDEX index_name ON table_name(column_name);
It is always wise to start by indexing columns that join with other
tables (they usually end _id). After that, look for columns you know
you will commonly search on. Focus on your largest tables.
Thank You!

More Related Content

What's hot (20)

View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
SQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaSQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
 
MYSQL-Database
MYSQL-DatabaseMYSQL-Database
MYSQL-Database
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
 
Explain that explain
Explain that explainExplain that explain
Explain that explain
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
 
SQL
SQLSQL
SQL
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
Subqueries
SubqueriesSubqueries
Subqueries
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
MySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsMySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 Tips
 
MySQL JOINS
MySQL JOINSMySQL JOINS
MySQL JOINS
 
MS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesMS Sql Server: Joining Databases
MS Sql Server: Joining Databases
 

Similar to MySQL INDEXES

Sql server ___________session_17(indexes)
Sql server  ___________session_17(indexes)Sql server  ___________session_17(indexes)
Sql server ___________session_17(indexes)Ehtisham Ali
 
Optimized cluster index generation
Optimized cluster index generationOptimized cluster index generation
Optimized cluster index generationRutvik Pensionwar
 
SQL dabatase interveiw pdf for interveiw preparation
SQL dabatase  interveiw pdf for interveiw preparationSQL dabatase  interveiw pdf for interveiw preparation
SQL dabatase interveiw pdf for interveiw preparationkumarvikesh2841998
 
Database index
Database indexDatabase index
Database indexRiteshkiit
 
Dbms interview questions
Dbms interview questionsDbms interview questions
Dbms interview questionsambika93
 
Sydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexesSydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexespaulguerin
 
Database Application for La Salle
Database Application for La SalleDatabase Application for La Salle
Database Application for La SalleJimmy Chu
 
Sql interview q&a
Sql interview q&aSql interview q&a
Sql interview q&aSyed Shah
 
Db performance optimization with indexing
Db performance optimization with indexingDb performance optimization with indexing
Db performance optimization with indexingRajeev Kumar
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfDraguClaudiu
 
SQL Interview Questions - InterviewBit.pdf
SQL Interview Questions - InterviewBit.pdfSQL Interview Questions - InterviewBit.pdf
SQL Interview Questions - InterviewBit.pdfAniket223719
 

Similar to MySQL INDEXES (20)

V25 sql index
V25 sql indexV25 sql index
V25 sql index
 
MSSQL_Book.pdf
MSSQL_Book.pdfMSSQL_Book.pdf
MSSQL_Book.pdf
 
Index in sql server
Index in sql serverIndex in sql server
Index in sql server
 
Sql server ___________session_17(indexes)
Sql server  ___________session_17(indexes)Sql server  ___________session_17(indexes)
Sql server ___________session_17(indexes)
 
Optimized cluster index generation
Optimized cluster index generationOptimized cluster index generation
Optimized cluster index generation
 
SQL dabatase interveiw pdf for interveiw preparation
SQL dabatase  interveiw pdf for interveiw preparationSQL dabatase  interveiw pdf for interveiw preparation
SQL dabatase interveiw pdf for interveiw preparation
 
Database index
Database indexDatabase index
Database index
 
Dbms interview questions
Dbms interview questionsDbms interview questions
Dbms interview questions
 
Sydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexesSydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexes
 
Database Application for La Salle
Database Application for La SalleDatabase Application for La Salle
Database Application for La Salle
 
Sql interview q&a
Sql interview q&aSql interview q&a
Sql interview q&a
 
Indexes
IndexesIndexes
Indexes
 
Module08
Module08Module08
Module08
 
Module08
Module08Module08
Module08
 
Sql introduction
Sql introductionSql introduction
Sql introduction
 
Db performance optimization with indexing
Db performance optimization with indexingDb performance optimization with indexing
Db performance optimization with indexing
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
 
Reviewing SQL Concepts
Reviewing SQL ConceptsReviewing SQL Concepts
Reviewing SQL Concepts
 
DBMS LAB M.docx
DBMS LAB M.docxDBMS LAB M.docx
DBMS LAB M.docx
 
SQL Interview Questions - InterviewBit.pdf
SQL Interview Questions - InterviewBit.pdfSQL Interview Questions - InterviewBit.pdf
SQL Interview Questions - InterviewBit.pdf
 

Recently uploaded

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Recently uploaded (20)

ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 

MySQL INDEXES

  • 2. Why we need INDEXes  Searching for single record in a large table. The usual method of searching the record in the table is to start from the beginning record by record, till we get the record. But it is not feasible when table is large. 1
  • 3. What is an INDEX  Index is usually created to enhance the performance of retrieval of records in huge tables.  Primary key itself acts as an index in a table. 2  An index in a database is very similar to an index in the back of a book.
  • 4. INDEX advantages and disadvantages Advantages Speed up  SELECT queries  WHERE clauses Disadvantages  Slows down transactions like INSERT/DELETE/UPDATE. 3
  • 5. CREATE INDEX  Creating an index depends on the table access frequency, the columns(combination of columns) which are used for fetching the records etc. Indexes involving two or more columns should be ordered from most frequently accessed columns to less frequently accessed columns.  The basic syntax of a CREATE INDEX is as follows  CREATE INDEX index_name ON table_name; 4
  • 6. DROP INDEX  Drop the indexes, if they are no more required in the database. Unwanted and unused indexes always lead to bad performance of a query. An index can be dropped using DROP command. The basic syntax is as follows  DROP INDEX index_name; 5
  • 7. RENAME INDEX  Index can be renamed too  ALTER INDEX index_name RENAME TO new_index_name; 6
  • 8. INDEX types  Single-Column index is created based on only one table column. The basic syntax is as follows  CREATE INDEX index_name ON table_name (column_name);  Unique indexes are used not only for performance, but also for data integrity. A unique index does not allow any duplicate values to be inserted into the table. The basic syntax is as follows.  CREATE UNIQUE INDEX index_name ON table_name (column_name); 7
  • 9. INDEX types  Composite (concatenated) index is an index on two or more columns of a table. Its basic syntax is as follows  CREATE INDEX index_name ON table_name (column1, column2);  Implicit indexes are the one which are indexes by default. That means database considers them as index when the table is created. Primary key and unique key columns are implicit indexes. 7
  • 10. When should INDEXES be avoided? The following guidelines indicate when the use of an index should be reconsidered Indexes should not be used on small tables. Tables that have frequent, large batch updates or insert/delete operations. Indexes should not be used on columns that contain a high number of NULL values. Columns that are frequently manipulated should not be indexed. 8
  • 11. Creating a simple INDEX ID First Name Last Name Class 1 James Bond 6A 2 Chris Smith 6A 3 Jane Eyre 6B 4 Dave Smith 6B In this example, we will be working with a table of students at an extraordinarily large school. This is quite a large table as we have 100,000 studentsin our school. The first few rows of the table look like this 9
  • 12. Queries used The ` was created using the following query 10
  • 13. Requirements Our web application performs 3 queries against this table  Look up a student by ID  Search for students by last name  List all students in a class Each of these queries searches for data from a single column, so we should ensure that each of these columns has its own index. 11
  • 14. The First Query The first query is a special case because it is looking up a row using its PRIMARY KEY. Because we already know exactly which row we want, no further optimization is required. SELECT * FROM students WHERE id = 1; 12 ID First Name Last Name Class 1 James Bond 6A
  • 15. The Second Query The second query will be searching a column which does not currently have an index and this is exactly the type of query that will search the whole table unless we do something about it SELECT * FROM students WHERE last_name = `Smith`; Lets go right ahead and create an index on that column CREATE INDEX by_last_name ON students(`last_name`); Exactly the same principle can be applied to the class column CREATE INDEX by_class ON students (`class`); 13
  • 16. The Third Query The third query will be searching a column which has an index SELECT * FROM students WHERE class = `6A` AND last_name = `Smith`; 14 ID First Name Last Name Class 2 Chris Smith 6A
  • 17. Choosing Columns to Index15 Rather than looking at your queries, it is quite possible to index your database simply by looking through your tables and indexing columns that will obviously be searched on. Here are some examples of columns that should almost always be indexed Columns that join with other tables (they usually end _id). Usernames and/or email addresses, these are looked up every time a user logs in. Any field used in a URL. Remember that id should already be a primary key.
  • 18. Summary16 If you find your SELECT queries are taking a long time to run, you are most likely missing an index on your table. Look at which columns are searching on, and create an index on each one using the following syntax CREATE INDEX index_name ON table_name(column_name); It is always wise to start by indexing columns that join with other tables (they usually end _id). After that, look for columns you know you will commonly search on. Focus on your largest tables.