SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 very large table 3 billion records indexing issue
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MrBloom
Starting Member

United Kingdom
34 Posts

Posted - 07/28/2013 :  04:12:50  Show Profile  Reply with Quote
Hi


I have a table with almost 3 billion records
the are 4 columns
ID (varchar), start (int), end(int), value (varchar)

ID and start compounded together can make the record unique but ID can be a mix of alphanumerics so is set as a varchar.



the main query I would like to run is fairly simple.




SELECT   ID, start,  [end] , value
  FROM MYTable
  WHERE ID  = 'somevalue' AND  start >= someint and [end] <= someint



This query is usually run through several times in a batch script where different ID, start and end values are
passed to the query and the results are selected into a temp table.


I'm not sure about the best index to build on this table to make the query run the most efficiently. Whether to build a clustered or non clustered index on ID, start, end.
Or even to reload the table with a unique identity column and partition on this.

thanks

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 07/28/2013 :  11:46:27  Show Profile  Reply with Quote
Clustered on id,start,end combination should be enough

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

srimami
Posting Yak Master

160 Posts

Posted - 08/08/2013 :  05:03:18  Show Profile  Reply with Quote
It depends on your where condition that is being used in queries. Visakhs's suggestion would work based on the query you provided but if other users are querying on Data Column then I would suggest you go with Clustered Index on Date column and NCL on remaining columns.

Thanks,
Sri.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 08/08/2013 :  06:31:42  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Creating a clustered index on a 3 billion row table will take time and a lot of log file space.
At least 1.5-2 hours to complete.

Which indexes do you already have on the table?





Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000