performance - 为什么在主表上查询很慢?

标签 performance postgresql partitioning

我有一张很大的 table 。所以我对这张表进行了分区。并将所有记录从主表复制到子表。然后我从主表中删除了所有记录。现在我的主表是空的。对子表进行查询非常快。但是查询master表还是很慢的。有什么问题吗?

postgres=# select count(*) from only cdr;
 count 
-------
     0
(1 row)

postgres=# explain select count(*) from only cdr;
                              QUERY PLAN                               
-----------------------------------------------------------------------
 Aggregate  (cost=2045094.31..2045094.32 rows=1 width=0)
   ->  Seq Scan on cdr  (cost=0.00..2044867.85 rows=90585 width=0)
(2 rows)

postgres=# EXPLAIN ANALYZE select count(*) from only cdr;
                                                        QUERY PLAN                                                    

----------------------------------------------------------------------------------------------------------------------
-----
 Aggregate  (cost=2045094.31..2045094.32 rows=1 width=0) (actual time=168385.356..168385.356 rows=1 loops=1)
   ->  Seq Scan on cdr  (cost=0.00..2044867.85 rows=90585 width=0) (actual time=168385.351..168385.351 rows=0 loop
s=1)
 Total runtime: 168385.404 ms
(3 rows)

我还在主表上运行了真空分析。但仍然没有运气。

postgres=# vacuum analyze cdr; 真空

我发现其他一些人也遇到了同样的问题。可能根本原因是虽然master表中的旧记录已被删除,但psql不知何故仍然扫描这些垃圾数据。一种解决方案是创建一个新的主表,并放弃旧的主表。但是这个解决方案不适合我。没有停机的任何其他解决方案?谢谢!

最佳答案

我解决了这个问题。只需要在主表上运行“vacuum full”或“c​​luster”。

关于performance - 为什么在主表上查询很慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31342196/

相关文章:

mysql - 如何对包含多个唯一键的 MySQL 表进行分区?

java - 成为绩效顾问的主要技能是什么?

java - 为什么单个 "if"比 "switch"慢?

performance - 如何选择和配置 JasperReports 虚拟器?

ruby-on-rails - 在 Rails 中反序列化数据库中的列

sql - Postgres JOIN 实现

javascript - 与使用 eval 相比,包含 <script> 标签是否有性能提升?

postgresql - postgres 行到二维数组

sql - 对现有表进行分区

apache - 为什么配置单元中的桶数应等于 reducer 数?