General index and unique index, how to choose

/ * 

 1. innodb the size of each data page default is 16KB 
2. For the general index, it found to meet the conditions in the query on the first day of recording when you need to find the next record, until he came first k = 5 does not meet the conditions of the recording 
will stop inquiries 3. for a unique index is defined as unique, so the first record found to meet the conditions of 
the general index and unique index performance difference is minimal 
change buffer 
in memory there mysql data cache that page, if at the time of the update, the disk contents changed, but the data has not changed back to memory data inconsistency, this time you need to change buffer, innodb will update these cached in the change buffer, the next If you need to access the data page, the data page is read into memory and then perform the operation on this change buffer data pages, eventually writes data to disk. 

This change buffer operations to the original data pages, get the new process is called merge 

so under what circumstances you can use change buffer? 
The only index; for the unique index, all the update operations more will first determine whether the operation violates a unique constraint, for example, to insert a (4,400) need to judge for themselves whether there is k = 4 this record in the table, and is a must to read data pages into memory to judgment. If you have already read into memory, and, directly update the memory that will be faster, there is no need to use change buffer, 
and therefore can not be updated using a unique index change buffer, in fact, only the general index can be used
change buffer using a buffer pool in memory, and therefore can not be increased infinitely. change buffer size may be dynamically set by the parameter innodb_change_buffer_max_size. When this parameter is set to 50 to indicate the size of the change buffer occupancy of a maximum of 50% buffer pool of. 

The first case: the updated target records in memory, and an update on how the operation is performed in the innodb, a new data (4,500) 
unique: find the positions 3 and 5 of the judgment there is no conflict, if no data is inserted. 
General: Found positions 3 and 5, and insert the data 
difference between them is more than a judge, this difference is very small for the cpu is 

the second case: the record to be updated target data page in memory is not 
unique: first target data page read into memory, it is determined whether the target conflict, again written to 
ordinary: the update operations recorded in the change buffer, the execution ends 
change buffer reduces random access to the disk, so the updated performance or significant 


change buffer applications scene 

by the above we know that change buffer to accelerate the process of update operations, and is limited to the general index, but not for a unique index. 

Problem: All scenarios are applicable to ordinary index change buffer it? 
change buffer is to update our operations on a data page recorded in a data page so the more (that is, the more the number of updates) make changes before the merge, change buffer recording, the greater the benefits 
so for Write Once Read less business, the page is accessed immediately finish the probability is small, this time the best use change buffer
This common business there, billing, logs, etc. 

On the other hand, if a business finished soon make inquiries, even if the condition is satisfied, the first update record in change buffer, but immediately accessible, would immediately trigger the merge process, so random access IO It does not reduce the number of times, but also increase maintenance costs change buffer, so this change buffer business use but will be counterproductive. 



So the general index and how to choose a unique index in the end 
we know that in terms of their inquiry is no difference, mainly on account of the performance of the above update. So try to choose the general index 

if query operation immediately after the update, change buffer should be closed, while in other cases the change buffer can have a significant performance boost 
how open and close change buffer it? 
You can control whether to enable the change buffer via the parameter innodb_change_buffering. 
--all: default. Open inserts Buffer, delete-marking the Operations, Purges 
--none: Buffer is not open Change 
--inserts Dump: just open the buffer insert operation 
--deletes: just open the delete-marking operation 
--changes: open buffer insert operation and delete-marking operation 
--purges: open buffer function of the physical delete operation only in the background of 


why the change buffer capable of supporting data persistence it?
change buffer operation will be recorded in the redo log If the server is shut down unexpectedly, the redo log files in the log also records
 
write redo log that is mainly used to save random IO into the disk consumption (converted to sequential write)
And this is the change buffer to save disk random read IO consumption 


* /

 

Guess you like

Origin www.cnblogs.com/LF-place/p/11537514.html