Answer the question
In order to leave comments, you need to log in
Are the columns "separately" indexed, or do they need to be specified explicitly?
I add a unique index on two columns.
If there is a select/sort/etc on one of them, do I need to add a separate index for one column? In other words, are the columns indexed "separately", or does it have to be explicitly specified? ALTER TABLE `table` ADD UNIQUE (`col1`, `col2`)
Answer the question
In order to leave comments, you need to log in
Columns are not individually indexed, but conditional queries with the first of the specified columns can use a composite index.
Few examples:
Will use index
Will also use the index
The index will not be used.
And in this query, although the index will be used, but only for col1. For col2 - full view of the table.
The index will be used for WHERE, but not for ORDER BY.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question