For a Table that i'll just SELECT
rows from it,
It has 3 Columns [A, B, C]
.
I can create one of those two INDEXES
ALTER TABLE `table` ADD INDEX `A_B` (`A', `B`),ADD INDEX `B_C` (`B`, `C`);
OR
ALTER TABLE `table` ADD UNIQUE INDEX `A_B_C` (`A`, `B`, `C`),ADD INDEX `B_C` (`B`, `C`);
Both works at the same speed, and has the same result in EXPLAIN
.
How do i decide what to chose?
Normal one is 4 Columns, and Unique one is 5 Columns to prevent Duplication,
But i'll just SELECT
on the table
, So is it better to use The Normal ? Or using the Unique won't make any different?
There is a slight overhead to having more columns in an index.
However, I prefer the unique index because it also ensures uniqueness -- that is, it enforces a property about the table that you want.
Note that if you have defined the trio of columns as unique
, there is not need to have a separate index on them.
I should add that if all the conditions in your queries are equality conditions, then one unique index might suffice.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.