Vasu
Vasu

Reputation: 1

Performance of SQL query if more conditions includes in WHERE clause

Can anyone answer how the performance of SQL will be impacted if we include more conditions in Where clause?

For example I have a table TABLE1 with 15 columns Column1, Column2, ..., Column15. And of those 15 columns, column1 (primary key) and column7 are indexed.

Now if I want to retrieve the data based on COLUMN1, COLUMN7 and COLUMN10 from my application (hibernate ORM), so is it good to query with

SELECT * 
FROM TABLE1 
WHERE COLUMN1 = ? AND COLUMN7 = ? AND COLUMN10 = ?

or

SELECT * 
FROM TABLE1 
WHERE COLUMN1 = ? AND COLUMN7 = ? 

and filter the results for COLUMN10 in the application side?

Including more filters in the WHERE clause gives better performance or it is bad for performance of SQL query?

Upvotes: 0

Views: 718

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269445

You should put more conditions in the WHERE clause. Let the database do the work. Here are two good reasons:

  • It reduces the amount of data passing between the database and the application. Less data is more performance.
  • It allows the database to optimize the query, perhaps using better indexes. More optimization is more performance.

Upvotes: 2

Related Questions