Select 查询优化:: Postgres

Select Query Optimization :: Postgres

我想优化下面的数据库选择查询

select * from
    table_name 
 where
    (title=? and grade =?)
 or
    (title=? and debt =? and grade =?)
 or
     (prog=? and title = ? and debt =?)

您可以使用以下方式作为替代方法

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

试试看,确保所有内容都已编入索引。