Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 358419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:17:52+00:00 2026-05-12T12:17:52+00:00

Assume I have a table called table and I have 3 columns, a, b,

  • 0

Assume I have a table called “table” and I have 3 columns, a, b, and c.

What does it mean to have a non-clustered index on columns a,b?

Is a nonclustered index on columns a,b the same as a nonclustered index on columns b,a? (Note the order).

Also, Is a nonclustered index on column a the same as a nonclustered index on a,c?

I was looking at the website sqlserver performance and they had these dmv scripts where it would tell you if you had overlapping indexes and I believe it was saying that having an index on a is the same as a,b, so it is redundant. Is this true about indexes?

One last question is why is the clustered index put on the primary key. Most of the time the primary key is not queried against, so shouldn’t the clustered index be on the most queried column. I am probably missing something here like having it on the primary key speeds up joins?

Great explanations. Should I turn this into a wiki and change the title index explanation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:17:52+00:00Added an answer on May 12, 2026 at 12:17 pm

    This is turning into a more-general introduction to indexing, but I suspect you’ll still find it useful. The first two paragraphs especially speak to your question.

    Clustered vs Non-clustered

    This refers to how the table is physically arranged on disk. A clustered index works by sorting the physical pages and rows in a table on disk based on the index definition. Non-clustered indexes use a separate location on disk to store a copy of the columns in the index (and only those columns), plus a pointer to the source records. For this reason, clustered indexes are often faster because they will always cover any data you need in the query. However, you only get one of them because otherwise you’d duplicate the entire table. It’s also important to know that adding non-clustered indexes to a table actually slows down write operations like inserts and updates, because the database has to rebuild the index, or at least certain pages in the index.

    Index Order

    An index on (A,B) is not the same as on (B,A). If the first case, records in the index are ordered by column A first, and column B only effects the index order when you have duplicate values for A. Searching the index with a column B value only won’t help you, because you still have to scan through every record in the index to find all your matching values in B. In the second case, the reverse happens: records are ordered by column B first, and column A only helps when you have duplicate values for A. Searching that index with a column A value only won’t help you.

    Covering Indexes

    Sometimes a database can fulfill the requirements of a query entirely from an index. In this case, the index is said to be a "covering" index for that query. This is advantageous because indexes are often cached in memory, and so the database may not have to go do disk at all. To understand this, imagine an index on (A,B) where there are very few duplicate values for A. Including A in the index seems wasteful, unless you have a query that runs often that looks for a particular value of A and also needs B. This index will now save a lot work going back to the original table to retrieve B.

    Selectivity

    Selectivity is a value from 0 to 1 (often expressed as a percentage) that tells you how unique each value in an index is. A selectivity of 1 or 100% means there are no duplicates. A selectivity of 0 means there is only one value in the column. Generally, a higher selectivity (approaching 1) is better for indexes.

    To demonstrate this, think about what would happen with a low-selectivity index. For example, you try to speed up a query by adding an index to a bit column in a table with 10000 records. In this case (assuming uniform distribution), the selectivity is .5. You run your query, and the index returns 5000 records. But each of those records still has to go back to the original table, and since the index order doesn’t match the table order it would have to do a lot of separate look-ups into the table. Instead, it’s likely faster to just scan through the entire table start to finish to retrieve the needed data.

    Selectivity explains why you would want to cluster on the primary key. Since the clustered index tells the database how to order the table, going for anything less than 100% selectivity here means a query will have to scan the table more often. Clustering on the primary key gives you perfect selectivity. And since this primary key is often used as the record pointer in other indexes, you want to keep it as small as possible (ie, an integer identity column).

    There’s a good article on the selectivity and indexing here:
    http://www.akadia.com/services/ora_index_selectivity.html

    Sargable

    This refers to whether the database is able to use a particular filter with an index.

    As we have shown, indexes normally work by first sorting the data into a specific order, so that lookups into that index can use something efficient like a tree-based search rather than a slower linear search. Anything that can’t be effectively compared with sorted data can’t be used with an index. A good example is the LIKE operator. This is sargable:

    SELECT * FROM [Table] WHERE [Column] LIKE @Value + '%'
    

    but this is not sargable:

    SELECT * FROM [Table] WHERE [Column] LIKE '%' + @Value + '%'
    

    Some other things that can make a filter un-sargable are non-deterministic functions (and there are more of those than you think).

    Per-Column Indexes

    A common mistake I’ve seen is to have a separate index for each column in the table. For example, someone will take a table with columns (A,B,C,D) and create four separate indexes, one each for A, B, C, D, believing they have now indexed every column and so every query should be fast. In fact, this is rarely helpful for reasons I hope I’ve already explained, and will often make things worse rather than better because the database will now need to update these indexes for every change to the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 257k
  • Answers 257k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Sorry all, self-resolved... I have to remove the same name… May 13, 2026 at 10:41 am
  • Editorial Team
    Editorial Team added an answer In your example you can't have SillyBase* because SillyBase is… May 13, 2026 at 10:41 am
  • Editorial Team
    Editorial Team added an answer Trac http://trac.edgewall.org/ is my goto app for development tracking. By… May 13, 2026 at 10:41 am

Related Questions

I have a table called prices which includes the closing price of stocks that
I have a question that I'm struggling with in ADO.NET Data Services: When assembling
When designing a database, what usually determines what tables will be the primary and
I’m new to PLINQO, I’m fairly new to LINQ2SQL and I’m adding a new

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.