数据库表结构
id(int) name(varchar 50) state(int)id为自增,name为32位字符串,state为int,值的范围为0 1 2 3 该表大量数据的state为0现在需要频繁查询state不为0的数据where state<>0 and name="ABCDEFRG....."请问这种情况下,如何优化查询速度?
另 对mysql版本有没有最低要求?
谢谢

解决方案 »

  1.   

    create index xxx on 数据库表(name)
      

  2.   

    其实你是想过滤掉state为0的数据,现在你的state状态确定,那就要看你的数据量大不大了,如果大的话你可以直接根据你的state进行分区。这样查询就快了。又因为你的state不是唯一的,无法建索引。
      

  3.   


    如果state的状态 后续会从非0 update成0,对性能有影响吗?
      

  4.   

    在where后查询字段重复率比较高时候最好不要创建索引的。
      

  5.   

    engine=memory
    在MySQL中超频繁最好这样,如果能保证连接不会断开,最好是 temporary table engine=memory
      

  6.   

    where state<>0 and name="ABCDEFRG....."
    ==>
    where state>0 and name="ABCDEFRG....."索引照常用.
      

  7.   

    create index idx_na on t (name);