Notes on adding indexes to mysql large tables

LINXU top command:
http://www.cnblogs.com/ggjucheng/archive/2012/01/08/2316399.html
My table records 8674132, the table size is about 2G;
add primary index
ALTER TABLE USER ADD PRIMARY KEY (ID) ;
Add a common index
ALTER TABLE USER ADD INDEX (NAME ) ;
When adding an index, make sure there is enough memory. In my opinion, the memory needs 3G and the disk needs 4G. This is only a conservative estimate.
Sometimes mysql will process when adding an index In the sleep state, we cannot get enough CPU time slices.
We can adjust the finite level of
renice of the mysql process -20 15134
-20 is the nice value, 15134 is the pid, and the priority PR of the process cannot be adjusted by us. You can change the
PR through nice ( new) = PR (old) + nice
The following is the usage of adding ordinary index memory


. It is about 2.8G


at the beginning. It is stable and there is less than 800M
. The disk usage is:



18G is


stable at the beginning, and there is 14G
. Test:
before the index is built :
SELECT * FROM USER WHERE NAME LIKE 'West Bank Village Dacha%'
took 17.683s
after the index was built:
Time consuming 0.010s
SELECT * FROM USER WHERE NAME LIKE '% Xi'an Village Dacha%'
takes 20.128s
From the above, we can know that the matching of strings starting with % does not apply to the index; in addition, for varchar indexing, the null string can The index is used, so it generally does not affect the efficiency and performance. On the contrary, the index on oracle does not contain null values, so if you check the null data, the index will not be used and will be affected.


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326775315&siteId=291194637