MySQL Forums
Forum List  »  Performance

Index vs Partition vs Other? for not-very-selective column
Posted by: Nicholas Beaudrot
Date: September 14, 2009 02:04PM

I have a query I'm running repeatedly against this table:

CREATE TABLE song_data (
id BIGINT NOT NULL AUTO_INCREMENT,
beat_number UNSIGNED SMALLINT NOT NULL,
total_score UNSIGNED MEDIUMINT NOT NULL,
band_state UNSIGNED INT NOT NULL,
PRIMARY_KEY (id)
) ENGINE=...

beat_number is in the range [0,4192). The id exists only because I seem to need it in order to have indices. For each beat_number, there are about 10m rows, each with a different band_state value.

This is the query we run over and over again:

SELECT band_state, total_score FROM table where beat_number=n AND band_state IN (...)

with between 0 and 65 values in the IN clause. All executions for the same beat_number will be run consecutively.

Hopefully now you can see where I am going: what I am trying to do is tell the database to load all the rows for a given beat_number (and only for that beat_number) from disk, and then keep them in memory while I iterate over them again and again. But I'm not sure what the best way to instruct the DB is. Should I partition based on beat_number? Can I just index on beat_number and trust the DB to do something reasonable? Is there some other arrangement I haven't considered?

I took a look at the best practices PDF and it seems to suggest than an index for a column that isn't very selective (which is true for beat_number in my example) may not be a good idea. But my data set is too large to run a full table scans for every query, so I need some way to shrink the search space.

Options: Reply• Quote


Subject
Views
Written By
Posted
Index vs Partition vs Other? for not-very-selective column
3417
September 14, 2009 02:04PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.