有一张很老的数据表,时间戳格式为varchar,字段如下:idbigintnamevarchar(200)create_timevarchar(200)//索引KEY`IDX_CREATED`(`create_time`),数据约500多万,现在引出发现的问题,一条sql语句效率非常的低:selectid,namefromtwherecreate_time>1434115807296orderbycreate_timelimit1000;本机测试200s,执行计划:>explainselectid,namefromtwherecreate_time>1434115807296orderbycreate_timelimit1000;+----+-------------+-------+-------+---------------+---------------+---------+------+------+-------------+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|+----+-------------+-------+-------+---------------+---------------+---------+------+------+-------------+|1|SIMPLE|User|index|IDX_CREATED|IDX_CREATED|63|NULL|1000|Usingwhere|+----+-------------+-------+-------+---------------+---------------+---------+------+------+-------------+1rowinset(0.00sec)如果去掉limit:selectid,namefromtwherecreate_time>1434115807296orderbycreate_time执行时间5s,执行计划:>explainselectid,namefromtwherecreate_time>1434115807296orderbycreate_time+----+-------------+-------+------+---------------+------+---------+------+---------+-----------------------------+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|+----+-------------+-------+------+---------------+------+---------+------+---------+-----------------------------+|1|SIMPLE|User|ALL|IDX_CREATED|NULL|NULL|NULL|4858500|Usingwhere;Usingfilesort|+----+-------------+-------+------+---------------+------+---------+------+---------+-----------------------------+1rowinset(0.00sec)一个index查询竟然比ALL&filesort查询慢这么多?请MySQL达人指教
九州编程
杨魅力
相关分类