Home  >  Article  >  Database  >  mysql添加索引迅速提升查询速度_MySQL

mysql添加索引迅速提升查询速度_MySQL

WBOY
WBOYOriginal
2016-05-31 08:48:25906browse

每个人都知道,大量数据查询时,提高性能显得尤为重要,性能提高方式有很多种,如,查询时尽可能避免采用*,in等语法。

对mysql数据表中的数据字段添加索引,提升查询速度是显而易见的。下面以实际列子来操控


未添加索引,同样的查询条件,花费的时间是0.0214行       

    显示行 0 - 11 ( 12 总计, 查询花费 0.0214 秒)
            SELECT *
            FROM `noc_pro_contest`
            WHERE `npc_name` LIKE "%动画制作%"
            LIMIT 0 , 30
           

添加索引后

ALTERTABLE `noc_pro_contest` ADDINDEX ( `npc_name` ) 

查询时间瞬间下降到0.0006秒,性能上升的空间显而易见
            
            显示行 0 - 11 ( 12 总计, 查询花费 0.0006 秒)
            SELECT *
            FROM `noc_pro_contest`
            WHERE `npc_name` LIKE "%动画制作%"
            LIMIT 0 , 30


索引的缺点是,增、删、改性能下降,执行时,需要对整表进行索引重排;索引同时也会更快使得数据库文件达到最大尺寸。慎用索引,才是解决之道

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn