Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
SQL Server 2005 General Discussion
»
Index creation after of before populate?
Index creation after of before populate?
Rate Topic
Display Mode
Topic Options
Author
Message
ricardo_chicas
ricardo_chicas
Posted Monday, September 13, 2010 8:54 AM
SSC Journeyman
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 3:49 PM
Points: 94,
Visits: 426
Hello all,
What do you think is better, create indexes for temp tables after or before we populate them,
I tend to believe that create them before the inserts could be better, since we won't be blocking temp, but i have heard some other opinions
What do you think?
Thanks
Post #984857
Tim Walker.
Tim Walker.
Posted Monday, September 13, 2010 9:01 AM
SSC Veteran
Group: General Forum Members
Last Login: Yesterday @ 9:20 AM
Points: 259,
Visits: 815
My preference, if this is possible to do in your scenario, is:
1. Create table and unique clustered index
2. Insert data IN ORDER OF CLUSTERED INDEX
3. Create non clustered indexes
This way, you avoid fragmentation and unecessary sorting,
If you have to sort the data to achieve step 2, it doesn't matter so much which way around you do it.
.
Post #984858
WayneS
WayneS
Posted Monday, September 13, 2010 9:14 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 7:13 AM
Points: 6,370,
Visits: 8,233
If you are inserting a large amount of data, you will probably find it faster to add the index afterwards.
Wayne
Microsoft Certified Master: SQL Server 2008
If you can't explain to another person how the code that you're copying from the internet works, then
DON'T USE IT
on a production system! After all,
you
will be the one supporting it!
Links:
For better assistance in answering your questions
,
How to ask a question
,
Performance Problems
,
Common date/time routines
,
CROSS-TABS and PIVOT tables Part 1
&
Part 2
,
Using APPLY Part 1
&
Part 2
,
Splitting Delimited Strings
Post #984868
Steve Jones - SSC Editor
Steve Jones - SSC Editor
Posted Monday, September 13, 2010 9:17 AM
SSC-Dedicated
Group: Administrators
Last Login: Yesterday @ 3:26 PM
Points: 31,425,
Visits: 13,738
Ultimately you need to test and get an idea of when it's quicker which way. It often does depend on how much data, and your disk I/O.
Follow me on Twitter:
@way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
Post #984870
ricardo_chicas
ricardo_chicas
Posted Monday, September 13, 2010 9:31 AM
SSC Journeyman
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 3:49 PM
Points: 94,
Visits: 426
Actually my concern is that we have several dbs and ost of users, so I really need to be careful with the use of temp db, I like the approach of
Create table
create clustered index
Inserts
nonclustered
Post #984881
ALZDBA
ALZDBA
Posted Monday, September 13, 2010 9:36 AM
SSCertifiable
Group: General Forum Members
Last Login: Yesterday @ 2:17 AM
Points: 6,862,
Visits: 8,049
ricardo_chicas (9/13/2010)
Actually my concern is that we have several dbs and ost of users, so I really need to be careful with the use of temp db, I like the approach of
Create table
create clustered index
Inserts
nonclustered
In general that would be the prefered order if you load a full set. It will get you most optimal indexes with regards to fragmentation.
Keep in mind loading in order of the clustering index will have advantages too with regards to space usage and IO.
However, tempdb is always a special case, so profound testing may be in order !
Johan
Jul 13
Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere
-
How to post Performance Problems
-
How to post data/code to get the best help
-
How to prevent a sore throat after hours of presenting ppt ?
"press F1 for solution", "press
shift
+F1 for urgent solution"
Need a bit of Powershell? How about
this
Who am I ?
Sometimes this is me
but
most of the time this is me
Post #984887
Dung Dinh
Dung Dinh
Posted Monday, September 13, 2010 10:00 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Friday, May 03, 2013 8:54 AM
Points: 113,
Visits: 890
Which approach if we populate large data into a table many times?
Eg: Today I populate 2GB data follow below steps
Create Clustered Index on table
Insert data
Create Non-Clusterd Index(s)
Tomorrow, I will also populate data into the table.
Thanks,
Post #985212
Tim Walker.
Tim Walker.
Posted Tuesday, September 14, 2010 8:10 AM
SSC Veteran
Group: General Forum Members
Last Login: Yesterday @ 9:20 AM
Points: 259,
Visits: 815
The same principle 'probably' applies
i.e. Create table and clustered index, populate IN CLUSTERED INDEX ORDER, create additional indexes
But...
(1) With this much data you may well be sorting it first unless you are getting it straight out of another indexed tables (e.g. aggregation). If you have a sort step you'll need to test whether sorting is more intensive than creating the clustered index afterwards. It may well be.
(2) With this much data there may be a better way of doing this - e.g. only populating changes - you'd have to write logic for this
(3) With more complex requirements, as previous posters have said, you should test different techniques and see what works best - There are lots of potential differences vetween environments.
There is no 'best' way of doing things which always applies!
.
Post #985531
ALZDBA
ALZDBA
Posted Tuesday, September 14, 2010 8:15 AM
SSCertifiable
Group: General Forum Members
Last Login: Yesterday @ 2:17 AM
Points: 6,862,
Visits: 8,049
Any partitioning involved ... search BOL for "sliding windows"
Johan
Jul 13
Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere
-
How to post Performance Problems
-
How to post data/code to get the best help
-
How to prevent a sore throat after hours of presenting ppt ?
"press F1 for solution", "press
shift
+F1 for urgent solution"
Need a bit of Powershell? How about
this
Who am I ?
Sometimes this is me
but
most of the time this is me
Post #985536
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.