日期:2014-05-19  浏览次数:20508 次

提高数据性能的问题
select   *   from   Count   where  
charindex( 'baidu.com ',CountReferer)> 0   or     charindex( 'google ',CountReferer)> 0   or  
charindex( 'yahoo ',CountReferer)> 0   or     charindex( 'yahoo.com ',CountReferer)> 0  
or     charindex( 'sogou.com ',CountReferer)> 0   or     charindex( 'tom.com ',CountReferer)> 0
or     charindex( '163.com ',CountReferer)> 0   or     charindex( 'soso.com ',CountReferer)> 0  
or     charindex( 'iask.com ',CountReferer)> 0   or     charindex( 'msn.com ',CountReferer)> 0

---------------
这样好像要全表搜索,怎么写才能更好,谢谢!

------解决方案--------------------
好像也只能这么写了。

或者用LIKE
------解决方案--------------------
在CountReferer上建索引.

charindex( 'yahoo ',CountReferer)> 0 or charindex( 'yahoo.com ',CountReferer)> 0
这两个条件重复
------解决方案--------------------

CharIndex 和 LIke '%关键字% ' 两者效率差不多,都使用不上索引。

用全文索引试试。


------解决方案--------------------
select * from (
select * from Count where charindex( 'baidu.com ',CountReferer)> 0 union all
select * from Count where charindex( 'google ',CountReferer)> 0 union all
select * from Count where charindex( 'yahoo ',CountReferer)> 0 union all
select * from Count where charindex( 'yahoo.com ',CountReferer)> 0 union all
select * from Count where charindex( 'sogou.com ',CountReferer)> 0 union all
select * from Count where charindex( 'tom.com ',CountReferer)> 0 union all
select * from Count where charindex( '163.com ',CountReferer)> 0 union all
select * from Count where charindex( 'soso.com ',CountReferer)> 0 union all
select * from Count where charindex( 'iask.com ',CountReferer)> 0 union all
select * from Count where charindex( 'msn.com ',CountReferer)> 0 ) t
------解决方案--------------------
charindex和LIKE没有什么区别
这个查询没有救了

其实如果有这个需要,建表时应该把这个规划出来的

------解决方案--------------------
添加一个siteId字段,可以在你查询前维护其值或插入数据时。

如:
id,site
1,google.com
2,baidu.com
4,sohu.com
8,yahoo.com

查询google+baidu+yahoo的语句就是:
select * from table where siteId & (1+2+8) = siteId
位运算,速度超快~~~

------解决方案--------------------

CharIndex 和 LIke '%关键字% ' 两者效率差不多,都使用不上索引。

而 LIke '关键字% ',可以使用索引。

用全文索引试试。

------解决方案--------------------
hyc_music1981(穿裤衩的地狱天使) ( ) 信誉:100 Blog 加为好友 2007-04-17 16:11:33 得分: 0


int有三十一种,bigint有六十三种,呵呵


赞同:)