I have an SQL query that uses both standard WHERE clauses and CONTAINS text index clauses. A query is created dynamically from code and includes a variable number of WHERE and CONTAINS clauses.
For a query to be fast, it is very important that the entire text index is executed before the other criteria are applied.
However, SQL Server decides to process the WHERE clauses before the CONTAINS clauses and invokes table scans, and the query is very slow.
I can rewrite this using two queries and a temporary table. When I do this, the query is 10 times faster. But I do not want to do this in the code that creates the request, because it is too complicated.
Is there a way to get SQL Server to process CONTAINS first? I cannot force a plan (USER PLAN) because the request is built dynamically and varies greatly.
Note. I have the same problem on SQL Server 2005 and SQL Server 2008.
source share