又很多 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 的情况这两个字段要建立索引马??
另外 试图上面 怎么建立索引啊?
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 的情况这两个字段要建立索引马??
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上检索引