If you’re doing a query on a very large db then always make sure you’ve got an index on fields that are being used to group (WHERE) data. In my case, I was doing a query on a table with 249M entries that was using a WHERE on a ‘symbol’ field. By adding an index to the symbol field, the data is grouped by MySQL and is returned way, way faster (hundreds of times faster)

DO this at your own risk and DO NOT do this on a DB unless you have a full backup.

ALTER TABLE data.minute ADD INDEX(symbol);

data.minute is the table

symbol is the field you’re adding the index to.

More info and detail can be found here