Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Clustered Indexes


Clustered Indexes

Author
Message
Evil Kraig F
Evil Kraig F
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5713 Visits: 7660
GilaMonster (10/5/2010)
Craig Farrell (10/5/2010)
I got it right, but a question regarding dedicated extents. I know page splits will happen, etc etc, but does an extent stay compact for a range of data, or will it split out of the extent and return to it with page pointers?


Test it out and see (hint DBCC IND and DBCC PAGE)

Think about it. What happens if all 8 pages in the dedicated extent are full and a row is inserted that has to go onto page 4 of the extent?


Ah, DBCC IND, thank you, couldn't remember for the life of me. Stupid undocmented... mutter mutter.

It's going to go cross extent. Gyeah. For some reason I had though the extents shifted, keeping multiple page chains intact... and I check the extent alloc status and it's all over the place. Alright, I have some understanding on extents to do. My experience with them is limited to fighting with LOB data.

Which begs the question, why the heck are there extents in the first place for anything but LOB data...


- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47376 Visits: 44396
Craig Farrell (10/5/2010)
Which begs the question, why the heck are there extents in the first place for anything but LOB data...


An extent is nothing more than a contiguous 8 pages (64kb) aligned on a 64kb boundary. It has no special structure.

Why they exist, my guesses:
Make allocation easier. The GAM and SGAM pages are both 1 bit per extent. DIFF and ML pages as well I believe. If allocation was on a page level, there would be 8 times more allocation pages in the database files. (PFS pages are per-page though)

Make read-ahead more efficient. Read-ahead requires contiguous pages. So SQL can issue a read-ahead request for pages 36176 - 36208 possibly as a single IO request. To ask for pages 36208, 36210, 36215, 36218, 36220 and 36222 requires6 IO requests. (I think. I need to double check IO basics again)

Among probably many other reasons.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Dhruvesh Shah
Dhruvesh Shah
SSChasing Mays
SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)

Group: General Forum Members
Points: 635 Visits: 237
Great Question.
rtelgenhoff
rtelgenhoff
Right there with Babe
Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)Right there with Babe (716 reputation)

Group: General Forum Members
Points: 716 Visits: 356
Ok Robert, you made me dig into this one deeper. We see the misconceptions about physical vs. logical ordering of pages in a clustered index, but there also seems to be misconceptions about physical ordering of rows within pages.

According to BOL
http://msdn.microsoft.com/en-us/library/ms190639.aspx
'A clustered index is particularly efficient on columns that are often searched for ranges of values. After the row with the first value is found using the clustered index, rows with subsequent indexed values are guaranteed to be physically adjacent.'

Digging deeper, though, there is the concept of the row offset table _aka_ slot array at the end of each page. Using the indirection of this table, index order of rows within the page is maintained by the order of the row entries in this table. Entry 0 has the offset of the 1st ordered row, entry 1->2nd ordered row. The values of the offsets in this table don't have to be in order, they just have to point to the correct row start location in the page. As rows are inserted/deleted/updated, the offsets in this table are updated as needed to maintain the sort order.

Ordered Row - Offset
4 (0x4) - 177 (0xb1)
3 (0x3) - 150 (0x96)
2 (0x2) - 123 (0x7b)
1 (0x1) - 96 (0x60) offset of 2nd row in sort order
0 (0x0) - 204 (0xcc) offset of 1st row in sort order (a newly inserted record, 1st in the offset table, but physically at end)

Paul S. Randal explains this in depth on his site www.sqlskills.com
http://www.sqlskills.com/BLOGS/PAUL/post/Inside-the-Storage-Engine-Proof-that-records-are-not-always-physically-stored-in-index-key-order.aspx
Bhuvnesh
Bhuvnesh
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2930 Visits: 4076
really GOOD question..i really got my eye-brow raised while see the answer.:-D

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Hardy21
Hardy21
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1204 Visits: 1399
rtelgenhoff (10/5/2010)
Ok Robert, you made me dig into this one deeper. We see the misconceptions about physical vs. logical ordering of pages in a clustered index, but there also seems to be misconceptions about physical ordering of rows within pages.

According to BOL
http://msdn.microsoft.com/en-us/library/ms190639.aspx
'A clustered index is particularly efficient on columns that are often searched for ranges of values. After the row with the first value is found using the clustered index, rows with subsequent indexed values are guaranteed to be physically adjacent.'

Digging deeper, though, there is the concept of the row offset table _aka_ slot array at the end of each page. Using the indirection of this table, index order of rows within the page is maintained by the order of the row entries in this table. Entry 0 has the offset of the 1st ordered row, entry 1->2nd ordered row. The values of the offsets in this table don't have to be in order, they just have to point to the correct row start location in the page. As rows are inserted/deleted/updated, the offsets in this table are updated as needed to maintain the sort order.

Ordered Row - Offset
4 (0x4) - 177 (0xb1)
3 (0x3) - 150 (0x96)
2 (0x2) - 123 (0x7b)
1 (0x1) - 96 (0x60) offset of 2nd row in sort order
0 (0x0) - 204 (0xcc) offset of 1st row in sort order (a newly inserted record, 1st in the offset table, but physically at end)

Paul S. Randal explains this in depth on his site www.sqlskills.com
http://www.sqlskills.com/BLOGS/PAUL/post/Inside-the-Storage-Engine-Proof-that-records-are-not-always-physically-stored-in-index-key-order.aspx


Thanks it clears my doubts. :-)

Thanks
deepak.a
deepak.a
Mr or Mrs. 500
Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)Mr or Mrs. 500 (562 reputation)

Group: General Forum Members
Points: 562 Visits: 863
thanks for the nice question
khullargirish02
khullargirish02
Old Hand
Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)

Group: General Forum Members
Points: 385 Visits: 126
CoolSatisfiedClustered index is newly created or rebuilt, it is physically and logically ordered as per the cluster key(s). But when data is inserted or the clustering key values are updated, DB engine preserves logical ordering of the data.
dva2007
dva2007
Mr or Mrs. 500
Mr or Mrs. 500 (550 reputation)Mr or Mrs. 500 (550 reputation)Mr or Mrs. 500 (550 reputation)Mr or Mrs. 500 (550 reputation)Mr or Mrs. 500 (550 reputation)Mr or Mrs. 500 (550 reputation)Mr or Mrs. 500 (550 reputation)Mr or Mrs. 500 (550 reputation)

Group: General Forum Members
Points: 550 Visits: 1109
I've seen this question following the clarification of physical and logical ordering so i got it right. I am sure i must have answered it wrong before few days. Good one.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search