嗨,我托管在 Heroku 上,在他们的 Ika 计划(7,5gb ram)上运行 postgresql 9.1.6。我有一张叫汽车的桌子。我需要执行以下操作:
SELECT COUNT(*) FROM "cars" WHERE "cars"."reference_id" = 'toyota_hilux'
现在这需要很长时间(64 秒!!!)
Aggregate (cost=2849.52..2849.52 rows=1 width=0) (actual time=63388.390..63388.391 rows=1 loops=1)
-> Bitmap Heap Scan on cars (cost=24.76..2848.78 rows=1464 width=0) (actual time=1169.581..63387.361 rows=739 loops=1)
Recheck Cond: ((reference_id)::text = 'toyota_hilux'::text)
-> Bitmap Index Scan on index_cars_on_reference_id (cost=0.00..24.69 rows=1464 width=0) (actual time=547.530..547.530 rows=832 loops=1)
Index Cond: ((reference_id)::text = 'toyota_hilux'::text)
Total runtime: 64112.412 ms
一点背景:
该表包含大约 3.2m 行,我试图依靠的列具有以下设置:
reference_id character varying(50);
和索引:
CREATE INDEX index_cars_on_reference_id
ON cars
USING btree
(reference_id COLLATE pg_catalog."default" );
我究竟做错了什么?我希望这种表现不是我应该期待的——或者我应该期待吗?