Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do SQL FullText queries slow down when you OR?
    primarykey
    data
    text
    <p>In SQL Server (2008), I have a FullText index on two columns, call them <code>Table1.FirstNames</code> and <code>Table2.LastNames</code>. After profiling some queries, I came up with the following results:</p> <pre><code>SELECT * FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey) WHERE CONTAINS(FirstNames, 'Bob') OR CONTAINS(LastNames, 'Bob') </code></pre> <p>=> 31 197ms</p> <pre><code>SELECT * FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey) WHERE (FirstNames LIKE '%Bob%') OR CONTAINS(LastNames, 'Bob') </code></pre> <p>=> 1941ms</p> <pre><code>SELECT * FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey) WHERE CONTAINS(FirstNames, 'Bob') OR LastNames LIKE '%Bob%' </code></pre> <p>=> 3201ms</p> <pre><code>SELECT * FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey) WHERE CONTAINS(FirstNames, 'Bob') </code></pre> <p>=> 565ms</p> <pre><code>SELECT * FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey) WHERE FirstNames LIKE '%Bob%' </code></pre> <p>=> 670ms</p> <pre><code>SELECT * FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey) WHERE CONTAINS(LastNames, 'Bob') </code></pre> <p>=> 17ms</p> <pre><code>SELECT * FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey) WHERE LastNames LIKE '%Bob%' </code></pre> <p>=> 3ms</p> <p>This behaviour persists even if I rebuild the FullText index.</p> <p>FullText is usually much faster than a LIKE query over large sets of data in a specific language, but why do query speeds slow down by an order of magnitude when I OR together two FullText clasues?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload