select [id],[poster],[fid],[title],[editername],[modifytime] from(
select [id],[poster],[fid],[title],[editername],[modifytime], row_number() over
( order by id desc) as row from [news] WITH (NOLOCK)
where path like 'A_B%' and id not in
(select id from [news] where layer=7 or layer=5)) a
where row between 1 and 15
上面的查询很慢。如果只执行子查询就很快,但是做 where row between 1 and 15 分页就很慢很慢,原来是因为查询里面用了or,优化成下面的就不超时了
select [id],[poster],[fid],[title],[editername],[modifytime] from(
select [id],[poster],[fid],[title],[editername],[modifytime], row_number() over
( order by id desc) as row from [news] WITH (NOLOCK)
where path like 'A_B%' and id not in
(select id from [news] where layer=7 union select id from [news] where layer=5)) a
where row between 1 and 15