How indexs are used to locate data from table

  • I have a table structure

    Titles (table)

    -> TitleID (Primary Key clustered index)

    -> AuthorID (Foreign Key non-clustered index)

    -> AccountID (Foreign Key non-clustered index)

    -> some other columns (title name etc)

    Now i fire the following query

    Select * from Titles

    Where AuthorID = 10 and AccountID = 20

    Suppose in the table there are 100 rows corresponding to AuthorID = 100 and 150 rows for AccountID = 20 and say

    28 rows where AuthorID = 100 and AccountID = 20.

    It means the above query returns 28 rows.

    Now my question is how the two non clustered index will be used, i mean to say which of the following scenario will

    be used in SQL server 2000

    1. Uses AuthorID non-clustered to find rows containg 100 and then out of these 100 rows find AccountID where value is 20

    If this happens in SQL server 2000 then does it mean the non-clustered index of AccountID is not used.

    2. Uses AuthorID non-clustered to find rows containg 100 and Uses AccountID non-clustered to find rows containg 20 and then take the intersection of these results.

    3. any other scenario (if that so please suggest).

  • Have you followed the query's execution plan in QA?

    Frank

    http://www.insidesql.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • No i haven't seen its query plan.

    Actually i want to know what is the approach of SQL server.?

    No problem i will check the execution plan

  • quote:


    Actually i want to know what is the approach of SQL server.?


    ex ante you can't tell which strategy will be chosen by the optimizer.

    Frank

    http://www.insidesql.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Hi Frank Kalis

    The query plan shows that it uses second approach that is select the data using indexes and then take a intersection of the results based on the primary key column.

  • Get a copy of

    Inside sql server 2000 by Kalen Delaney.

    It tells you a lot about the internal structures in sql server.

    Cursors never.

    DTS - only when needed and never to control.


    Cursors never.
    DTS - only when needed and never to control.

  • quote:


    Cursors never.

    DTS - only when needed and never to control.


    ...

    Hey Nigel, where is the third line in your autosignature ?

    Frank

    http://www.insidesql.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Beer is not cold and it's not fizzy

  • The SQLServer is using only 1 index on one table at time.

    The optimizer will choose one of the index dependig on the statistics.

    After either there will be a bookmark lookup or it will access the table and fetch all the corresponding rows and selects the reqired ones (those corresponding to the second parameter)

    I hope in the next versions of there will be an improved index join/merge usage before accessing the data table itself

    Bye

    Gabor



    Bye
    Gabor

Viewing 9 posts - 1 through 8 (of 8 total)

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