首页 > 解决方案 > 以更好的优化方式重写查询

问题描述

我有一个更大的查询,当我使用outbreak_info_id in (80106)where 条件时,它会导致我在 2 secs 内。

由于我需要获取一些更相关的数据,所以我需要将上面的where条件替换为下面的 where 条件。

当我将以下where条件放在同一个查询中时,它会在大约 30 秒内给我结果。

有人可以帮助以更好的方式重写以下where条件,以便它以更快的方式执行。

我只能想到我在下面写的。

预期:以更好的方式重写以下查询,

select distinct outbreak_info_id from outbreak_infos 
where outbreak_id 
IN (
select distinct ofe.outbreak_id  from 
outbreaks_for_events ofe
         inner join reports_infos ri on ofe.report_id=ri.report_id
        where  ofe.report_id in ( select distinct report_id from
         outbreaks_for_events oe where outbreak_id in ( 
              select distinct outbreak_id from outbreak_infos 
              where outbreak_info_id in (80106)))
    and ri.status='Validated')

标签: postgresqlquery-optimizationwhere-clause

解决方案


推荐阅读