0% found this document useful (0 votes)
5 views10 pages

8 Tips To Improve SQL Query Performance

The document provides tips for improving SQL query performance, including using limited joins, creating indexes, and utilizing query plans. It emphasizes the importance of restricting columns, avoiding wildcards and subqueries, and preferring EXISTS over joins when applicable. Additionally, it highlights the benefits of using primary keys for optimized searching in queries.

Uploaded by

vinnuglv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

8 Tips To Improve SQL Query Performance

The document provides tips for improving SQL query performance, including using limited joins, creating indexes, and utilizing query plans. It emphasizes the importance of restricting columns, avoiding wildcards and subqueries, and preferring EXISTS over joins when applicable. Additionally, it highlights the benefits of using primary keys for optimized searching in queries.

Uploaded by

vinnuglv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

SQL Tips to Improve

Query Performance

Vikas Rajput
@vikasrajputin
1. Use Limited Joins

➔ Make a habit of using as less join


as possible, using more joins
degrade the query performance

➔ Use only when it's absolutely


required

@vikasrajputin
2. Indexing and Primary Key

➔ Make sure to create indexes for


the columns being frequently
searched

➔ Make sure to put the primary key


in the table, it also helps in
boosting the performance

@vikasrajputin
3. Use Query Plan

➔ Query plan/optimization report


breaks the query processing into
multiple parts and tells you how
much time each part is taking

➔ Helps a lot in identifying the issue,


and you can take necessary actions
accordingly

Note: Query Plan/Optimization Report’s Name might


depends on DB to DB.

@vikasrajputin
4. Restrict Columns

➔ Avoid fetching all columns or any


unused columns, focus on the
columns you need to accomplish
the given task

➔ Don't try to reuse same query


everywhere in which you're using
unused columns

➔ Create another method, and write a


separate query

@vikasrajputin
5. Avoid Wildcards

➔ The wildcard-based search slows


down the query performance

➔ It scans all the records to find


correct results

➔ Avoid them if the same job can be


done with an alternate approach

@vikasrajputin
6. Avoid Subqueries

➔ Too much subquery can degrade


the performance very badly

➔ They get executed for each row


fetched so it is advisable to limit
their use

@vikasrajputin
7. Try EXISTS over Joins

➔ Sometimes, to check if a record exist


or not, we use join with the main
table

➔ If you are not retrieving the columns


of the other table which you've
joined, then try to use EXISTS
instead of Join

➔ EXISTS is blazing fast!

Note: Not in all cases Exists is fast, it depends on your DB


server, Query execution plan used by your server so first
try if EXISTS is performing better in place of Join, if yes
then only use it.

@vikasrajputin
8. Prefer Primary Key

➔ Primary keys are optimised for


searching, whenever possible
always use primary key in where
clause Instead of using any non
primary key column

@vikasrajputin
❤ Thanks for reading !

For more content on


Java & Backend Development,
follow me on below handles

Vikas Rajput
@vikasrajputin

You might also like