1
有沒有辦法來加速我們的plpgsql函數來計算某個類型的文檔全部在一個循環中執行的查詢中? ALL在一個查詢中?加速plpgsql來計算循環中的文檔類型?
validador := (select count(id_doc) from webdte.doc_tip_cifra
where id_doc = id_documento and id_tipo_cifra = 901);
validador2 := (select count(id_doc) from webdte.doc_tip_cifra
where id_doc = id_documento and id_tipo_cifra = 902);
validador3 := (select count(id_doc) from webdte.doc_tip_cifra
where id_doc = id_documento and id_tipo_cifra = 905);
validador4 := (select count(id_doc) from webdte.doc_tip_cifra
where id_doc = id_documento and id_tipo_cifra = 907);
謝謝你的回答,但不幸的是它仍然很慢。它永遠需要20000個文件。我把索引放在所有id列上,但仍然無法使用。 |如果沒有辦法進一步優化它,我會完全放棄這個想法,爲4個不同的ID測試所有文檔,並在插入觸發器上插入空行。 – mugdiman 2012-07-24 01:44:55
剛剛在25k行的表上進行了測試,上面的查詢花費了100毫秒,沒有任何索引。你的桌子或你的裝置有些東西沒有了。運行'VACUUM FULL ANALYZE webdte.doc_tip_cifra',然後重試查詢。任何改變?順便說一句,如果'id_doc = id_documento'對於表的相當大的部分是正確的(超過〜5%,取決於行大小和其他因素),**索引不會幫助**查詢,因爲表掃描速度更快。你不應該只是「把索引放在所有ID列」。只創建實際需要的索引 - 它們也會帶來成本。 – 2012-07-24 02:26:23