SQLServerCentral

Physical and Logical Ordering of an index


https://www.sqlservercentral.com/Forums/Topic809198.aspx

By Chandhini - Monday, October 26, 2009 10:10 PM

Hi,

Fragmentation will occur if physical and logical order are different..

but there is a confusion, what exactly are we referring physical order and logical order?

My understand of them,
Physical Order : Contiguous pages
By Chandhini - Monday, October 26, 2009 10:14 PM

Hi,

Fragmentation will occur if physical and logical order are different..

but there is a confusion, what exactly are we referring physical order and logical order?

My understand of them,
Physical Order : Contiguous pages

and logical order : data pages are linked like a linked list. and references would be there for physical order.

Is that correct. please guide me if i m wrong.

Regards,
Ramani
By Grant Fritchey - Monday, October 26, 2009 11:21 PM

Logical order is the ordering of the index. Let's assume an index based on last name. The logical order would be:

Adams
Johnson
Smith
Williams

But, due to page splits, insertions, deletes and the other things that can affect the order in which pages or stored, the physical order, meaning the order of the actual storage, may look like this:

Adams
Wiliam
Johnson
Smith

Defragmenting will move the order of the physical storage closer to that of the logical definition. It may not be exact and it's unlikely to remain so as the data changes.
By jsb12 - Saturday, January 16, 2010 9:33 AM

I'm getting it now. I had doubts regarding this.
But still, one more clarification - when it is said that when clustered index is traversed to the leaf level, the data is retrieved not just pointed to. Does this retrieving have any bearing on the physical storage, or how data is physically stored? what implications does this have in terms of logical order vs physical order?
By Matt Miller (4) - Saturday, January 16, 2010 1:42 PM

When there IS a clustered index, the physical data is stored in the clustered index. So the leaf level of a CLUSTERED index = the actual record. Any non-clustered index points to the clustered index for its data, so given your description, in a clustered index the data is retrieved as soon as you access the leaf node, instead of the extra hop (called a "bookmark lookup") you end up with in a non-clustered index.

Keep in mind that even the pages themselves are logical constructs. Granted - they're a fixed size, but they exist within physical files which grow as needed, so you could have multiple kinds of "physical fragementation". For example, with files that grow with "auto-growth on", the files themselves will be fragmented on the OS layer; the pages can physically exist anywhere within those OS files, then getting logically assigned to the index based on the usage and maintenance patterns on the table.
By GilaMonster - Saturday, January 16, 2010 7:19 PM

This series on indexing (and especially the comments on the second one) may be worth reading
http://www.sqlservercentral.com/articles/Indexing/68439/