ここに違いはありません (pg 9.1.2)。アーティファクトだと思います (スキーマ、大文字と小文字の区別はありませんか?)
DROP SCHEMA tmp CASCADE;
CREATE SCHEMA tmp ;
SET search_path=tmp;
CREATE TABLE lutser
( id INTEGER NOT NULL PRIMARY KEY
, val INTEGER NOT NULL
);
INSERT INTO lutser(id,val)
SELECT g, g %31
FROM generate_series(1,100000) g
;
DELETE FROM lutser WHERE random() < .5;
VACUUM ANALYZE lutser;
EXPLAIN ANALYZE
SELECT COUNT(*) FROM lutser
WHERE id >= 1000 AND id < 2000
;
CREATE INDEX lutser_id ON lutser(id);
VACUUM ANALYZE lutser;
EXPLAIN ANALYZE
SELECT COUNT(*) FROM lutser
WHERE id >= 1000 AND id < 2000
;
結果:
NOTICE: drop cascades to table tmp.lutser
DROP SCHEMA
CREATE SCHEMA
SET
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "lutser_pkey" for table "lutser"
CREATE TABLE
INSERT 0 100000
DELETE 50051
VACUUM
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=20.28..20.29 rows=1 width=0) (actual time=0.294..0.295 rows=1 loops=1)
-> Index Scan using lutser_pkey on lutser (cost=0.00..19.03 rows=499 width=0) (actual time=0.015..0.216 rows=487 loops=1)
Index Cond: ((id >= 1000) AND (id < 2000))
Total runtime: 0.343 ms
(4 rows)
CREATE INDEX
VACUUM
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=19.03..19.04 rows=1 width=0) (actual time=0.232..0.232 rows=1 loops=1)
-> Index Scan using lutser_id on lutser (cost=0.00..17.79 rows=497 width=0) (actual time=0.033..0.185 rows=487 loops=1)
Index Cond: ((id >= 1000) AND (id < 2000))
Total runtime: 0.266 ms
(4 rows)