The Product table has 700K records in it. The query:
SELECT TOP 1 ID,
Name
FROM Product
WHERE contains(Name, \'\"White Dress\"\')
ORDER BY DateMadeN
Looks like FullTextMatch has over 400K executions. Why is this happening?
Since you have an index combined with TOP 1
, optimizer thinks that it will be better to traverse the index, checking each record for the entry.
How can it be made faster?
If updating the statistics does not help, try adding a hint to your query:
SELECT TOP 1 *
FROM product pt
WHERE CONTAINS(name, '"test1"')
ORDER BY
datemadenew DESC
OPTION (HASH JOIN)
This will force the engine to use a HASH JOIN
algorithm to join your table and the output of the fulltext query.
Fulltext query is regarded as a remote source returning the set of values indexed by KEY INDEX
provided in the FULLTEXT INDEX
definition.
Update:
If your ORM
uses parametrized queries, you can create a plan guide.
ORM
sends verbatimSSMS
using hints and save it as XML
sp_create_plan_guide
with an OPTION USE PLAN
to force the optimizer always use this plan.