title: SQL Server 2005 charindex performance
body: <p>I'm trying to run an update query that updates one table based on rows it finds in another table where a specific value exists anywhere in one of the remote table's column values. The query I'm using is:</p>
  
  <pre><code>update 
      c
  set
      LastStep = @StepNumber,
      LastDate = pv.Created
  from
      @Conversions c
          inner join PageViews pv on c.SessionID = pv.SessionID
  where
      c.GoalName = @GoalName AND
      pv.Created &gt; c.LastDate AND
      charindex(@MatchValue, pv.PageUrl) &gt; 0;
  </code></pre>
  
  <p>On a test database with 50,000 rows in the PageViews table, this single query is causing just over 1 million reads according to SQL profiler and is taking 1 minute and 14 seconds. Any ideas why?</p>