mysql - Best way to index a table with a unique multi-column? -
i creating table store around 100million rows in mysql 5.6 using innodb storage engine. table have foreign key link table around 5 million rows.
current table structure:
`pid`: [foreign key table] `price`: [decimal(9,2)] `date`: [date field] and every pid should have 1 record date
what best way create indexes on table?
option #1: create primary index on 2 fields pid , date
option #2: add column id auto_increment , primary index , create unique index on column pid , date
or other option?
only select query using on table is:
select pid,price,date table pid = 123
based on said (100m; query is...; innodb; etc):
primary key(pid, date); and no other indexes
some notes:
- since innodb, rest of fields "clustered" pk, lookup pid acts if
pricepart of pk.where pid=123 order dateefficient. - no need index(pid, date, price)
- adding
auto_incrementgains nothing (except hint of ordering). if needed ordering, index startingdatemight best. - extra indexes slow down inserts.
uniqueones.
Comments
Post a Comment