Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


April 1997

10 More Performance-Enhancing Ideas for SQL Server


RSS
Subscribe to Windows IT Pro | See More Performance Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Tip 9:
Don't Create Too Many Indexes

Some database administrators try to anticipate every possible sort and search combination by creating indexes on practically every column in every table. Having too many indexes impedes your system in many ways. Every time you perform an insert or delete, you have to modify the indexes and the data. When you update an indexed column, the SQL Server engine updates all affected indexes, an action that can have the added undesirable effect of causing the engine to restructure the index trees. This update operation can impede performance for all applications accessing the table and can even briefly degrade response across the entire system. You have no way of knowing whether the engine has restructured the index trees. Extra indexes also consume more disk space. Finally, when confronted with too many indexes, the optimizer may not choose the best-qualified index. Your database operation may run more slowly than if you had fewer indexes.

The best way to know whether you have too many indexes is to test your database operations with SHOWPLAN. Simulate a typical work day, remove the SHOWPLAN command from any procedures or code that you modified, and then review the output. You can quickly determine which index SQL Server is using and then remove any indexes that the engine doesn't reference often.

Sometimes you need additional indexes to handle specific, easily identifiable tasks, such as an end-of-month processing suite. In these cases, create the indexes immediately before you need them and drop them as soon as you finish. At other times, you need to run large batch update operations, which can be time-consuming if you have too many indexes to update. You can benefit from creating a stored procedure to drop some indexes, perform the operation, and then re-create the indexes. The overall time to do this can be less than if you let the batch update operation alter the extra indexes.

Tip 10:
Use the Multiple Table DELETE Option

Traditional SQL limits your delete operations to one table at a time. Transact-SQL has a multi-table delete capability that reduces the number of individual engine calls. For example, to delete rows in two tables, resources and parts, you can issue two SQL statements:

delete from resources where resource_cost > 5000
delete from parts where part_cost > 5000
Or you can use Transact-SQL's multiple table DELETE extension:
delete from resources
from parts
where resources.resource_cost = parts.part_cost
and resources.resource_cost > 5000

This approach is not portable, so you can't run your application against different databases. But if you work only with SQL Server, multi-table is a convenient shortcut. You can also use the UPDATE statement to alter several tables at one time.

A Last Word
As you experiment with these tips, change only one parameter at a time so you know which change produces which effect. And be sure you back up your database before and after each change.

For more information about these tips and other suggestions for enhancing SQL Server's performance, read my book, Microsoft SQL Server: Planning and Building a High-Performance Database.

Microsoft SQL Server : Planning and Building a High-Performance Database
Author: Robert D. Schneider
Publisher: Prentice Hall PTR
Upper Saddle River, N.J., 1997

End of Article

   Previous  1  2  3  [4]  Next  


Reader Comments
In Robert D. Schneider’s April article, “10 More Performance-Enhancing Ideas for SQL Server,” I noticed that Tip 10: Use the Multiple Table DELETE Option is at best misleading, and at worst wrong.
Tip 10 is about a delete statement that uses multiple tables. A delete statement can affect only one table at a time but can use the contents of other tables to decide which rows to delete. The article implies that one SQL statement can delete rows from multiple tables at the same time. This capability has never been possible with any major RDBMS, and in fact, is against the ANSI SQL standard.
Try the following simple code, which is the SQL presented in the article with some statements added to create the tables and populate them. Review the contents after the delete statement has completed.<br><br>

create table resources
(resource_cost money)<br>
create table parts (part_cost money)<br>
insert resources values ($1000)<br>
insert resources values ($6000)<br>
insert parts values ($1000)<br>
insert parts values ($6000)<br>
delete from resources from parts<br>
where resources.resource_cost = parts.part_cost<br>
and resources.resource_cost> $5000<br><br>

select * from resources<br>
select * from parts<br><br>

The only rows the delete statement affects are the rows in the resources table.
Schneider complicates the problem by including a join clause in the delete statement. Unless you have a true one-to-one relationship between the resources and parts table, you will delete rows only where you have a match on the cost columns. This is not the equivalent of deleting all rows from each individual table where the cost is greater than 5000.<br>
--Lawrence Rogers

Lawrence Rogers August 12, 1999


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Related Events SQL Server Unleashed EMEA

Deep Dive into Windows Server 2008 R2 presented by John Savill

The Easiest Way to Save Time and Money on E-mail and SharePoint Management

Check out our list of Free Email Newsletters!

SQL Server and Database eBooks Safeguarding Your Windows Servers

SQL Server Administration for Oracle DBAs

Taking Control: Monitoring the Windows Platform Proactively

Related SQL Server and Database Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement