Deeper into Nonclustered Indexes: Stairway to SQL Server Indexes Level 2

  • Comments posted to this topic are about the item Deeper into Nonclustered Indexes: Stairway to SQL Server Indexes Level 2

  • 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 :).

    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

  • 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.

  • 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.

  • 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

  • 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!)

  • 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.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • 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

    (

    idINTNOT NULL,

    c1CHAR(20)NOT NULL,

    c2DATENOT 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 🙂

    Seems to be worthless to discuss the intention 🙂

    Microsoft Certified Master: SQL Server 2008
    MVP - Data Platform (2013 - ...)
    my blog: http://www.sqlmaster.de (german only!)

  • 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.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • What this article has done is show me how much index study I need to do. Thanks.

  • Thank you for the fine article. Where does the concept of indek "seek" and index "scan" fit into this article? It would be good to cover if not already planned in a future article.

     

    ----------------------------------------------------

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply