问题是搜索的条件复杂啊, 举个例子:当点击搜索时可能产生的语句,(注:the_id是identity,yuyan是语言):where is_del=0 and topic like @search_text order by the_id desc 搜索全部语言 或 where yuyan_id=@yuyan_id and is_del=0 and give_date between @date1 and @date2 order by give_date desc 搜索部分语言和时间 或 where yuyan_id=@yuyan_id and is_del=0 and give_date between @date1 and @date2 and topic like @search_text order by give_date desc这样我该如何建立索引呢,是建一个呢,还是建3个呢?建一个呢好像无法满足,建多个呢怕影响速度。怎么办?
order by 目的是排序
举个例子:当点击搜索时可能产生的语句,(注:the_id是identity,yuyan是语言):where is_del=0 and topic like @search_text order by the_id desc 搜索全部语言
或
where yuyan_id=@yuyan_id and is_del=0 and give_date between @date1 and @date2 order by give_date desc 搜索部分语言和时间
或
where yuyan_id=@yuyan_id and is_del=0 and give_date between @date1 and @date2 and topic like @search_text order by give_date desc这样我该如何建立索引呢,是建一个呢,还是建3个呢?建一个呢好像无法满足,建多个呢怕影响速度。怎么办?
先看看怎么建立聚集索引和非聚集索引你的问题就解决了。
通常where后的建立非聚集索引
通常order by后建立聚集索引
而一个表中只能建立一个聚集索引和多个非聚集索引。
还是先看看sql help吧!
建立 第一个索引 is_del、give_date
建立 第二个索引 yuyan_id、is_del、give_date (当然都是非聚集索引)