的delayed_job做了查詢關鍵詞,比如定期的:在postgres上進行此delayed_job查詢的最佳索引是什麼?
SELECT "delayed_jobs".*
FROM "delayed_jobs"
WHERE ((run_at <= '2012-05-23 15:16:43.180810' AND (locked_at IS NULL OR locked_at < '2012-05-23 11:16:43.180841') OR locked_by = 'host:foo pid:1') AND failed_at IS NULL)
ORDER BY priority ASC, run_at ASC LIMIT 5
我的日誌,對我相當大的DB機報告,它需要四分之一秒的運行。我只能在所選的所有列上拋出一些索引,但我可能從多列索引中獲得更多性能。
什麼是我可以爲這個查詢做出的最優多列索引?有什麼工具可以爲我計算這個嗎?
更新
Postgres的版本:9.1.3
一個現有的索引:優先級,run_at(名爲 「delayed_jobs_priority」)
出explain analyze
:
Limit (cost=0.00..219.65 rows=5 width=1154) (actual time=0.727..0.727 rows=0 loops=1)
-> Index Scan using delayed_jobs_priority on delayed_jobs (cost=0.00..351.43 rows=8 width=1154) (actual time=0.725..0.725 rows=0 loops=1)
Filter: ((failed_at IS NULL) AND (((run_at <= '2012-05-23 18:11:03.980113'::timestamp without time zone) AND ((locked_at IS NULL) OR (locked_at < '2012-05-23 14:11:03.98014'::timestamp without time zone))) OR ((locked_by)::text = 'host:foo pid:1'::text)))
Total runtime: 0.754 ms
(4 rows)
有沒有現有的索引? – swasheck
什麼是當前的解釋計劃和你在什麼版本的PG? – Kuberchaun
@JustBob我現在將這個信息添加到我的問題 –