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 北京市 北京
这条语句查询需要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 北京市 北京
explain select count(*) from tarea where '13211916191' between Fgsmno_begin and Fgsmno_end and locate('杭州', Fcity_name) > 0;以供大家进行分析优化。
'截至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#结帖
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
这样的,似乎用不上字段上的索引,
最好改成Fgsmno_begin>='13211916191' and Fgsmno_end<='13211916191'
这两个字段都得创建索引。另外,可以如楼上, 可以看看查询计划之类的。
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毫秒左右,感觉还是慢