postgresql - 以更好的优化方式重写查询
问题描述
我有一个更大的查询,当我使用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')
解决方案
推荐阅读
- dockerfile - 从一个 dockerfile 构建和部署,还是为每个目的使用不同的文件?
- jmeter - Java jar 文件(JWT 令牌生成器)需要在 jmeter 中导入,并且必须通过运行方法生成令牌并在一个测试步骤中使用它
- php - JQuery Ajax:购物车项目中的onchange应该改变总值
- android - 有没有办法在 Nativescript Vue 中使用 toString 和 Split 方法?
- emacs - TAB 键在 emacs 的暂存缓冲区中不起作用
- swift - 如何根据相同的id添加两行TableView
- python - 如何在不合并的情况下基于熊猫中的多个键进行映射
- python - CORS 请求在 python flask-socketio 中没有成功
- postgresql - 使用函数的输出作为表名时出现未定义列错误
- java - 在包含侦听器的情况下运行并在没有侦听器的情况下通过时出现 NoClassDefFound 错误