Christoffer
Christoffer

Reputation: 7777

How should I optimize my MySQL Query or Table?

I have a database-table with about 33 million rows. I'm trying to optimize my queries. Right now I'm only using a smaller version of the dataset with 8 million rows. If I run this:

SELECT DISTINCT c_size FROM data WHERE c_name = 'jeans'

It will return the data in 176 seconds If I run:

EXPLAIN SELECT DISTINCT c_size FROM data WHERE c_name = 'jeans'

This is the result.

id: 1   
select_type : SIMPLE
table : data
type : index
possible_keys : NULL    
key : c_size
key_len : 5
ref : NULL
rows :  14876049
Extra : Using where

Do you have any pointers to how I could optimize my queries, my table or my database? The database is running through MAMP. I'm administrating the database with Sequel Pro.

Upvotes: 1

Views: 45

Answers (1)

Alex
Alex

Reputation: 21766

Adding the following index on the data table might help performance:

CREATE INDEX ix_data_c_name ON data (c_name);

Upvotes: 1

Related Questions