postgresql - Postgresql select count(*) 耗时太长
问题描述
我的 postgresql 表中有一个表。该表有大约 9.100.000 行。当我执行查询select count(*) from table
时,执行时间约为 1.5 分钟。这是正常的吗?我能做些什么来减少这个时间?
解决方案
如果您想估计大小,可以使用 count_estimate。它要快得多。 https://wiki.postgresql.org/wiki/Count_estimate
另一种解决方法是使用统计字段,在每次添加新行时增加它。
另请阅读https://www.citusdata.com/blog/2016/10/12/count-performance/
推荐阅读
- c++ - 向量int交换实现?
- maven - Maven Surefire 运行测试命令行字符串限制 (-Dtest=xyz#abc)
- firebase - Firebase 中的 BigQuery 集成反复返回 409
- html - 关于 HTML5 替代图像文件的说明
- aerospike - AEROSPIKE_ERR_INDEX_NOT_FOUND - Python 客户端
- firebase - 如何使用 id_token 通过 HTTP REST API 生成自定义令牌
- android - 我需要同步第二个库,但 IDE 告诉我他找不到它为什么以及是什么问题
- powershell - 使用 powershell 构建管道
- python - 在python中,如何求解对数方程(x*logx)
- python - S3 存储桶上的 AWS Lambda 触发器到海王星“无法为源启动新负载”