QUESTION POSED ON: 30 June 2005
I have inherited an application that uses SQL Server. The application essentially tracks orders for hundreds of companies.
Initially, performance on the Orders table was poor. To improve it, I added CompanyID to the Orders table, since that would be the limiting factor for all users. Now the problem revolves around an OrderStatusHistory table.
Required functionality of the application includes selecting all records from OrderStatusHistory for a particular company (although it is also limited by an Active flag). The current stored procedure for retrieving this data contains SQL similar to "SELECT OrderStatusHistory.SomeFields, Orders.OtherFields FROM OrderStatusHistory WITH (NOLOCK) INNER JOIN Orders WITH (NOLOCK) ON Orders.OrderID = OrderStatusHistory.OrderID WHERE Orders.CompanyID = @CompanyID" AND Active = 1.
How can I improve performance of this query (currently 16 seconds against 2 million records) without adding CompanyID to the OrderStatusHistory table?
|