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