I have the below query that through profiling is taking a bit more time that expected and I would like to tweak it some. The purpose of the query is to get the last 3 hours of data from the Messages table for a given device_id and order the results by last message receive (time desc). There currently is a composite index on the database that doesn't seem to really be ideal. Any index or query syntax changes recommendations to speed up this query?
Messages Table Structure:
Columns:
id (auto incremented PK NUMBER(10))
device_id
model_id
state
creation_date (DATE when row was inserted)
time (unix time message was transmitted)
//a bunch of other columns omitted
Indexes:
id
device_id, model_id, state (composite index)
Query:
select * from messages where device_id='0-12345678' and creation_date > sysdate-3/24 order by time desc