您好,我有以下查询(我使用CURRENT_DATE进行查询演示,稍后它将作为函数的参数):
SELECT *
FROM FOO_TBL
WHERE FOO_VERSION_FROM <= CURRENT_DATE
AND (FOO_VERSION_TO >= CURRENT_DATE) OR (FOO_VERSION_TO IS NULL))
AND (FOO_ACTIVE_FROM IS NOT NULL)
ORDER BY ID;
我已经创建了这样的索引:
CREATE INDEX FOO_IDX ON FOO_TBL (FOO_VERSION_FROM, FOO_VERSION_TO, FOO_ACTIVE_FROM )
对该查询的解释(分析,缓冲区)命令输出:
"Sort (cost=7171052.33..7173000.95 rows=979450 width=6999) (actual time=2135.384..2364.861 rows=979517 loops=1)"
" Sort Key: ID"
" Sort Method: external merge Disk: 212224kB"
" Buffers: shared hit=10380 read=47568, temp read=61082 written=61166"
" I/O Timings: read=269.324"
" -> Seq Scan on plain_subjekt subjekt (cost=0.00..77435.98 rows=979450 width=6999) (actual time=0.175..733.647 rows=979517 loops=1)"
" Filter: ((FOO_VERSION_FROM <= CURRENT_DATE) AND ((FOO_VERSION_TO >= CURRENT_DATE) OR (FOO_VERSION_TO IS NULL)) AND (FOO_ACTIVE_FROM IS NOT NULL))"
" Rows Removed by Filter: 2"
" Buffers: shared hit=10380 read=47568"
" I/O Timings: read=269.324"
"Planning time: 0.156 ms"
"Execution time: 2410.941 ms"
我做错了什么?