I want to speed up the following query
There are two conditions in the WHERE clause (see below query for reference)
Currently, it takes about 60 seconds. However
Can you split this into two queries? or often causes a problem for optimizers:
if @Query is null
begin
select *
from (select row_number() over( order by b.BookTitle) as RowNumber, b.*
from Books b (nolock)
where @Query is NULL
) as t1
where t1.RowNumber between 40 and 60;
end
else
begin
select *
from (select row_number() over( order by b.BookTitle) as RowNumber, b.*
from Books b (nolock)
where contains(b.BookTitle, @Query)
) as t1
where t1.RowNumber between 40 and 60;
end