当前位置:网站首页>What is the difference between a database unique index and a common index?

What is the difference between a database unique index and a common index?

2022-06-11 02:57:00 ambition_ forever

1、 If the business field to update Frequent normalization , Choose a unique index or a normal index ?

      If the uniqueness can be guaranteed in the business, try to use the common index instead of the unique index .

2、 For the query, the query of the general index is after the qualified content is found , Continue to the next content query , If the next item does not match, return ; But the only index query is to return the content that meets the conditions directly , On the whole, there is less than one query , But the overall efficiency is not much different .

3、 For the update operation, there is a big gap between the two .

      To understand the gap between the two in the update operation, first understand change buffer.

      change buffer Used to record update operations , When the data to be updated is not read from the hard disk to the memory , The update operation will be recorded to change buffer in , At the next time select And then read the data before the update into the memory , And then execute change  buffer To merge data , This process is called merge.

      If it is the update of the unique index , First, it is necessary to determine whether the updated data exists in the database , At this time, there must be a read operation , With the read operation, the hard disk data will be loaded into the memory . In this case, for the update of the unique index change buffer It doesn't make much sense .

      If the update of the general index , Will take advantage of change buffer To reduce the update time IO operation , Improve efficiency .

      If the read is greater than the write or update operation , There is little difference between choosing a normal index and a unique index . If reading is less than writing , Using a normal index is more efficient , Because it will use change buffer. If you want to query immediately after writing , The efficiency of ordinary indexes is not very good , Because it will involve frequent merge operation , And you need extra space .
 

      

    

原网站

版权声明
本文为[ambition_ forever]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110232211536.html