我想问为什么执行一个简单的查询优化器决定使用相同的过滤器执行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
答案 0 :(得分:1)
(对不起,这是一个评论,而不是答案。)