Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server full text query across multiple tables - why so slow?
    primarykey
    data
    text
    <p>I'm trying to understand the performance of an SQL Server 2008 full-text query I am constructing.</p> <p>The following query, using a full-text index, returns the correct results immediately:</p> <pre><code>SELECT O.ID, O.Name FROM dbo.EventOccurrence O WHERE FREETEXT(O.Name, 'query') </code></pre> <p>ie, all EventOccurrences with the word 'query' in their name. And the following query, using a full-text index from a different table, also returns straight away:</p> <pre><code>SELECT V.ID, V.Name FROM dbo.Venue V WHERE FREETEXT(V.Name, 'query') </code></pre> <p>ie. all Venues with the word 'query' in their name. But if I try to join the tables and do both full-text queries at once, it 12 seconds to return:</p> <pre><code>SELECT O.ID, O.Name FROM dbo.EventOccurrence O INNER JOIN dbo.Event E ON O.EventID = E.ID INNER JOIN dbo.Venue V ON E.VenueID = V.ID WHERE FREETEXT(E.Name, 'search') OR FREETEXT(V.Name, 'search') </code></pre> <p>Here is the execution plan: <a href="http://uploadpad.com/files/query.PNG" rel="noreferrer">http://uploadpad.com/files/query.PNG</a></p> <p><strong>UPDATE: the plan in in text form:</strong></p> <pre><code> |--Nested Loops(Left Semi Join, OUTER REFERENCES:([E].[ID], [V].[ID])) |--Hash Match(Inner Join, HASH:([E].[ID])=([O].[EventID])) | |--Hash Match(Inner Join, HASH:([V].[ID])=([E].[VenueID])) | | |--Clustered Index Scan(OBJECT:([iScene].[dbo].[Venue].[PK_Venue] AS [V])) | | |--Clustered Index Scan(OBJECT:([iScene].[dbo].[Event].[PK_Event] AS [E])) | |--Clustered Index Scan(OBJECT:([iScene].[dbo].[EventOccurrence].[PK_EventOccurrence] AS [O])) |--Concatenation |--Table-valued function |--Table-valued function </code></pre> <p>From my reading, I didn't think it was even possible to make a free text query across multiple tables in this way, so I'm not sure I am understanding this correctly.</p> <p>Note that if I remove the WHERE clause from this last query then it returns all results within a second, so it's definitely the full-text that is causing the issue here.</p> <p>Can someone explain (i) why this is so slow and (ii) if this is even supported / if I am even understanding this correctly.</p> <p>Thanks in advance for your help.</p>
    singulars
    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