select * from t where id=1 or id=2 or id=3 order by s desc
select * from t where id<4 order by s desc
select * from t where exists(1,2,3) order by s desc

解决方案 »

  1.   

    1.把“*”换成具体字段名2.用 exists 要比用 in 效率高3. s字段建立索引
      

  2.   

    ~~ IN 操作符优化:
        优化器把使用IN比较符的检索表达式替换为等价的使用“=”和“OR”操作符的检索表达式。
      

  3.   

    好技术库,不容错过:http://www.ciitc.com
      

  4.   

    学习,好题
    不过,用in有时也是很方便的,in是通用SQL,exists不知道是不是了!
      

  5.   

    这个题目没有意义
    如果id是主键
    实际情况下,in和exists和or的效率是一样的。
    没有必要再做任何优化。看来verycd出题的人自己对mysql也不大了解,只是道听途说
      

  6.   

                                \\\|///
                              \\  - -  //
                               (  @ @  )
    ┏━━━━━━━━━━━━oOOo-(_)-oOOo━━━━━━━━━━━━┓