2

I have 8 billion records in my SQL Server table. I need to create an index on a couple of columns. I am sure that is going to take an unruly large amount of time.

Could somebody tell me a faster and better way of doing it?

2
  • See also: dba.stackexchange.com/questions/41153/…
    – Bacon Bits
    Nov 3, 2017 at 16:51
  • What's the index on? Don't create an index until you know what queries you will typically be using. You have a large selection of different types of indexes depending on what performance issue you are trying to solve. Across all of your questions on this topic you have not identified any actual issue. For example if this takes 8 hours to create an index, why is that a problem? It might take 5 minutes it might take 5 days
    – Nick.Mc
    Nov 7, 2017 at 10:59

2 Answers 2

3

One option i could think of is SORT_IN_TEMPDB = ON.which can help in creating index faster

The intermediate sort results that are used to build the index are stored in tempdb. This may reduce the time required to create an index if tempdb is on a different set of disks than the user database. However, this increases the amount of disk space that is used during the index build.

you could also try not querying the table so that there won't be any locking,blocking during creation of index or else use ONLINE = { ON | OFF } based on your edition of sqlserver..

Also if your database is in simple recovery model,this operation is minimally logged which reduces IO..

-2

It really shouldn't take that long to create indexes:

CREATE INDEX index_name
ON table_name (column1, column2, ...)
1
  • 2
    8 billion rows, though, which will take a while, especially if anything is updating that table. Assuming the columns are two ints, reading all the data into memory would occupy 64GB, which a server is unlikely to assign to a (relatively low priority) index build if memory is scarce. So the operation is likely to write out some data to disk (And for other reasons, too), which increases the time it takes. Nov 3, 2017 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.