I have a table with 85,000 records, which will grow daily!
I am running a query for example:
SELECT * FROM `table`
WHERE `start_timestamp` >= 'TIMESTAMP'
AND `end_timestamp` <= 'TIMESTAMP'
This query is literally taking forever to run on 85,000 rows, never mind 1,000,000
Now the field for the timestamp is actually a large integer holding a timestamp from php. The query is run through php with codeigniter query()
It runs pretty quick if the date range < 31 days, but anything above that it's extremely slow. I also have indexes on those 2 columns on the where clause.
These are some suggestions to improve the performance of the query
Since start_timestamp
and end_timestamp
are the only criteria for your query, I suggest you create an index for them.
CREATE INDEX `idx_timestamp` ON `table` (`start_timestamp`, `end_timestamp`);
This should optimize MySQL's ability to locate the records with the specified criteria.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.