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


Stairway to SQL Server Indexes: Step 2, Deeper into Nonclustered Indexes


Stairway to SQL Server Indexes: Step 2, Deeper into Nonclustered Indexes

Author
Message
David Durant
David Durant
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 23
Comments posted to this topic are about the item Stairway to SQL Server Indexes: Step 2, Deeper into Nonclustered Indexes
russella0-96423
russella0-96423
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 255
I think the line that reads 'scanning the entire table of one million rows' should probably be 'scanning the entire table of twenty thousand odd rows'.

I'm not being pedantic here - I always like it when someone questions something in a doc I've written as it shows they've read it. The only reason I noticed it was such a good article that I was paying proper attention when I read it Smile.

Thanks for this series, I'm really enjoying it.

I'm meant to be a seasoned DBA, sometimes it worries me how rusty I am on some very fundamental subjects.

Best,

Andy



David Durant
David Durant
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 23
Andy,

Sorry for the long delay in replying; have been completing the remaining levels.

Will reread the level with an eye of rewording it.

Thanks for the input,
Dave Durant.
Author.
GURSETHI
GURSETHI
SSC Journeyman
SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)

Group: General Forum Members
Points: 96 Visits: 469
Hi David,

One quick one. In session II of Stairway to SQL Server Indexes you mentioned that:

* Non Clustered Index Is a sorted set of entries.

I have little doubt on it.

If we run below query you will find that the output of first query on "CONTACTS_INDEX" table with "FULLNAME" index on "LastName, FirstName" the out put is not sorted.

SELECT * FROM DBO.CONTACTS_INDEX WHERE LASTNAME LIKE 'Ste%'

But when we run the below query on "CONTACT_NOINDEX" table results are sorted.

SELECT * FROM DBO.CONTACTS_NOINDEX WHERE LASTNAME LIKE 'Ste%'


So now my question is why is it so? If I do a select on Heap table I am getting data sorted but when I do a select on table with NonCluster index data is not sorted.
mirzafarazbeg
mirzafarazbeg
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 102
Dave,

Really benefiting from this series, in fact, all stairway series.

I have a very beginner-level question, you're showing the contents of the indexes as if selecting from a table. Is there a way to actually do it. I mean like "select * from ix_table1_nc_index"... is there a way to do that?

Thanks,
Faraz
Uwe Ricken
Uwe Ricken
Right there with Babe
Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)

Group: General Forum Members
Points: 728 Visits: 844
Hi Faraz,

you can use DBCC IND if you use SQL Server < 2012 or sys.dm_db_database_page_allocation for SQL Server >= 2012.
This will give you a list of allocated pages.
To have a look at the root node (or any other page of the index you use

DBCC PAGE

More details about can be found here:
http://blogs.msdn.com/b/sqlserverstorageengine/archive/2006/12/13/more-undocumented-fun_3a00_-dbcc-ind_2c00_-dbcc-page_2c00_-and-off_2d00_row-columns.aspx

Microsoft Certified Master: SQL Server 2008
MVP - Data Platform (2013 - ...)
my blog: http://www.sqlmaster.de (german only!)
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8400 Visits: 19504
Uwe Ricken (11/26/2014)
Hi Faraz,

you can use DBCC IND if you use SQL Server < 2012 or sys.dm_db_database_page_allocation for SQL Server >= 2012.
This will give you a list of allocated pages.
To have a look at the root node (or any other page of the index you use

DBCC PAGE

More details about can be found here:
http://blogs.msdn.com/b/sqlserverstorageengine/archive/2006/12/13/more-undocumented-fun_3a00_-dbcc-ind_2c00_-dbcc-page_2c00_-and-off_2d00_row-columns.aspx


Helpful as this response may be, it does not answer Faraz' question.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Uwe Ricken
Uwe Ricken
Right there with Babe
Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)Right there with Babe (728 reputation)

Group: General Forum Members
Points: 728 Visits: 844
Hey Phil,

why doesn't it meet the requirements / question?
He wants to have the content of the index itself or do I missunderstand the request?


CREATE TABLE dbo.foo
(
id INT NOT NULL,
c1 CHAR(20) NOT NULL,
c2 DATE NOT NULL,

CONSTRAINT pk_foo_id PRIMARY KEY CLUSTERED (Id)
);
GO

INSERT INTO dbo.foo (id, c1, c2) VALUES
(1, 'col1', '20140101'),
(2, 'col2', '20140201'),
(3, 'col3', '20140301'),
(4, 'col4', '20140401')
GO

CREATE NONCLUSTERED INDEX ix_foo_c2 ON dbo.foo(c2);
GO

-- check the index id's of dbo.foo
SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID('dbo.foo');
GO

-- IF nonclustered index is ID = 2
DBCC IND('demo', 'dbo.foo', 2);

-- Output of page content to client
-- after execution of DBCC IND the page with type = 2 is
-- the index page! 10 is IAM!
-- Replace the page_id with that evaluated id
DBCC TRACEON (3604);
DBCC PAGE('demo', 1, <page_id, 3);
GO



When running this script you get the list of values from one page of the index with its content!
BTW: The question was from 2012 Smile
Seems to be worthless to discuss the intention Smile

Microsoft Certified Master: SQL Server 2008
MVP - Data Platform (2013 - ...)
my blog: http://www.sqlmaster.de (german only!)
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8400 Visits: 19504
why doesn't it meet the requirements / question?
He wants to have the content of the index itself or do I missunderstand the request?


Because I believe the poster was asking whether the actual physical data could be returned by selecting from the index, not the index meta data.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Iwas Bornready
Iwas Bornready
SSCrazy Eights
SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)

Group: General Forum Members
Points: 8706 Visits: 885
What this article has done is show me how much index study I need to do. Thanks.
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