select count(*)  from tarea where '13211916191' between Fgsmno_begin and Fgsmno_end and locate('杭州', Fcity_name) > 0;
这条语句查询需要500-600毫秒左右说明:
Fgsmno_begin(char):手机号码段开始 如:13161000000
Fgsmno_end(char):手机号码短结束 如:13161009999
Fcity_name(varchar):城市名称表数据有14万,表结构 
Fid Farea_type Fgsmno_type Fgsmno_begin Fgsmno_end Fstation Fcity_code Fvalid_flag Fmodify_time Fvalie_time Fexpire_time Fmobile_type Fcity_name Fprovince 
1 2 2 13161000000 13161009999 bjunicom 10 Y 2010-04-20 12:39:30 2002-04-12 22:05:23 2032-06-05 17:11:54 0 北京市 北京 

解决方案 »

  1.   

    你是否创建了相关的索引。比如你至少需要一个 Fgsmno_begin 的索引。给出你的show index from tarea;
    explain select count(*)  from tarea where '13211916191' between Fgsmno_begin and Fgsmno_end and locate('杭州', Fcity_name) > 0;以供大家进行分析优化。
      

  2.   

    jwjw233233 (jwjw233233)
      '截至2010-12-30 09:48:23  用户结帖率0.00% 当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖
      

  3.   

    explain select count(*) from tarea where '13211916191' between Fgsmno_begin and Fgsmno_end and query result
    id select_type table type possible_keys key key_len ref rows Extra 
    1 SIMPLE tarea ALL index_tarea,NewIndex1 (NULL) (NULL) (NULL) 146808 Using where 
      

  4.   

    '13211916191' between Fgsmno_begin and Fgsmno_end, 
    这样的,似乎用不上字段上的索引,
    最好改成Fgsmno_begin>='13211916191' and Fgsmno_end<='13211916191'
    这两个字段都得创建索引。另外,可以如楼上, 可以看看查询计划之类的。
      

  5.   

    觉得查询慢,先EXLPAIN查看一下执行计划。没有用到索引的就添加索引或者修改SQL语句。
      

  6.   

    现在 我建立了 Fgsmno_begin,Fgsmno_end,Fcity_name 这样一个索引
    explain select count(*) from tarea where '13211916191' between Fgsmno_begin and Fgsmno_end and locate('杭州', Fcity_name) > 0;query result
    id select_type table type possible_keys key key_len ref rows Extra 
    1 SIMPLE tarea range index_tarea,NewIndex1 NewIndex1 36 (NULL) 18775 Using where; Using index 查询速度有一点提高 200多,100多,300多毫秒的都有,一般在280毫秒左右,感觉还是慢