I have the following simple table that contains traffic measurement data:
CREATE TABLE "TrafficData" ( "RoadID" character varying NOT NULL, "DateID" numeric NOT NULL, "ExactDateTime" timestamp NOT NULL, "CarsSpeed" numeric NOT NULL, "CarsCount" numeric NOT NULL ) CREATE INDEX "RoadDate_Idx" ON "TrafficData" USING btree ("RoadID", "DateID");
The RoadID column uniquely identifies the road whose data is being recorded, and DateID identifies the day of the year (1..365) of the data - basically a rounded ExactDateTime view.
I have about 100,000,000 lines; the RoadID column has 1,000 different values ββand 365 different values ββin the DateID column.
Then I run the following query:
SELECT * FROM "TrafficData" WHERE "RoadID"='Station_1' AND "DateID">20100610 AND "DateID"<20100618;
It will take up to three breathtaking seconds to complete, and I canβt let my life determine WHY.
EXPLAIN ANALYZE gives me the following result:
Bitmap Heap Scan on "TrafficData" (cost=104.84..9743.06 rows=2496 width=47) (actual time=35.112..2162.404 rows=2016 loops=1) Recheck Cond: ((("RoadID")::text = 'Station_1'::text) AND ("DateID" > 20100610::numeric) AND ("DateID" < 20100618::numeric)) -> Bitmap Index Scan on "RoadDate_Idx" (cost=0.00..104.22 rows=2496 width=0) (actual time=1.637..1.637 rows=2016 loops=1) Index Cond: ((("RoadID")::text = 'Station_1'::text) AND ("DateID" > 20100610::numeric) AND ("DateID" < 20100618::numeric)) Total runtime: 2163.985 ms
My specifications:
- Windows 7
- Postgres 9.0
- RAM 4 GB
I would really appreciate some helpful tips!
performance indexing postgresql
Troutking
source share