explain analyze
表明Postgres将使用索引扫描我的查询,其获取的行和由日期执行滤波(即,2017-04-14 05:27:51.039
):postgres如何决定是使用索引扫描还是seq扫描?
explain analyze select * from tbl t where updated > '2017-04-14 05:27:51.039';
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------
Index Scan using updated on tbl t (cost=0.43..7317.12 rows=10418 width=93) (actual time=0.011..0.515 rows=1179 loops=1)
Index Cond: (updated > '2017-04-14 05:27:51.039'::timestamp without time zone)
Planning time: 0.102 ms
Execution time: 0.720 ms
然而运行相同的查询,但具有不同的日期过滤器“2016年4月14日05:27:51.039' 显示,Postgres将使用了序列扫描,而不是运行查询:
explain analyze select * from tbl t where updated > '2016-04-14 05:27:51.039';
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------
Seq Scan on tbl t (cost=0.00..176103.94 rows=5936959 width=93) (actual time=0.008..2005.455 rows=5871963 loops=1)
Filter: (updated > '2016-04-14 05:27:51.039'::timestamp without time zone)
Rows Removed by Filter: 947
Planning time: 0.100 ms
Execution time: 2910.086 ms
按日期进行过滤时如何Postgres的决定使用什么,特别是?