My table structure is as follows:
CREATE TABLE IF NOT EXISTS
commodity_data(
dataidbigint(20) unsigned NOT NULL AUTO_INCREMENT,
commoditysmallint(6) NOT NULL,
marketsmallint(6) NOT NULL,
quantityfloat NOT NULL,
price_minmediumint(9) NOT NULL,
price_maxmediumint(9) NOT NULL,
price_modalmediumint(9) NOT NULL,
datedate NOT NULL,
modifiedtimestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (dataid)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7059415 ;
My SELECTs on this table will have WHERE clauses with one or more of 'commodity', 'market' and 'date' searched on.
My ORDER BYs will be by price_min, price_max or price_modal and sometimes most of the other fields.
The table will end up being over 10 million rows and will keep expanding by about 5 to 10 thousand a day.
My server is currently a VPS dual 2.4Ghz xeon, 4GB RAM.
The only index is currently on the 'dataid' field.
I have read that setting up indexes can help and I think these should be on commodity, market and date, but I wanted to check if this is right before going ahead unless there's a better way of doing this. The table size will be around 600MB and growing.
The 'commodity' and 'market' fields refer to the ID of commodities and markets in other tables. I will either LEFT JOIN or if it's faster, I will read those tables into arrays in PHP (simple one-level associative arrays id => name). There are around 300 commodities and 2,000 markets.
Currently SELECTs are taking too long, and for example COUNT queries with a WHERE clause will take a minute or more.