手机看片精品高清国产日韩,色先锋资源综合网,国产哺乳奶水91在线播放,乱伦小说亚洲色图欧洲电影

MySQL索引管理優(yōu)化詳述

2018-04-21 23:48:45 798

1、整合DDL語句
      在將索引添加到MySQL表的過程中,一個(gè)很重要的問題就是DDL語句時(shí)阻塞性,把多條alter語句整合成一條SQL語句時(shí)一種簡單的優(yōu)化改進(jìn)。
例如:
alter table test add index(username);
 alter table test drop index name,add index name(last_name,first_name);
 alter table test add column laset_visit date null;
改成:
alter table test 
 add index(username),
 drop index name,
 add index name(last_name,first_name),
 add column laset_visit date null;
      該優(yōu)化能夠大幅度提升管理任務(wù)的性能。
2、去除重復(fù)索引
      重復(fù)的索引有兩個(gè)主要的影響:第一,所有DML語句都會(huì)運(yùn)行的更慢,因?yàn)樾枰喙ぷ鱽肀3謹(jǐn)?shù)據(jù)和索引的一致性;第二,數(shù)據(jù)庫的磁盤占用量會(huì)更大,這將導(dǎo)致備份和恢復(fù)的時(shí)間增加。
例如:
create table test
 (id int unsinged not null,
 first_name varchar(30) not null,
 last_name varchar(30) not null,
 joined date not null,
 primary key(id),
 index (id)
 );
      這個(gè)DDL中id列上的索引是重復(fù)的索引,需要將其移除。
      當(dāng)一個(gè)給定索引的最左邊部分被包含在其他索引中時(shí)也會(huì)產(chǎn)生重復(fù)索引。
create table test
 (id int unsinged not null,
 first_name varchar(30) not null,
 last_name varchar(30) not null,
 joined date not null,
 primary key(id),
 index name1 (last_name),
 index name2 (last_name,first_name)
 );
 name1這個(gè)索引是多余的,因?yàn)榇怂饕诘牧幸呀?jīng)被包含在索引name2的最左邊部分里面了。
3、刪除不用的索引
      除了重復(fù)索引沒有被使用到之外,還有其他索引可能也沒有被用到,這些索引和重復(fù)索引一樣會(huì)影響性能。
4、監(jiān)控?zé)o效的索引
      當(dāng)定義多列索引時(shí),一定要注意確定所指定的每一列是否真的有效,可以通過分析指定表上的所有SQL語句的key_len列來找到那些可能包含沒有使用到的列的索引。

提交成功!非常感謝您的反饋,我們會(huì)繼續(xù)努力做到更好!

這條文檔是否有幫助解決問題?

非常抱歉未能幫助到您。為了給您提供更好的服務(wù),我們很需要您進(jìn)一步的反饋信息:

在文檔使用中是否遇到以下問題: