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

  • Home
  • SEARCH
  • 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 496263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:40:11+00:00 2026-05-13T05:40:11+00:00

Does cardinality play a role in composite indexes? If so, what? I was running

  • 0

Does cardinality play a role in composite indexes? If so, what?

I was running a query that was joining on two columns and it used what I thought to be a sup-optimal index, so it’s making me rethink how I design indexes…

Let’s say we had a table that listed all of the Cities in the United States. My first instinct here is to make a clustered index on (State -> City) so that if we ever need to query all of the Cities for one State, it would probably target that index. In addition, it would be a great index for queries that specify both City and State (here we can assume that City,State is a unique pair).

I ran into a query that is essentially joining off of a table that gave a list of Special Cities. So this is a subset of the Cities table. I’m specifying the join on Special.City and Special.State, but what surprised me here is that it used the primary key index (automatically created by SQL server) of the Cities table instead of the clustered index I made. How come?

I’ve also heard that good indexes have high cardinality…

So I’m wondering if the clustered index (or another, separate index) should have been created (City -> State) (notice the difference in order) because (we assume) just City has high cardinality and is way more discriminating than State is in the first series of buckets.

It’s been my rule of thumb to always create clustered indexes on parent->child in parent-child relationships, like in Cities and States, to benefit queries that target specific children and queries that fetch all children for a given parent. Do I need to rethink something here?

Informal testing shows that an index for (City -> State) was marginally cheaper than the PK index.

  • 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-13T05:40:11+00:00Added an answer on May 13, 2026 at 5:40 am

    Some thoughts:

    • When you joined on “Special Cities”, did you ask for all columns or just City and State from “City”? That is, what it covered

    • What is the index or PK order for “Special Cities”?

    • Did you filter anywhere?

    The cardinality of the column can play a part though: see Craig Freedman’s blog entry for residual lookups. And another one.

    And it’s mentioned in BOL (can’t find it though) that it should be most selective first

    However, this falls apart where you use several layers of tables and composite keys. Example:

    • table Grandad (GrandDadID, …)
    • table Dad (GrandDadID, DadID, …)
    • table Son (GrandDadID, DadID, SonID, …)

    The PK for Son covers the FK needs for both parent tables.

    If you reverse that order for “Dad” and “Son” because DadID and SonID should be selective then GrandDadID, then you suddenly need a lot more indexes to cover queries and FK DRI.

    So: column cardinality plays a part but it’s just one factor and, er, “it depends”…

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

Sidebar

Related Questions

If I have two columns, one with very high cardinality and one with very
Does anyone know the function of the command vmware-vim-cmd vimsvc/connect (vimid). I thought that
How does SQL Server determine whether a table column has low cardinality? The reason
Does anyone know of a Mootools script that provides nested sortable but also works
I have a regex that contains a character class followed by TWO cadinality characters
Can you describe: How does term 'cardinality' differs from 'relation' in data-modeling?
In Java, the containsAll and retainAll in the AbstractCollection class explicitly state that cardinality
Does the Windows API provide a way to notify a running Delphi application in
I remember reading at one point that indexing a field with low cardinality (a
Does anyone remember the XMP tag? What was it used for and why was

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.