• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

SQL Server -Clustered Indexed tables

Tell me if I have the concept down on Clustered Index tables:

The actual clustered Indexes are arranged in order by index value ( physically) on a page with each having a  pointer to a leaf page where the data resides. The data rows in the leaf pages are not physically stored in the same order has the index but are stored in chained pages.
0
metro156
Asked:
metro156
  • 2
  • 2
1 Solution
 
PortletPaulCommented:
A clustered index sorts and stores the data rows of the table or view in order based on the clustered index key. The clustered index is implemented as a B-tree index structure that supports fast retrieval of the rows, based on their clustered index key values.
http://msdn.microsoft.com/en-us/library/ms175049.aspx

i.e. I don't believe your description is accurate.
(that description is more akin to a non-clustered index - see your other question)
Each index row in the nonclustered index contains the nonclustered key value and a row locator.
0
 
metro156Author Commented:
I guess what I am really getting at is the Leaf Node of the clustered index table. Say you have a leaf node page with a  index key range of 100 to 150. meaning the clustered index values range from 100 to 150. The arranged data rows in that leaf node page can be arranged like so
100
130
120
150 etc In other words the rows in the Leaf node are not necessarily physically stored in order by the index but that the leaf node page contains that range of values.
See https://www.simple-talk.com/sql/learn-sql-server/sql-server-index-basics/
what I mean by physically order by index
100
120
130
150
Forget I mentioned a pointer to the leaf node page. The process is traversing the BTree to get to a range of index values and then getting to that range on the leaf (100-150) and searching within that range.

I just read in my MCTS Exam 70-432  MS SQL Server 2008 Implementation and Maintenance book that a clustered index does not physically store the data on disk in a sorted order  because doing so creates a large amount of disk I/O for page split operations. Instead, a clustered ensures that the page chain of the index is sorted logically, allowing SQL Server to traverse directly down the page chain to locate data.
0
 
PortletPaulCommented:
ok, understand your question better now
certainly the clustered index nodes store the related data (and the index itself is sorted) - that bit you know

Is the data within a node physically sorted?  - if the clustered index design arrived at uniqueness then by inference the data would be (as result of the sorted index) - if however a clustered index didn't arrive at uniqueness - then your question arises
(and that bit I don't know I'm afraid, as I've never looked that far into it, I'm more interested in logic and less interested in the physical arrangement, others do that for me:)

There  are other experts here with that style of knowledge
0
 
DcpKingCommented:
Metro,

Here's possibly the best explanation:

Basically, a page contains rows and a row index array to tell the DBMS where each row starts in the page. If you consider that a clustered index literally keeps things in order then you might expect to find rows 7, 8, and 9 on a page, and the row index array should show 7, 8, 9 in that order. In fact while those three rows will exist in the page, and the row index array will say "7, 8, 9", it's quite possible to have the rows in any physical order within the page - the DBMS goes to the row index array to find the offset within the page of the row, so it incurs no delay no matter where the row is in the  page.

hth

Mike
0
 
metro156Author Commented:
Mike,
That makes sense. Great answer.

 Larry
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now