An index on (col1, col2, col3, col4)
can only be used, if the WHERE
clause contains a condition on the first columns. That means, if the query does not contain a condition on col1
, the index cannot be used at all (see Multiple-Column Indexes). If you have such queries, additional indices should be defined. These might be (col2, col3, col4)
, (col3, col4)
and (col4)
.
On the other hand, separate indices on (col1)
, (col2)
, (col3)
and (col4)
are also a good choice. Int that case, there is no need to include the primary key in the indices. I'd prefer this solution over the solution mentioned above.
I find your choice of primary key strange. If (col1, col2, col3, col4)
is unique, use that as a primary key. If you do not want a primary key on four columns (most people don't), the next choice is often a surrogate key (i.e. an auto_increment
column in MySQL). In that case, a unique key on (col1, col2, col3, col4)
enforces data integrity.