Creating appropriate index

  • I have a transaction table with columns as below:

    (1) Tran_Id int P.K [Identity]

    (2) Location_Id smallint

    (3) Vertical_Id smallint

    (4) Customer_Id smallint

    (5) M_ID int

    (6) Condition_ID tinyint

    (7) T_ID smallint

    (8) Amount decimal(10,2)

    (9) Transaction_Date DateTime

    When user selects Date, Location, Vertical and Customer, a set of combination is returned (M_ID, Condition_ID and T_Id) for that date.

    I want to create an index and want to know which columns to include.

    I am thinking something like:

    CREATE INDEX IDX_DETAILS

    ON Transaction_Date

    INCLUDE (Location_ID, Vertical_ID, Customer_ID, M_ID, Condition_ID, T_ID)

    I want to do this because all the columns in the INCLUDE clause are linked to Transaction Date.

    Whenever I want to pick any set of M_ID, Condition_ID and T_ID, I am first going to select Date, Location, Vertical and Customer.

    I ran the Actual Execution Plan but it is not suggesting any missing indexes because the data, as of now, is low.

    What type of index would be suitable in this case?

    "Here is a test to find out whether your mission in life is complete. If you're alive, it isn't. "

    Richard Bach

  • Hi,

    You should always keep the indexing key as narrower as possible. However, sometimes you could use one index to cover more queries. In your case you plan to use only the Transaction_Date column in the key list, and include the other columns. If the execution plan does not detect missing indexes, then it'll keep on that way regardless of the table size. It will be better if you can overview some other queries to possibly extend the key and the include list, but always try to keep narrower the key list for faster navigation. The extension of the include list increases the index's size and does not have impact on the index's seeking speed.

    Regards,

    Igor

    Igor Micev,My blog: www.igormicev.com

  • What if I create two indexes as below:

    CREATE INDEX IDX_DATE

    ON Transaction_Date

    CREATE INDEX IDX_LOCATION

    ON Location_ID

    INCLUDE (Vertical_ID, Customer_Id)

    "Here is a test to find out whether your mission in life is complete. If you're alive, it isn't. "

    Richard Bach

  • @RDBMS (3/16/2014)


    What if I create two indexes as below:

    CREATE INDEX IDX_DATE

    ON Transaction_Date

    CREATE INDEX IDX_LOCATION

    ON Location_ID

    INCLUDE (Vertical_ID, Customer_Id)

    You'd better go with one index having Location_ID and Transaction_Date in the key list. The combination of an int and date column has proved as a good indexing strategy. In general you should avoid more than necessary indexes in a table.

    Igor Micev,My blog: www.igormicev.com

  • So according to your suggestion, the index would be:

    CREATE INDEX IDX_LOCATION_DATE

    ON Location_Id, Transaction_Date

    INCLUDE (Vertical_ID, Customer_Id)

    After creating this index, how can I determine whether it is performing well or not?

    "Here is a test to find out whether your mission in life is complete. If you're alive, it isn't. "

    Richard Bach

  • @RDBMS (3/16/2014)


    So according to your suggestion, the index would be:

    CREATE INDEX IDX_LOCATION_DATE

    ON Location_Id, Transaction_Date

    INCLUDE (Vertical_ID, Customer_Id)

    After creating this index, how can I determine whether it is performing well or not?

    You can use the logical and physical reads for a query run.

    Use

    set statistics io on

    and use

    dbcc dropcleanbuffers

    to clear the memory buffer, during your test.

    Igor Micev,My blog: www.igormicev.com

  • Thanks Igor.

    "Here is a test to find out whether your mission in life is complete. If you're alive, it isn't. "

    Richard Bach

Viewing 7 posts - 1 through 6 (of 6 total)

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