to get only data with latest timestamp i use the mysql query from this answer:
fetch-the-row-which-has-the-max-value- for-a-column
my query is following:
SELECT stock_id,timestamp,price FROM market m1
WHERE timestamp =
(SELECT MAX(timestamp) FROM market m2 WHERE m1.stock_id = m2.stock_id)
but it takes 10 minutes to execute.
what are the different options to optimize it? (mysql)
market has following schema: (sqlalchemy)
class Market(db.Model):
stock_id=db.Column(db.Integer,db.ForeignKey('stock.id'),primary_key=True)
timestamp=db.Column(db.Integer,primary_key=True)
price=db.Column(db.Float)