資料庫調優教程(七)索引的代價,調優代價

來源:互聯網
上載者:User

資料庫調優教程(七)索引的代價,調優代價
三、           索引

4.      索引的代價

前面幾講介紹了索引在提高效能方面的威力以及如何使用索引,但是索引也是有開銷的

1)    佔用磁碟空間

如前面所述,索引是有開銷的,表現在添加索引後.ibd檔案(innodb引擎)或者.myi檔案(myisam引擎)會變大。


2)    導致dml操作速度變慢

添加索引後之所以會快,是因為表依據索引對資料按某種演算法(二叉樹等)進行排序,所以刪除、增加、插入後二叉樹要重新排序,導致執行效率降低。

 

此時要看自己的資料庫是dml語句執行的多還是dql語句執行的多

使用以下語句可以查詢

 

查詢一共執行了多少次select

show  status like ‘com_select’

查詢一共執行了多少次insert

show status like ‘com_insert’

以此類推

 

一般來說,dql語句操作比dml語句要多得多!接近9:1

 

既然索引有利有弊,那麼怎樣人為地控制索引的使用呢?

強制不使用索引

select xxx from table ignore index(index_xxx)

強制使用索引

select * from table force index(index_xxx)


本講結束,下一講來講一下如何正確地使用索引。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.