select pubdate from products where lang='cn' GROUP BY pubdate order by pubdate desc LIMIT 7

解决方案 »

  1.   

    加lang和pubdate 这两个字段的联合索引
      

  2.   

    select count(id) from products where lang='en' order by id desc limit 1
      

  3.   

    create index xxx on products (lang,pubdate);
      

  4.   

    从查询计划看:并没有使用索引,因为索引的列pubdate并没有条件啊!!!
      

  5.   

    建立联合索引
    create index idx_a on products(lang,pubdate);
      

  6.   

    1. 你条件 lang='cn' 没有索引。 所以,这个条件会出现全表扫描。
    2. 因为你有group by 字段是 pubdate。 所以,大家建议你建立联合索引;这样会比较合理。