Skip to content
Advertisement

Optimize MySQL InnoDB query for max, count

I have an MySQL InnoDB table with 5.7M rows and 1.9GB size:

Here are my my.ini settings for my 3GB RAM server:

When I run next query it takes over 20 minutes to return the results:

I’ve done some research and it appears I need to add some indexes to speed things up, but I am confused how to go about it. There are some single-column indexes and some multi-column indexes, which one should I do?

To make things more complicated, there are few other queries that I will need to perform on this table regularly:

and

These two are probably less taxing, but I still need to optimize for them as well if possible, although the first query out of three is the top priority for now.

Advertisement

Answer

if you want just the value for a single day and the the data type is date then you could avoid the between clause and use =

and be sure you have an index on sale_date

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement