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 3424570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:29:24+00:00 2026-05-18T06:29:24+00:00

I have a question concerning best-practices for indexing in SQL Server (or any RDBMS

  • 0

I have a question concerning best-practices for indexing in SQL Server (or any RDBMS for that matter). Take the following table:

ProfileID int
Text      nvarchar(50)

ProfileID is joined to a Profile table. For each profile, each Text must be unique. Therefore I put a Primary cover key on both columns. Fine.

However, I also want to be able to query the above table by ProfileID. So I also put an index on ProfileID too.

This means I have an overlapping index. I don’t know if this is a total waste since there is a cover index already, or if it’s correct since the cover index would be a hash of the two columns (or am I misunderstanding cover indexes)?

Edit:

I created the index in the order (ProfileID, Text). What if, for argument’s sake, there were 3 columns A, B, and C, that had a cover index over all 3. Would it only benefit if we queried against “A” or “A, B, and C”, but not “B”, or “C”, or “B and C”?

  • 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-18T06:29:25+00:00Added an answer on May 18, 2026 at 6:29 am

    An index on (ProfileID, Text) (in this order) is an index on ProfileID as well.

    You may still want to create an additional index on ProfileID only, if you want greater SELECT performance on queries that do not involve Text.

    However, this has two drawbacks:

    1. Maintaining two indexes requires more resources and performance of DML queries (INSERT, UPDATE, DELETE) may suffer

    2. If you mix queries of the two types, both indexes will occupy the cache and there can be more cache misses than with a single index.

      It is not a problem if your table is small enough to fit into the cache along with both indexes.

    The cover index would be a hash of the two columns (or am I misunderstanding cover indexes)?

    A truly covering index would be created this way:

    CREATE INDEX ix_mytable_profile__text ON mytable (ProfileID) INCLUDE (Text)
    

    This way, Text would only be stored in leaf-level nodes of the index.

    However, since you need a UNIQUE index, both columns need to be parts of the key. The nodes are sorted lexicographically on ProfileID then Text.

    I created the index in the order (ProfileID, Text). What if, for argument’s sake, there were 3 columns A, B, and C, that had a cover index over all 3. Would it only benefit if we queried against "A" or "A, B, and C", but not "B", or "C", or "B and C"?

    CREATE INDEX ix_mytable_a_b_c ON mytable (a, b, c)
    
    SELECT  a, b, с
    FROM    mytable
    WHERE   a = 1 
    
    -- Index lookup, no table lookup. a is leading
    
    SELECT  a, b, с
    FROM    mytable
    WHERE   a = 1
            AND b = 1
    
    -- Index lookup, no table lookup. (a, b) are leading.
    
    SELECT  a, b, с
    FROM    mytable
    WHERE   b = 1
    
    -- Index full scan (`b` is not leading), no table lookup
    
    SELECT  a, b, с
    FROM    mytable
    WHERE   c = 1
    
    -- Index full scan (`c` is not leading), no table lookup
    
    SELECT  a, b, с, d
    FROM    mytable
    WHERE   a = 1
    
    -- Index lookup, table tookup (d is not a part of the index).
    
    SELECT  a, b, с, d
    FROM    mytable
    WHERE   b = 1
    
    -- Table full scan (there is no point in using index at all, neither for lookup nor for covering).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for information concerning the following: What are the best practices for
I have a question concerning the performance, reliability, and best practice method of using
I have question concerning a function I created. I would like to show the
I have a question concerning active record association, referring to this part of the
I have a question concerning subtypes of built-in types and their constructors. I want
I have a question concerning Core Data and how, if at all, Entities get
I have a question concerning number conversion i JS. I have a number like
I have a simple question concerning Javascript. I am trying to print in a
I have a strange question concerning subroutines: As I'm creating a minimal language and
I have a really basic question concerning unix timestamp and mysql date. I'm trying

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.