Yeah - a pretty common index I tend to add is for foreign keys so like, say you have a table of `s

Yeah - a pretty common index I tend to add is for foreign keys

so like, say you have a table of
sensors
and another table of
data
, where data stores
sensor_id
, an index on that column speeds up queries like
SELECT * FROM data WHERE sensor_id = ?


if you also store a timestamp in that table you might want to index against that too so filtering by date is fast, so it'd be like

CREATE INDEX idx_data_sensor_id_timestamp_desc ON data(sensor_id, timestamp DESC)
Was this page helpful?