hi
i got a query that takes about 14 mins
here it is
select BDProduct.Produ ctCode,BDProduc t.ProductName,S ALTerritory.Ter ritoryID
,SALTerritory.T erritoryName,SA LAccount.Accoun tID,SALAccount. AccountName
,sum(SalesNetFa ct.Qty2) as Quantity
,sum(SalesNetFa ct.bonus) as Bonus
from SalesNetFact
inner join BDProduct
on BDProduct.Produ ctID=SalesNetFa ct.ProductID
inner join SALAccount
on SALAccount.Acco untID=SalesNetF act.AccountID
and SALAccount.Bran chID=SalesNetFa ct.branchid
inner join SALTerritory
on dbo.SALAccount. TerritoryID = dbo.SALTerritor y.TerritoryID
and dbo.SALAccount. BranchID = dbo.SALTerritor y.BranchID
group by BDProduct.Produ ctCode,BDProduc t.ProductName
,SALTerritory.T erritoryID,SALT erritory.Territ oryName,SALAcco unt.AccountID
,SALAccount.Acc ountName
the SalesNetFact table has BranchID,Transa ctionLineID as primary key
the BDProduct table has ProductID as primary key
the SALAccount table has AccountID,Branc hID as primary key
the SALTerritory table has TerritoryID,Bra nchID 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