Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234

Clustered Indexes Expand / Collapse
Author
Message
Posted Tuesday, October 5, 2010 2:56 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 4:43 AM
Points: 5,401, Visits: 7,512
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
Post #998782
Posted Tuesday, October 5, 2010 3:08 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:09 PM
Points: 40,172, Visits: 36,560
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 2008, MVP
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

Post #998789
Posted Tuesday, October 5, 2010 4:27 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Sunday, November 17, 2013 11:53 AM
Points: 623, Visits: 237
Great Question.
Post #998838
Posted Tuesday, October 5, 2010 10:17 PM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 11:01 AM
Points: 703, Visits: 327
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

Post #998929
Posted Wednesday, October 6, 2010 12:55 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, October 6, 2014 5:46 AM
Points: 2,840, Visits: 3,969
really GOOD question..i really got my eye-brow raised while see the answer.

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #999004
Posted Wednesday, October 6, 2010 3:23 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 4:43 AM
Points: 1,130, Visits: 1,391
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
Post #999080
Posted Monday, October 18, 2010 3:24 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, January 2, 2014 9:57 AM
Points: 554, Visits: 863
thanks for the nice question
Post #1006055
Posted Friday, May 27, 2011 3:45 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Sunday, September 21, 2014 12:18 AM
Points: 375, Visits: 116
Clustered 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.
Post #1116086
Posted Thursday, November 3, 2011 8:57 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Saturday, March 8, 2014 5:15 AM
Points: 534, Visits: 1,040
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.
Post #1199957
« Prev Topic | Next Topic »

Add to briefcase «««1234

Permissions Expand / Collapse