2015-11-02 63 views
1
select top 10 productName 
from Products 
where productDetails like '%something%' 
group by productName 
order by productName asc 

我該怎麼做/改變我的查詢以提高性能SQL LINQ executequery工作緩慢。我如何提高性能?

+0

使用'LIKE'%something%''確保SQL Server不能使用任何類型的索引 - 這就是在查詢中查殺性能的原因!避免這樣做以提高您的搜索速度 –

+0

Ty爲您的答案。 –

回答

2

使用子句查詢<column> like '%<anything>'將導致表掃描檢查每一行以查看它是否與子句匹配。根據您選擇的RDBMS和您的確切要求,您可以查看全文索引,或者如果您的查詢可以重寫爲<column> like '<something>%',那麼查詢將能夠使用該列上的索引。

+0

Ty爲答案和信息。 –