select *  from  mcuhome_space use index(expert_experience) where is_expert = 1 or experience > 1000表 mcuhome_space里面有 很多字段,其中有2个字段is_expert=1表示为专家,还有。如果 is_expert=0的时候,如果experience >1000也可能是专家。
  
   我现在要查询出这个表里面所有专家,也就是is_expert=1或者是experience > 1000的数据。现在分别建立2个索引。在
(is_expert) 和(is_expert,experience )建立了2个索引。但是还是没走索引          

解决方案 »

  1.   

    create index exp_is on mcuhome_space(is_expert,experience)
    结果还是没走索引呢
    explain select *  from  mcuhome_space use index(exp_is) where is_expert = 1 or experience > 10001 SIMPLE mcuhome_space ALL exp_is 17 Using where
      

  2.   

    联合索引不行就用union 联合吧。如果 is_expert=0的时候,如果experience >1000也可能是专家,那is_expert=1是专家,是不是experience一定大于1000?是的话 那就用experience>10000的来查就好了。
      

  3.   

    explain select * from mcuhome_space where is_expert=1 union all select * from mcuhome_space where experience > 100001 PRIMARY mcuhome_space ref is_expert is_expert 1 const 1
    2 UNION mcuhome_space ALL 17 Using where
    UNION RESULT <union1,2> ALL
    这三种情况
    is_expert=1可能 experience < 10000   专家
    is_expert=0可能 experience > 10000   专家is_expert=1可能 experience > 10000   专家
      

  4.   

    贴出你的 show index 以供分析。估计你表中的大部分数据符合条件 experience > 10000
      

  5.   

    show index from mcuhome_space;mcuhome_space 0 PRIMARY 1 uid A 18 BTREE
    mcuhome_space 1 username 1 username A BTREE
    mcuhome_space 1 domain 1 domain A BTREE
    mcuhome_space 1 ip 1 ip A BTREE
    mcuhome_space 1 updatetime 1 updatetime A BTREE
    mcuhome_space 1 mood 1 mood A BTREE
    mcuhome_space 1 is_expert 1 is_expert A BTREE
    不是。里面可能会有很多会员信息。只有少部分会员。会成为专家。这个时候。我有必要把专家信息。独立出一个小表吗?还是专家和非专家。都在一个表里面
      

  6.   

    experience 上根本没有索引啊。 那肯定是要全表扫描了。