Solved

SQL Server -Clustered Indexed tables

Posted on 2013-06-13
5
330 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

932 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

12 Experts available now in Live!

Get 1:1 Help Now