前面说这种方法速度没办法提升,最好开全文索引select * from table1 where col like '%str%' union all
select * from table2 where col like '%str%' union all
..............
select * from table3 where col like '%str%' 前面的帖子:如何加快like的速度http://bbs.csdn.net/topics/390608207我开了全文索引,但是下面两条语句查出的行数完全不一样select * from table1 contains(col, 'str')
select * from table1 where col like '%str%'用contains的结果只有不到10条,而like的结果有6K多。
用sp_help_fulltext_catalogs看,全文索引构建已经结束了,应该不是索引没建立的关系,
而且我把col的语言也设置成2052(汉语),也不应该是断词的问题。那是什么问题?
select * from table2 where col like '%str%' union all
..............
select * from table3 where col like '%str%' 前面的帖子:如何加快like的速度http://bbs.csdn.net/topics/390608207我开了全文索引,但是下面两条语句查出的行数完全不一样select * from table1 contains(col, 'str')
select * from table1 where col like '%str%'用contains的结果只有不到10条,而like的结果有6K多。
用sp_help_fulltext_catalogs看,全文索引构建已经结束了,应该不是索引没建立的关系,
而且我把col的语言也设置成2052(汉语),也不应该是断词的问题。那是什么问题?
如果单为这个原因再用第3方全文索引软件,太麻烦了。
另外还要试试freetext
一、我试了下str*和freetext,结果是一样差很多(与like相比)。
二、下面就我在使用SQL Server2005全文索引中遇到的问题做下小结,然后结贴。
1、表table1, table2如下
select * into table2 from table1 where ...在两表同样列上做全文索引,然后select * from table1 where contains(col, 'str')
select * from table2 where contains(col, 'str')结果竟然不一样, table1一条记录没查出来, table2返回几条记录。2、全数字的查询问题create table test (col1 nvarchar(30),...)
--col1字段存放数字字符串,全是数字,比如邮政编码
--对col1建全文索引--查一个完整的邮编,有记录
select * from test where contains(col1, '100001')--查一个地区的邮编,无结果!
select * from test where contains(col1, '100')
select * from test where contains(col1, '100*')
select * from test where freetext(col1, '100')
综上,SQL全文索引给我的印象就是不可靠,查询有结果要靠概率,而且很不灵活。当然也可能是我使用中出现了问题,不过算了,我决定不用全文索引,还是老老实实地用like吧,最多弄成异步执行。