Hi,
I have one simple but large table.
id_tick INTEGER eg: 1622911
price DOUBLE eg: 1.31723
timestamp DATETIME eg: '2010-04-28 09:34:23'
For 1 month of data, I have 2.3 millions rows (150MB)
My query aims at returning the latest price at a given time.
I first set up a SQLite table and used the query:
SELECT max(id_tick), price, timestamp
FROM EURUSD
WHERE timestamp <='2010-04-16 15:22:05'
It is running in 1.6s.
As I need to run this query several thousands of time, 1.6s is by far too long...
I then set up a MySQL table and modified the query (the max function differs from MySQL to SQLite):
SELECT id_tick, price, timestamp
FROM EURUSD
WHERE id_tick = (SELECT MAX(id_tick)
FROM EURUSD WHERE timestamp <='2010-04-16 15:22:05')
Execution time is getting far worse 3.6s (I know I can avoid the sub query using ORDER BY and LIMIT 1 but it does not improve the execution time.)
I am only using one month of data for now, but I will have to use several years at some point.
My questions are then the following:
- is there a way to improve my query?
- given the large dataset, should I use another database engine?
- any tips ?
Thanks !