Reputation: 1
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
Reputation: 1269445
You should put more conditions in the WHERE
clause. Let the database do the work. Here are two good reasons:
Upvotes: 2