2

When creating an index one can determine if an index column is sorted using ascending or descending order. BOL says that

[ ASC | DESC ]
Determines the ascending or descending sort direction for the particular index column. The default is ASC.

What is the primary reason for choosing between ASC or DESC?

asked Dec 11, 2011 at 16:54

3 Answers 3

5

Since indexes can be scanned in both directions most of the time there isn't much reason for choosing DESC. Some TOP queries could be helped by the DESC on some of the columns of a covering index but only testing will show if this helps.

One other difference is that the forward order scan can be run in parallel but the reverse order scan is always single threaded.

answered Dec 11, 2011 at 17:55
3
  • Do you know what the system does to optimise the physical I/O on a descending scan so it plays nicely with the disk rotation? Commented Jan 6, 2012 at 14:25
  • The controllers and the drives themselves can re-order the requests, on SATA drives this is refered to as Native Command Queueing sata-io.org/technology/ncq.asp Commented Jan 6, 2012 at 14:36
  • So presumably it just issues scatter-gather I/O requests and lets the I/O subsystem return in whatever order it gets the data. Commented Jan 6, 2012 at 15:15
3

If you have a frequently used query that returns items in descending order then you might want to create the index with a column ordered DESC.

An example of where this might be useful is with date stamped transactions or history where you frequently issue queries where you want to see the most recent ones first. However, in most cases you probably want to use the default, which is ASC.

answered Dec 11, 2011 at 17:51
3

Another thing that needs consideration is when the index is a clustered one. You generally want to have new rows added at the end of a b-tree index, to avoid fragmentation. So, it would usually be better to have ASC and not DESC for a clustered index, e.g. for an IDENTITY or a DATETIME one.

Unless off course you have a column like DaysTillTheEndOfTheWord INT, where new rows will have smaller values that older rows. A clustered index should better be DESC in that case.

answered Dec 11, 2011 at 19:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.