PostgreSQL查询计划已更改

时间:2020-05-07 21:48:11

标签: postgresql postgresql-9.6

我最近对一系列表进行了全面的清理,并且特定的监视查询突然变得非常缓慢。这曾经是我们用于监控的查询,因此过去两个月会每10秒愉快地运行一次,但是由于真空之后出现的性能下降,大多数使用它的仪表板都关闭了,直到服务器用完为止连接或资源取决于。

不幸的是,我没有上一个的解释输出。

不指定日期限制:

解释(分析,定时),从iqsim_cdrs中选择min(id);

 Result  (cost=0.64..0.65 rows=1 width=8) (actual time=6.222..6.222 rows=1 loops=1)
   InitPlan 1 (returns $0)
     ->  Limit  (cost=0.57..0.64 rows=1 width=8) (actual time=6.216..6.217 rows=1 loops=1)
           ->  Index Only Scan using iqsim_cdrs_pkey on iqsim_cdrs  (cost=0.57..34265771.63 rows=531041357 width=8) (a
ctual time=6.213..6.213 rows=1 loops=1)
                 Index Cond: (id IS NOT NULL)
                 Heap Fetches: 1
 Planning time: 1.876 ms
 Execution time: 6.313 ms
(8 rows)

通过限制日期:

解释(分析,定时)从iqsim_cdrs中选择min(id),其中时间戳<'2019-01-01 00:00:00';

 Result  (cost=7.38..7.39 rows=1 width=8) (actual time=363763.144..363763.145 rows=1 loops=1)
   InitPlan 1 (returns $0)
     ->  Limit  (cost=0.57..7.38 rows=1 width=8) (actual time=363763.137..363763.138 rows=1 loops=1)
           ->  Index Scan using iqsim_cdrs_pkey on iqsim_cdrs  (cost=0.57..35593384.68 rows=5227047 width=8) (actual t
ime=363763.133..363763.133 rows=1 loops=1)
                 Index Cond: (id IS NOT NULL)
                 Filter: ("timestamp" < '2019-01-01 00:00:00'::timestamp without time zone)
                 Rows Removed by Filter: 488693105
 Planning time: 7.707 ms
 Execution time: 363763.219 ms
(9 rows)

不确定是什么原因造成的,我只能在时间戳使用索引之前完全假设吗?

*更新* 根据@jjanes的建议,此处id + 0更新

 explain (analyze,timing) select min(id+0) from iqsim_cdrs where timestamp < '2019-01-01 00:00:00';
                                                                          QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=377400.34..377400.35 rows=1 width=8) (actual time=109.176..109.177 rows=1 loops=1)
   ->  Index Scan using index_iqsim_cdrs_on_timestamp on iqsim_cdrs  (cost=0.57..351196.84 rows=5240699 width=8) (actual time=0.131..108.911 rows=126 loops=1)
         Index Cond: ("timestamp" < '2019-01-01 00:00:00'::timestamp without time zone)
 Planning time: 4.756 ms
 Execution time: 109.405 ms
(5 rows)

0 个答案:

没有答案
相关问题