title: Outer apply takes a long time when it contains string compare in it
body: <p>I have a query:</p>
  
  <pre><code>with cte as
  (   
  //some select statement
  )
      select -
      // also some code here
       from cte a 
       outer apply
  (select top 1 position,traffic,tags,url,Domain,Load_Date,trend_date
      from cte b 
      where b.Date_ID&lt;=a.Date_ID and 
          b.Load_Date is not null and 
          a.Domain is null and 
          a.Project_Id=b.Project_Id and
          a.SE_Id=b.SE_Id  and
          a.Keyword=b.keyword 
          order by a.Date_ID desc
          )x
  </code></pre>
  
  <p>My <code>cte</code> returns almost 3 million rows. This query takes a very long time to finish (every 4 minutes it returns only 500 rows)</p>
  
  <p>But the following query without <code>Keyword</code> compare in outer apply, is very fast:</p>
  
  <pre><code>with cte as
  (   
  //some select statement
  )
      select 
      // also some code here
       from cte a 
       outer apply
  (select top 1 position,traffic,tags,url,Domain,Load_Date,trend_date
      from cte b 
      where b.Date_ID&lt;=a.Date_ID and 
          b.Load_Date is not null and 
          a.Domain is null and 
          a.Project_Id=b.Project_Id and
          a.SE_Id=b.SE_Id  and
          order by a.Date_ID desc
          )x
  </code></pre>
  
  <p>The Problem is, that I need this Keyword comparison in my query. My question is now, How should I change my original query to have a better performance?
  good to know:</p>
  
  <ul>
  <li>Project_Id is <code>int</code></li>
  <li>SE_Id is <code>int</code></li>
  <li>Keyword is <code>nvarchar(2000)</code></li>
  </ul>