We have the following code:
select * from View1 where (Timestamp >= @x) and (SomeCode like 'ABC%')
It runs terribly slow. But the code
select * from View1 where (Timestamp >= @x) (*)
runs pretty fast. Also SomeCode like...
filter runs pretty fast on the previous (*) code. So, it's fast when two-phased. (View1
is a CLR computed view.)
Question: how to advice SQL Server 2008 R2 to make the query (more precisely, the two filters) in two phases, that is, first the Timestamp
filter and then the SomeCode
filter.
Note: Nesting the queries doesn't work for us, it's slow as well.