SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Training
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
SQL Azure
Developer
General DBA
ASP.NET / ADO.NET
SQL Azure

USEFUL SITES :

ASP.NET Tutorials
Windows and SQL Azure Tutorials
Cloud Hosting Magazine
SharePoint Tutorials
Windows Server Help

Write for Us

Share your SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server

More     
 
Latest FAQ's

Add Node to A SQL Server failover Cluster failed with invalid ...
SQL Server Destination remote server error
Setting Up Data And Log Files For SQL Server
Will Check Constraints Improve Database Performance?

More     
   
Latest Software Reviews

dbForge Review
Spotlight on ApexSQL Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Data Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Doc 2008

More     

articles >> performance tuning >> Using Index Intersection to Boost SQL Server ...

Using Index Intersection to Boost SQL Server Performance

By : Neil Boyle
Feb 28, 2003

Page 2 / 2


Using Index Intersection

Index Intersection is a technique built into the SQL Server engine to enable it to use more than one index on a table to satisfy a given query. To demonstrate, we need to alter the Pubs table a little, so now would be a great time to back up the database.

Backup secured? OK, let’s proceed.

First we are going to create a cut-down version of the authors table using this script:


CREATE TABLE authors_names (
id INT IDENTITY,
au_lname VARCHAR(40),
au_fname VARCHAR(40),
filler CHAR(7000)
)

GO

INSERT authors_names (au_lname, au_fname, filler)
SELECT l.au_lname, f.au_fname, 'filler'
FROM authors l CROSS JOIN authors f

GO

ALTER TABLE authors_names ADD CONSTRAINT PK_authors_names PRIMARY KEY CLUSTERED (id)

GO

CREATE NONCLUSTERED INDEX i__au_fname ON authors_names (au_fname)

GO

CREATE NONCLUSTERED INDEX i__au_lname ON authors_names (au_lname)

GO


Note that I have takes a couple of short cuts to generate suitable test data. Apart from ignoring unnecessary columns for the test, I have used a CROSS JOIN to increase the amount of available test data. I have also added a "filler" column to use up extra space, as SQL Server will not use indexes on very small tables.

Now, if you run the three queries we used earlier against the "authors_names" table using the "Display Estimated Execution Plan" option in Query Analyzer, you should see that the all three queries use one or more indexes (remember the query against au_fname did a table scan previously).

In addition, you should see that the query that specifies both first and last names in the WHERE clause uses both the index on au_fname and the index on au_lname. This is the advantage that Index Intersection brings. It allows SQL Server to scan more than one relevant index to get the data you need, minimizing the amount of data returns and maximizing performance. Prior to SQL 7.0, this functionality was not available in SQL Server.


Points To Note

I chose to use non-clustered indexes in this example for a good reason. The optimizer will generally prefer to use a clustered index rather than an Index Intersection, so the demonstration would be less likely to work on a setup where clustered indexes are used in the query.

Whether or not a combination of single-column indexes is better than a compound index depends on the data and the queries you run against it. You should test out both cases in your database designs to see which is more efficient for your circumstances.

As with any indexed tables, it’s important to maintain the index structure and statistics regularly (or use auto-stats) to help SQL Server choose efficient indexes for each query.



<< Prev Page         








C# Help and Tutorials | PHP MySQL Tutorial | Sharepoint Tutorial | Azure Tutorial | Cloud Hosting Magazine | ASP.NET Tutorials | Windows Server Help | Windows Phone Pro | Silverlight Ace | Visual Studio Tutorials | Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | SQL Server Training Videos | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 2010 Jude O'Kelly. All rights reserved