Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mike13
Posting Yak Master
219 Posts |
Posted - 2013-03-20 : 06:48:11
|
Hi all,I got this search statement, but i want to optimize itSELECT DISTINCT V_Product.id, V_Product.Image, V_Product.Name, V_Product_URL_Complete.urlFROM V_Product INNER JOIN dbo.T_Product_Description ON dbo.V_product.id = dbo.T_Product_Description.ProductID INNER JOIN V_Product_URL_Complete ON V_Product.id = V_Product_URL_Complete.id WHERE (V_Product.Lang = @lang) AND (V_Product_URL_Complete.Lang = @lang) AND (V_Product_URL_Complete.lang2 = @lang) AND (NOT (V_Product.id IN (SELECT ProductID FROM T_Product_Hide WHERE Country = @country))) AND ((dbo.T_Product_Description.Name LIKE '%' + @search + '%') or (dbo.T_Product_Description.Description LIKE '%' + @search + '%'))ORDER BY V_Product.Namethanks a lot |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-03-20 : 13:38:02
|
If possible try transforming the highlighted text into a join instead of the "NOT IN"SELECT DISTINCT V_Product.id, V_Product.Image, V_Product.Name, V_Product_URL_Complete.urlFROM V_Product INNER JOINdbo.T_Product_Description ON dbo.V_product.id = dbo.T_Product_Description.ProductID INNER JOINV_Product_URL_Complete ON V_Product.id = V_Product_URL_Complete.id WHERE (V_Product.Lang = @lang) AND (V_Product_URL_Complete.Lang = @lang) AND (V_Product_URL_Complete.lang2 = @lang) AND (NOT (V_Product.id IN(SELECT ProductIDFROM T_Product_HideWHERE Country = @country)))AND ((dbo.T_Product_Description.Name LIKE '%' + @search + '%') or(dbo.T_Product_Description.Description LIKE '%' + @search + '%'))ORDER BY V_Product.NameStill, if slow, then use execution plan in order to identify the problematic areas.CheersMIK |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2013-03-21 : 05:10:08
|
So turn it into a left join on id = id and country = @country, then add to your where a is null check on the id from t_Product_Hide. See if that is any faster. |
|
|
|
|
|
|
|