SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Creating appropriate index


Creating appropriate index

Author
Message
@RDBMS
@RDBMS
Valued Member
Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)

Group: General Forum Members
Points: 61 Visits: 58
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
Igor Micev
Igor Micev
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5940 Visits: 5084
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,
SQL Server developer at Seavus
My blog: www.igormicev.com
@RDBMS
@RDBMS
Valued Member
Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)

Group: General Forum Members
Points: 61 Visits: 58
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
Igor Micev
Igor Micev
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5940 Visits: 5084
@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,
SQL Server developer at Seavus
My blog: www.igormicev.com
@RDBMS
@RDBMS
Valued Member
Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)

Group: General Forum Members
Points: 61 Visits: 58
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
Igor Micev
Igor Micev
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5940 Visits: 5084
@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,
SQL Server developer at Seavus
My blog: www.igormicev.com
@RDBMS
@RDBMS
Valued Member
Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)

Group: General Forum Members
Points: 61 Visits: 58
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
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