title: Slow SQL query involving CONTAINS and OR
body: <p>We’re having a problem we were hoping the good folks of Stack Overflow could help us with. We’re running SQL Server 2008 R2 and are having problems with a query that takes a very long time to run on a moderate set of data , about 100000 rows. We're using CONTAINS to search through xml files and LIKE on another column to support leading wild cards.</p>
  
  <p>We’ve reproduced the problem with the following small query that takes about 35 seconds to run:</p>
  
  <pre><code>SELECT something FROM table1 
  WHERE (CONTAINS(TextColumn, '"WhatEver"') OR  
          DescriptionColumn LIKE '%WhatEver%')
  </code></pre>
  
  <p>Query plan:</p>
  
  <p><img src="https://i.imgur.com/Z1UZf.png" alt="Slow query"></p>
  
  <p>If we modify the query above to using UNION instead, the running time drops from 35 seconds to &lt; 1 seconds. We would like to avoid using this approach to solve the issue.</p>
  
  <pre><code>SELECT something FROM table1 WHERE (CONTAINS(TextColumn, '"WhatEver"') 
  UNION
  (SELECT something FROM table1 WHERE (DescriptionColumn LIKE '%WhatEver%'))
  </code></pre>
  
  <p>Query plan:</p>
  
  <p><img src="https://i.imgur.com/9rlXt.png" alt="Fast query"></p>
  
  <p>The column that we’re using CONTAINS to search through is a column with type image and consists of xml files sized anywhere from 1k to 20k in size.</p>
  
  <p>We have no good theories as to why the first query is so slow so we were hoping someone here would have something wise to say on the matter. The query plans don’t show anything out of the ordinary as far as we can tell. We've also rebuilt the indexes and statistics.</p>
  
  <p>Is there anything blatantly obvious we’re overlooking here?</p>
  
  <p>Thanks in advance for your time!</p>