我有一个工作很慢的PostgreSQL的功能。其中一个查询存在问题。有什么办法可以优化它吗?我做的索引帮助不大。很慢SQL INSERT查询
INSERT INTO aa_c_axis_doc_oper
SELECT a.pool_id,
l.lane_id,
a.axis_id,
l.id AS src_row_id,
a.running_sum_abs,
a.running_sum_abs_begin_max,
l.program_id
FROM aa_oper_axis AS a
INNER JOIN aa_src1 AS l
ON a.pool_id = l.pool_id
WHERE l.running_sum_abs_begin <= a.running_sum_abs_begin_max
AND a.running_sum_abs <= l.running_sum_abs
解释
Insert on aa_c_axis_doc_oper (cost=0.00..19727005.41 rows=345535083 width=84) (actual time=5428290.637..5428290.637 rows=0 loops=1)
-> Nested Loop (cost=0.00..19727005.41 rows=345535083 width=84) (actual time=235.809..5348024.371 rows=9954308 loops=1)
-> Seq Scan on aa_oper_axis a (cost=0.00..50396.63 rows=6085633 width=72) (actual time=0.040..3351.155 rows=6012431 loops=1)
-> Index Scan using aa_src1_pool_id_running_sum_abs_begin_running_sum_abs_idx on aa_src1 l (cost=0.00..2.75 rows=57 width=34) (actual time=0.881..0.887 rows=2 loops=6012431)
Index Cond: ((pool_id = a.pool_id) AND (running_sum_abs_begin <= a.running_sum_abs_begin_max) AND (a.running_sum_abs <= running_sum_abs))
Total runtime: 5428290.775 ms
这可能会得到更多的关注[这里](http://codereview.stackexchange.com/)或者[这里](http://dba.stackexchange.com/) – Alexander
@Alexander ...但你可以将其标记为迁移。 Madbw,没有必要重新张贴在其他地方。 –
@CraigRinger我不知道,谢谢。而且,实际上,这只是建议,我不确定。 – Alexander