在同一过滤器上进行多个seq扫描

时间:2014-06-27 08:25:07

标签: postgresql-9.3 sql-execution-plan

我想问为什么执行一个简单的查询优化器决定使用相同的过滤器执行seq扫描两次,最后附加结果?

SELECT count(*)
FROM customers c
WHERE ((name IS NOT NULL) AND (flag = 4) AND (birth_date < now()));

PostgreSQL版本9.3.4 EXPLAIN ANALYZE的输出:

Aggregate  (cost=4444780.90..4444780.91 rows=1 width=0) (actual time=50654.137..50654.137 rows=1 loops=1)

  ->  Append  (cost=0.00..4444776.28 rows=1847 width=0) (actual time=50654.128..50654.128 rows=0 loops=1)

        ->  Seq Scan on customers c  (cost=0.00..4439681.76 rows=1845 width=0) (actual time=50614.774..50614.774 rows=0 loops=1)

              Filter: ((name IS NOT NULL) AND (flag = 4) AND (birth_date < now()))

        ->  Seq Scan on customers c  (cost=0.00..5094.52 rows=2 width=0) (actual time=39.349..39.349 rows=0 loops=1)

              Filter: ((name IS NOT NULL) AND (flag = 4) AND (birth_date < now()))

Total runtime: 50654.245 ms

1 个答案:

答案 0 :(得分:1)

鲍里斯,我想你最好写信给postgresl邮件列表:pgsql-general@postgresql.org 你的问题听起来很奇特(因为它只发生在你身上)。 这是一个友好的群体:他们会帮助,因为支持postgres9.3。

(对不起,这是一个评论,而不是答案。)