有一張很老的數(shù)據(jù)表,時(shí)間戳格式為varchar,字段如下:idbigintnamevarchar(200)create_timevarchar(200)//索引KEY`IDX_CREATED`(`create_time`),數(shù)據(jù)約500多萬,現(xiàn)在引出發(fā)現(xiàn)的問題,一條sql語句效率非常的低:selectid,namefromtwherecreate_time>1434115807296orderbycreate_timelimit1000;本機(jī)測試200s,執(zhí)行計(jì)劃:>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執(zhí)行時(shí)間5s,執(zhí)行計(jì)劃:>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)一個(gè)index查詢竟然比ALL&filesort查詢慢這么多?請MySQL達(dá)人指教
MySQL limit對效率的影響
慕勒3428872
2019-04-21 20:41:59