获取postgres继承的行数



我使用postgres继承,其中每个基表有大约200个子表,每个子表有大约5个分区表,总记录约为20CR。我试图获取计数使用基本的选择(*)查询,但它需要很长时间。

是否可以在60秒内获得计数

12.8版本

您可以尝试使用解释(实际行),但它可能不准确:

explain analyze select count(*) from table;
QUERY PLAN                                                  
-------------------------------------------------------------------------------------------------------------
Aggregate  (cost=180.86..180.87 rows=1 width=8) (actual time=9.389..9.390 rows=1 loops=1)
->  Seq Scan on table  (cost=0.00..173.09 rows=3109 width=0) (actual time=3.070..9.255 rows=3156 loops=1)
Planning Time: 0.118 ms
Execution Time: 9.420 ms
(4 rows)
Time: 9,890 ms
# select count(*)  from table;
count 
-------
3156
(1 row)

时间:0.875 ms

最新更新