title: Sql serve Full Text Search with Containstable is very slow when Used in JOIN!
body: <p>I am using sql 2008 full text search and I am having serious issues with performance depending on how I use Contains or ContainsTable. </p>
  
  <p>Here are sample: (table one has about 5000 records and there is a covered index on table1 which has all the fields in the where clause. I tried to simplify the statements so forgive me if there is syntax issues.)</p>
  
  <p><strong>Scenario 1:</strong></p>
  
  <pre><code>select * from table1 as t1
  where t1.field1=90
  and   t1.field2='something'
  and   Exists(select top 1 * from containstable(table1,*, 'something') as t2 
  where t2.[key]=t1.id)
  </code></pre>
  
  <p>results: 10 second (very slow)</p>
  
  <p><strong>Scenario 2:</strong></p>
  
  <pre><code>select * from table1 as t1
  join containstable(table1,*, 'something') as t2 on t2.[key] = t1.id
  where t1.field1=90
  and   t1.field2='something'
  </code></pre>
  
  <p>results: 10 second (very slow)</p>
  
  <p><strong>Scenario 3:</strong></p>
  
  <pre><code>Declare @tbl Table(id uniqueidentifier primary key)
  insert into @tbl select {key] from containstable(table1,*, 'something')
  
  select * from table1 as t1
  where t1.field1=90
  and   t1.field2='something'
  and  Exists(select id from @tbl as tbl where id=req1.id)
  </code></pre>
  
  <p>results: fraction of a second (super fast)</p>
  
  <p>Bottom line, it seems if I use Containstable in any kind of join or where clause condition of a select statement that also has other conditions, the performance is really bad. In addition if you look at profiler, the number of reads from the database goes to the roof. But if I first do the full text search and put results in a table variable and use that variable everything goes super fast. The number of reads are also much lower. It seems in "bad" scenarios, somehow it gets stuck in a loop which causes it to read many times from teh database but of course I don't understant why.</p>
  
  <p>Now the question is first of all whyis that happening? and question two is that how scalable table variables are? what if it results to 10s of thousands of records? is it still going to be fast.</p>
  
  <p>Any ideas?
  Thanks</p>