I have a large table (> 50 m rows) that has some data with id and timestamp:
id, timestamp, data1, ..., dataN
... with an index with multiple columns on (id, timestamp) .
I need to query a table to select all rows with a specific identifier, where the timestamp is between the two dates that I am currently doing, using:
SELECT * FROM mytable WHERE id = x AND timestamp BETWEEN y AND z
It currently takes more than 2 minutes on a high-performance computer (2x Xeon 3Ghz tri-core with HT, 16 GB of RAM, 2x 1 TB of drives in RAID 0), and I really would like to speed it up.
I found this tip that recommends using a spatial index, but the example it gives applies to IP addresses. However, the increase in speed (from 436 to 3 seconds) is impressive.
How can I use this with timestamps?
performance sql postgresql spatial-index
Roger
source share