'Select Query Optimization :: Postgres
I want to optimize the below DB selection query
select * from
table_name
where
(title=? and grade =?)
or
(title=? and debt =? and grade =?)
or
(prog=? and title = ? and debt =?)
Solution 1:[1]
you can use case below way as alternative
select * from
table_name
where
1 = case
when title=? and grade =? then 1
when title=? and debt =? and grade =? then 1
when prog=? and title = ? and debt =? then 1
else 0
end
Just give a try and make sure all are indexed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
