又很多 order by publishTime Desc(一个日期时间字段) 的 情况请问这张表 的 publishTime 要建立索引马?  publishTIme 指这条记录插入的时间
另外 试图上面 怎么建立索引啊?
CREATE View ShopsList
AS SELECT ShopInfo.Id,ShopInfo.[Name],ShopInfo.ClickTimes,ShopInfo.[Type],
   (SELECT Count(ShopId) FROM ShopComment WHERE ShopId=ShopInfo.Id) AS CommentNumber,
    (SELECT AVG(Environment) FROM ShopComment WHERE ShopId=ShopInfo.Id) AS Environment
 FROM   ShopInfo 有order by CommentNumber 还有 Environment 的情况这两个字段要建立索引马??

解决方案 »

  1.   

    是否建索引有好些因素要考虑,一是尽量让索引有效,二是索引也是有代价的,并非越多越好首先假设下面提到的语句都是经常使用的查询(使用频率不高的话基本上是不考虑的)
    select * from table1 order by publishTime Desc,如果经常是不带where条件的查询,或者经常以publishTime为where条件,又或者select top 100 * form table1  order by publishTime Desc,则有必要在publishTime上建索引SELECT ShopInfo.Id,ShopInfo.[Name],ShopInfo.ClickTimes,ShopInfo.[Type],
       (SELECT Count(ShopId) FROM ShopComment WHERE ShopId=ShopInfo.Id) AS CommentNumber,
        (SELECT AVG(Environment) FROM ShopComment WHERE ShopId=ShopInfo.Id) AS Environment
     FROM   ShopInfo 这个应该在ShopComment的ShopId上检索引