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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:30:32+00:00 2026-05-23T14:30:32+00:00

I am using a nested set to represent a hierarchy in my application, and

  • 0

I am using a nested set to represent a hierarchy in my application, and am wondering where the best place to put indexes (clustered or otherwise) is. I am using Microsoft SQL Server 2008.

Operations:

  1. About 40 times a day, a new hierarchy will be added just off the root.
  2. Hierarchies will probably never be deleted.
  3. Hierarchies are accessed often during the day by parentId to incrementally fill combo boxes.
  4. Hierarchies are VERY rarely moved. Perhaps not even once a month.
  5. Biggest access is via left and right when linking with other tables. This is by far the most frequent access against the hierarchy.

I toyed with putting a clustered index on left and right (as the majority of the time, it will be queried with a val BETWEEN @left AND @right. But is clustering on left and right the correct way to go about it?

Many thanks in advance to anyone with more experience of SQL indexes than I!

Schema as it stands

_id       INT IDENTITY NOT NULL
_idParent INT IDENTITY NULL
_name     NVARCHAR(64)
_left     INT NOT NULL
_right    INT NOT NULL
  • 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-23T14:30:32+00:00Added an answer on May 23, 2026 at 2:30 pm

    Your best bet is to test various index configurations and just see which works best. At first glance though, clustered on lft and rgt seems like it would be best. It sounds like there isn’t much DML on the table, so it shouldn’t have to rearrange the data very often and the clustered index on lft and rgt should turn most of your queries into clustered index scans/seeks.

    The only downside that I see is that if you’re putting hierarchies right below the root then it might involve moving a lot of other hierarchies as well. Will you always be adding onto the “right” side of the root? That would only involve updating the rgt column in the root row, which would be good. If you add into the middle of the left side of the root then you’ll have to shift over all other hierarchies to the right of the new one. Also, how large is your table? That will have some affect on things. If it’s small enough then shifting those hierarchies might not be a big deal anyway. You definitely want to try to insert onto the right side of the root if you can though.

    EDIT: One other thing… have you looked into the SQL Server built-in hierarchyid data type?

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

Sidebar

Related Questions

I am using the nested set model to store a large hierarchy of data
I'm using a nested set in a MySQL table to describe a hierarchy of
I am using Spring Forms for my web application. For nested properties, the form
I'm using the nested set model that'll later be used to build a sitemap
I'm using nested set model for my menu tree, and I'm trying to get
My model is implemented using Doctrine's Nested Set behaviour. It's a simple hierarchical model
What are the pros and cons of using nested public C++ classes and enumerations?
It is often useful to implement algorithms using nested array operations. For example, to
I am using some nested layouts in Ruby on Rails, and in one of
Right now I am using this to export a repeater (with multiple nested repeaters)

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.