- 工信部備案號 滇ICP備05000110號-1
- 滇公安備案 滇53010302000111
- 增值電信業(yè)務(wù)經(jīng)營許可證 B1.B2-20181647、滇B1.B2-20190004
- 云南互聯(lián)網(wǎng)協(xié)會理事單位
- 安全聯(lián)盟認(rèn)證網(wǎng)站身份V標(biāo)記
- 域名注冊服務(wù)機(jī)構(gòu)許可:滇D3-20230001
- 代理域名注冊服務(wù)機(jī)構(gòu):新網(wǎng)數(shù)碼
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語句都會運(yùn)行的更慢,因?yàn)樾枰喙ぷ鱽肀3謹(jǐn)?shù)據(jù)和索引的一致性;第二,數(shù)據(jù)庫的磁盤占用量會更大,這將導(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í)也會產(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ù)索引一樣會影響性能。
4、監(jiān)控?zé)o效的索引
當(dāng)定義多列索引時(shí),一定要注意確定所指定的每一列是否真的有效,可以通過分析指定表上的所有SQL語句的key_len列來找到那些可能包含沒有使用到的列的索引。
售前咨詢
售后咨詢
備案咨詢
二維碼
TOP