SQL Server Performance Forum – Threads Archive
Tuning of a Query…
I HAVE QUERY AS FOLLOWS:<br /><br /> <blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">SELECT DISTINCT s.supplier_code, p.itemcode, s.Item_Code, s.Region_Code, s.Lead_Time<br />FROM PL_Supplier_Product_Relationship S, ProductHierarchy P<br />WHERE s.validconsumed = 1 <br /> AND S.Item_Code=P.ItemCode <br />AND P.TreeID IN (SELECT TreeID FROM ProdTreeName)<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br /><br />I have nonclustered index on s.validconsumed,S.Item_Code, P.ItemCode, P.TreeID columns separately. I have "TreeID FROM ProdTreeName" PK (cluster index) on TreeID column. I have update the statistice and rebuild the indexes (in ordre o make sure query engine using fresh information). But still give hash Match and Clustered Index Scan as you see from result part..<br />1.validconsumed-int<br />2.TreeID-int<br />3.Item_Code-varchar<br /><br /><br /><br />Result as follows:-<br /> <blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"> |–Hash Match(Aggregate, HASH<img src=’/community/emoticons/emotion-6.gif’ alt=’








Is this DISTINCT really needed?<br />How many rows in the base tables are involved?<br />How many rows are supposed to be returned?<br /><br />Btw, personally I would prefer an explicit JOIN instead of the WHERE thingy. But that’s not really important. [<img src=’/community/emoticons/emotion-1.gif’ alt=’

Thanks Frank..
1. yes distinct is required cos duplicate rows are there.
2. 53819 rows in base table
3. approx.. more than 5500 rows.. I have changed the query like this…
quote:SELECT DISTINCT s.supplier_code, p.itemcode, s.Item_Code, s.Region_Code, s.Lead_Time
FROM PL_Supplier_Product_Relationship S, ProductHierarchy P, ProdTreeName T
WHERE s.validconsumed = 1
AND S.Item_Code=P.ItemCode
AND P.TreeID = T.TreeID
FROM PL_Supplier_Product_Relationship S, ProductHierarchy P, ProdTreeName T
WHERE s.validconsumed = 1
AND S.Item_Code=P.ItemCode
AND P.TreeID = T.TreeID
regards
Guys I have another query.. along this previous one..
quote:UPDATE Stock
SET SUPID= A.RegCode, SupOrid=A.suppcode
FROM Stock B, Supplier A
WHERE StockId = 44 and B.ICode=A.ICode
SET SUPID= A.RegCode, SupOrid=A.suppcode
FROM Stock B, Supplier A
WHERE StockId = 44 and B.ICode=A.ICode
I have composite noncluster index on A.RegCode and A.suppcode columns and Cluster index on B.StockId.. It is showing Index scan on A.RegCode and A.suppcode columns from supplier table.
I need to make sure that is this ideal index apply or can be other better way to implement these index to be selective enough for query engine. you see I want to remove index seek rather than to index scan(it’s mean query do not using this index properly). regards…
]]>