hi
i got a query that takes about 14 mins
here it is
select BDProduct.ProductCode,BDProduct.ProductName,SALTer ritory.TerritoryID
,SALTerritory.TerritoryName,SALAccount.AccountID,S ALAccount.AccountName
,sum(SalesNetFact.Qty2) as Quantity
,sum(SalesNetFact.bonus) as Bonus
from SalesNetFact
inner join BDProduct
on BDProduct.ProductID=SalesNetFact.ProductID
inner join SALAccount
on SALAccount.AccountID=SalesNetFact.AccountID
and SALAccount.BranchID=SalesNetFact.branchid
inner join SALTerritory
on dbo.SALAccount.TerritoryID = dbo.SALTerritory.TerritoryID
and dbo.SALAccount.BranchID = dbo.SALTerritory.BranchID
group by BDProduct.ProductCode,BDProduct.ProductName
,SALTerritory.TerritoryID,SALTerritory.TerritoryNa me,SALAccount.AccountID
,SALAccount.AccountName
the SalesNetFact table has BranchID,TransactionLineID as primary key
the BDProduct table has ProductID as primary key
the SALAccount table has AccountID,BranchID as primary key
the SALTerritory table has TerritoryID,BranchID as primary key
i have no other indices in any of these tables
the execution plan shows that the sort step takes 96% cost,that is the
most expensive step,it is done after all the joining steps and before
the group by step
for the sort step:the estimated row count is 1552242,the arguments
are:ORDER BY [BDProduct].[ProductCode]
asc,[SALTerritory].[TerritoryID] asc,[SALTerritory].[TerritoryName]
asc,[SalesNetFact].[AccountID] asc,[SALAccount].[AccountID] asc)
any ideas about how to improve this sort step