Problem solve Get help with specific problems with your technologies, process and projects.

Improve query performance without adding CompanyID to OrderStatusHistory table

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?

I would research the performance improvement by changing your clustered and non clustered indexes. I would also determine if you can archive older data to limit the sheer amount of data that is queried.

Do you have comments on this Ask the Expert Q&A? Let us know.

Dig Deeper on Microsoft SQL Server Performance Monitoring and Tuning

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.