Version MySQL 5.7.2
I'm working with dummy data with int columns.
time: 1-10mm
products: 70,000 random ints with another 30,000 that are dupes from the 70,000
volume: ranges from 500 - 1000
price: ranges from 10 - 50 though the price stays within bounds of 1-5 diff for each product row data.
from the above, 10mm rows are created by randomly selecting a product and generating the required row data
running a range query like...
select * from productdata where product >= 1500 and product <= 2000
takes about 4 seconds.
When I add an index on product using...
create index productindex on productdata(product)
The query now takes about 30 seconds. Time is the only unique column in the table but setting that as the primary key does not help either.
On SQL Server and PostgreSQL I don't see the same issues with the same data and query using a non clustered index in each. I only really have experience with writing queries for SQL Server so a bit perplexed by this. I tried PostgreSQL as well to have another db to compare to.
All databases are the latest stable versions available.
Action Output (I had to decrease the range as the original query was taking too long)...
Without Index..
With Index..
Table status...
Buffer...
Explain Select...
Show create table...
CREATE TABLE `products` (
`time` int(11) DEFAULT NULL,
`product` int(11) DEFAULT NULL,
`quantity` int(11) DEFAULT NULL,
`price` int(11) DEFAULT NULL,
KEY `productindex` (`product`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Trying with time and product as key...
SHOW CREATE TABLE productdata;
and the version of MySQL (is it 5.7 or something else?)