Q

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.
This was first published in June 2005

Dig deeper on Microsoft SQL Server Performance Monitoring and Tuning

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

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.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

This Content Component encountered an error
Close