这么多查询条件如何建立索引?

gszxt 2010-09-03 02:42:14
product表结构大概如下:
productid(int主键),shopid(int),title(varchar),icon(varchar),price(float),status(tinyint),isIndex(tinyint),updateisIndex(datetime)categoryid(int),sortid(int),brandid(int),clickCnt(int),siteIstop(tinyint),isnews(tinyint),istop(tinyint)

正面是网站中用到的一些查询:

select top 4 shopid,productid,title,icon,price from product where status=1 and isIndex=1 order by clickCnt desc
select top 5 productid,title,price,icon from product where status=1 and shopid=1111
select top 222 * from product where userid=2323
select top 2 * from product where status=1 and isIndex=1 order by updateisIndex desc
select top 12 * from product where status=1 and siteIstop=1
select count(productid) as cnt from product where shopid=2332 and istop=1
select top 4 shopid,productid,title,price,icon from product where status=1 and isnews=2 order by productid desc
select top 10 shopid,productid,title,icon,price from product where status=1 and siteIstop=1 order by productid desc
select top 12 shopid,productid,title,icon from product where status=1 and categoryid=4 order by productid desc
select top 4 productid,shopid,title,price,icon from product where productid in(select max(productid) from product where istop=1 and status=1 group by shopid) order by productid desc
select top 4 shopid,productid,title,icon,price,clickCnt from product where status=1 order by clickCnt desc,productid desc
select top 4 shopid,productid,title,icon,price from product where status=1 and istop=1 order by productid desc
select count(shopid) as num from product where status=1 and brandid=20
select count(brandid) as num from product where status=1 and categoryid=20
select top 8 * from product where istop=1 and shopid=20 and status=1 order by productid desc
select top 2 * from product where status=1 and istop=1 and shopid=222 order by productid desc

这样的应用表中应该如何建索引好呢?
...全文
410 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gszxt 2010-09-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yutian_31 的回复:]
经常用到但重复有不是很多的字段上建立,你这个你可以在status栏位上 试下。productid 建为聚集唯一
[/Quote]
怎样看?
狼王_ 2010-09-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zsh0809 的回复:]
看一下执行计划,涉及到的最耗时table的相关栏位酌情加上索引就可以了。
[/Quote]
duanzhi1984 2010-09-04
  • 打赏
  • 举报
回复
重建下索引试试啊
「已注销」 2010-09-04
  • 打赏
  • 举报
回复
看一下执行计划,涉及到的最耗时table的相关栏位酌情加上索引就可以了。
yutian_31 2010-09-03
  • 打赏
  • 举报
回复
经常用到但重复有不是很多的字段上建立,你这个你可以在status栏位上 试下。productid 建为聚集唯一

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧