优化大量数据的SQL查询

时间:2020-05-12 02:31:00

标签: sql postgresql

我在优化SQL查询方面不是很好,因此需要专家的帮助。 如果您能帮助我优化以下查询,以便使其更高效地运行,将不胜感激。 该查询的执行花费了大约1分钟的时间。

    select distinct oninf.out_id,ob.report_id,cq.total_out, rep.epi_id ,rep.r_id     
                        from o_infos oninf
                        inner join o_for_events ob on oninf.out_id = ob.out_id 
                        left outer Join cluster_quantities cq on oninf.out_id = cq.out_id 
                        inner join reports rep on ob.epi_id = rep.epi_id                
                        inner join reports_infos rinf on rep.r_id = rinf.r_id
                        inner Join o_sp_quantity osq on osq.out_id  = oninf.out_id 
                        where rinf.r_type in ('SS', 'DM') and rinf.status in('V') 

1 个答案:

答案 0 :(得分:0)

请尝试以下操作:

1)收集统计信息,如果需要,可以在桌子上进行真空分析 2)检查AWR报告(自动工作负荷报告),看是否可以改善任何事情,例如I / O操作,CPU使用率等。 3)您可能必须看一下是否可以从并行执行方面进行任何改进: https://www.postgresql.eu/events/pgconfeu2018/sessions/session/2140/slides/141/PQ_PGCON_EU_2018.pdf 4)如果以上方法均无效,则请查看您创建了哪些索引以及如何使用它们。根据需要适当使用索引。 5)如果问题仍然存在,则可以将逻辑拆分为中间表,请在联接运算符中使用这些中间表。这样,您将不必连接较少数量的表,并且可以在中间表中使用预先计算的结果。