PostgreSQL选择计数(*)花费的时间太长

时间:2018-10-23 08:12:50

标签: postgresql postgresql-9.5

我的postgresql表中有一个表。该表具有约9.100.000行。当我执行查询select count(*) from table时,执行时间约为1.5分钟。这正常吗?而我该如何减少这个时间?

1 个答案:

答案 0 :(得分:0)

如果要估计大小,可以使用count_estimate。它快得多。 https://wiki.postgresql.org/wiki/Count_estimate

另一种解决方法是使用统计信息字段,每次添加新行时都要增加它。

还请阅读https://www.citusdata.com/blog/2016/10/12/count-performance/

相关问题