Solved

SQL Server -Clustered Indexed tables

Posted on 2013-06-13
5
327 Views
Last Modified: 2013-06-13
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
Comment
Question by:metro156
  • 2
  • 2
5 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39246401
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
 

Author Comment

by:metro156
ID: 39246414
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
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39246438
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
 
LVL 16

Accepted Solution

by:
DcpKing earned 500 total points
ID: 39246509
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
 

Author Closing Comment

by:metro156
ID: 39246586
Mike,
That makes sense. Great answer.

 Larry
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now