PostgreSQL执行计划出现——never executed原因及解决方案

目录

  • 问题
  • 解决方案

问题

如题,在使用explain解析执行计划时发现某些执行计划的扫表操作出现(never executed),并且该SQL执行时间很短:

Finalize Aggregate  (cost=18773.69..18773.70 rows=1 width=68) (actual time=99.808..106.950 rows=1 loops=1)
   ->  Gather  (cost=18773.47..18773.68 rows=2 width=68) (actual time=99.637..106.933 rows=3 loops=1)
         Workers Planned: 2
         Workers Launched: 2
         ->  Partial Aggregate  (cost=17773.47..17773.48 rows=1 width=68) (actual time=94.611..94.618 rows=1 loops=3)
               ->  Nested Loop  (cost=43.27..17773.46 rows=1 width=68) (actual time=94.602..94.608 rows=0 loops=3)
                     ->  Hash Join  (cost=43.12..17772.57 rows=2 width=72) (actual time=94.601..94.607 rows=0 loops=3)
                           Hash Cond: (mc.movie_id = t.id)
                           ->  Parallel Seq Scan on movie_companies mc  (cost=0.00..17729.09 rows=89 width=40) (actual time=94.598..94.598 rows=0 loops=3)
                                 Filter: (((note)::text !~~ '%(as Metro-Goldwyn-Mayer Pictures)%'::text) AND (((note)::text ~~ '%(co-production)%'::text) OR ((no
te)::text ~~ '%(presents)%'::text)))
                           ->  Hash  (cost=43.05..43.05 rows=6 width=44) (never executed)
                                 ->  Nested Loop  (cost=19.07..43.05 rows=6 width=44) (never executed)
                                       ->  Hash Join  (cost=18.93..41.81 rows=6 width=4) (never executed)
                                             Hash Cond: (mi_idx.info_type_id = it.id)
                                             ->  Seq Scan on movie_info_idx mi_idx  (cost=0.00..20.20 rows=1020 width=8) (never executed)
                                             ->  Hash  (cost=18.88..18.88 rows=4 width=4) (never executed)
                                                   ->  Seq Scan on info_type it  (cost=0.00..18.88 rows=4 width=4) (never executed)
                                                         Filter: ((info)::text = 'top 250 rank'::text)
                                       ->  Index Scan using title_pkey on title t  (cost=0.14..0.21 rows=1 width=40) (never executed)
                                             Index Cond: (id = mi_idx.movie_id)
                     ->  Index Scan using company_type_pkey on company_type ct  (cost=0.15..0.40 rows=1 width=4) (never executed)
                           Index Cond: (id = mc.company_type_id)
                           Filter: ((kind)::text = 'production companies'::text)
 Planning Time: 0.898 ms
 Execution Time: 107.107 ms

解决方案

首先,never executed出现的位置大多数是Index Scan/Seq Scan/Parallel Seq Scan等扫表操作,这时候怀疑是表里没数据:

select count(*) from title;

发现查出来的数据为空,所以重新导入数据,将缺少数据的表导入,而后执行计划就正常了,且sql执行的时间也正常。

你可能感兴趣的:(各类安装bug和其它bug,postgresql,哈希算法,数据库)