MySQL index

dont create index on each columnci

for multicolumn index, the column order matters for B-Tree indexit

 

UNIQUE and PRIMARY KEY are constraints, not indexes. Though most databases implement these constraints by using an index. The additional overhead of the constraint in addition to the index is insignificant, especially when you count the cost of tracking down and correcting unintentional duplicates when (not if) they occur.io

Indexes are usually more effective if there you have a high selectivity. This is the ratio of number of distinct values to the total number of rows.table

For example, in a column for Social Security Number, you may have 1 million rows with 1 million distinct values. So the selectivity is 1000000/1000000 = 1.0 (although there are rare historical exceptions, SSN's are intended to be unique).select

But another column in that table, "gender" may only have two distinct values over 1 million rows. 2/1000000 = very low selectivity.exception

So create index on non-unique column may slow down the query.im

相關文章
相關標籤/搜索