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的決定使用什麼,特別是?