I have a database table that has three columns: an ID, a timestamp, and a string. About 14,000 rows are inserted every day, so the table is very large. It currently has 1.3 million rows.
Table definition:
CREATE TABLE readings (
id int primary key auto_increment,
ts datetime not null, --the timestamp
json text not null --the string
);
The query I’m running is:
SELECT * FROM readings WHERE ts >= 'TIME_START' AND ts <= 'TIME_END' ORDER BY ts
The query takes around 45 seconds to execute. How can I modify the table and/or query to make it faster?
Thanks.
Add a new index on
tsto the table.