从mysql优化方式中选择n行

时间:2016-02-12 06:23:34

标签: mysql

我正在使用下面的查询从mysql中选择10行,但是当它搜索4000000行时,它会导致服务器负载过重。

   explain SELECT * FROM `tableA` where status = '0' and id < '9600000' order by id desc  LIMIT 10

如果我可以使用&gt;与&lt;一起然后结果集很低,查询很快,但我不知道数据值的另一面,所以我不能使用&gt;。关于下面的查询优化,但我无法使用,因为我不知道下一个没有

  explain SELECT * FROM `tableA` where status = '0' and id >'9500000'and id < '9600000' order by id desc  LIMIT 10

但9500000更改,我不知道如何预测此值以优化我的查询。 任何想法都会很棒 EXPLAIN OUTPUT

     id     select_type     table   type    possible_keys   key     key_len     ref     rows    Extra   
     1  SIMPLE  tableA range    PRIMARY     PRIMARY     4   NULL    3890786     Using where

0 个答案:

没有答案