Community Tech Note
Community Tech Note
INTRODUCTION
SQL Server Performance is always one of the most challenging subject. Hard drives are
getting cheaper and cheaper and data is growing exponentially. With this new pattern we
all have an important challenge. In the database world, though, we now have a new
problem of performance. Here are few questions that keep coming up in various systems in
the industry:
1.
2.
3.
4.
5.
6.
7.
Throughout the years I have seen and solved many similar issues. I have seen many bad
practices implemented in SQL Server at the server and database level. There are hundreds of
tips that one can practice to keep a database at optimal performance.
The purpose of this document is to highlight a few best practices that can give maximum
benefits to the SQL Server system. Out of thousands of the best practices I have selected the
five best practices related to Indexes.
-1-
Lots of unused indexes are an extra burden on SQL Server. Every time any field is updated
which is referenced in the index, the index also has to be updated. Updating the index is an
additional load on the SQL Server engine. If you have an Index maintenance script, it will also
be wasting some resources on rebuilding/reorganizing indexes.
The best practice for unused indexes is to drop them. When dropping indexes, one has to be
very careful that they do not drop any index which is useful to queries by mistake. It is
recommended to evaluate this unused index script on the server after running it continuously
for a while without restarting the services or server.
Unused Index scripts are based on DMV and will return lots of results. Select the top 2-3
indexes at a time and drop them on the development server. Keep your server on watch for
a while and, if you find it appropriate, drop them on the production server too.
You can download the script from here: http://bit.ly/UnusedIndex
-2-
existing indexes; they just create the new index as per their requirement. This can lead to
multiple indexes with the same definition in the system.
There is absolutely no point to have two indexes with exactly the same structure in any
database system. This duplicate index not only takes up space on the hard drive but also
reduces the performance. All the INSERT, UPDATE and DELETE queries will have to now
update two similar sets of the data on every single occurrence. As there are duplicate
indexes, only one of the indexes is used when any query is executing, making the duplicate
index redundant.
The best practice is to drop the duplicate index and keep any database free from additional
overhead. Again, please be sure to verify that the index is indeed a duplicate before
dropping it.
You can download the script from here: http://bit.ly/DuplicateIndex
Columns which have large numbers of unique, distinct data may be good
candidates for clustered indexes.
In OLTP workload the common practice is to create clustered indexes on the
primary key as data is often looked up using the same keys. (In SQL Server
when a Primary Key is created it automatically creates the clustered index if it
does not already exist. There are some rare cases when Primary Keys are on
different columns than Clustered indexes). It is indeed good practice to have
clustered indexes on unique values (e.g. Primary Keys) as it will avoid adding
an additional unique identifier on the clustered index.
Keep the width of the Clustered Index as narrow as possible.
-3-
FINAL NOTE
Try all the queries on the development server first. Test all the changes first on the
development server and validate all the results. Deploy only after careful
consideration. Take all the advice here as a best practice but not as a strict rule.
Embarcadero Technologies, Inc. is the leading provider of software tools that empower
application developers and data management professionals to design, build, and run
applications and databases more efficiently in heterogeneous IT environments. Over 90 of
the Fortune 100 and an active community of more than three million users worldwide rely on
Embarcaderos award-winning products to optimize costs, streamline compliance, and
accelerate development and innovation. Founded in 1993, Embarcadero is headquartered
in San Francisco with offices located around the world. Embarcadero is online at
www.embarcadero.com.
-4-