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:
- About 40 times a day, a new hierarchy will be added just off the root.
- Hierarchies will probably never be deleted.
- Hierarchies are accessed often during the day by parentId to incrementally fill combo boxes.
- Hierarchies are VERY rarely moved. Perhaps not even once a month.
- 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