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
»
T-SQL (SS2K5)
»
Performance of Joins over Updates
Performance of Joins over Updates
Rate Topic
Display Mode
Topic Options
Author
Message
dwilliscp
dwilliscp
Posted Friday, September 07, 2012 7:40 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 9:52 AM
Points: 187,
Visits: 332
I was wondering if anyone knows which is faster, to build data for my reporting table..
To write new data using three outer joins or to use one outer join, and get most of the data, then use three updates to load the other three columns?
Granted there is not a lot of rows being loaded.. about 500K each night, 70MB of data. The linked tables are not large.. except for the material table that has several mil rows.
Post #1355980
Michael Valentine Jones
Michael Valentine Jones
Posted Friday, September 07, 2012 8:11 AM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 10:01 PM
Points: 2,944,
Visits: 10,504
You haven't provided enough information for anyone to begin to answer that question.
You should just try each way to see which is faster.
Post #1355999
dwilliscp
dwilliscp
Posted Friday, September 07, 2012 8:29 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 9:52 AM
Points: 187,
Visits: 332
Michael Valentine Jones (9/7/2012)
You haven't provided enough information for anyone to begin to answer that question.
You should just try each way to see which is faster.
The problem with that is.. before the second run I would need to make sure the data is flushed from memory... not sure how to do that. Otherwise the second run should always be faster since it does not have hard drive I/O.
Post #1356009
ChrisM@Work
ChrisM@Work
Posted Friday, September 07, 2012 8:38 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 4:43 AM
Points: 5,609,
Visits: 10,974
dwilliscp (9/7/2012)
Michael Valentine Jones (9/7/2012)
You haven't provided enough information for anyone to begin to answer that question.
You should just try each way to see which is faster.
The problem with that is.. before the second run I would need to make sure the data is flushed from memory... not sure how to do that. Otherwise the second run should always be faster since it does not have hard drive I/O.
Then do several runs - A after A, A after B, B after A, B after B.
I've rarely seen an UPDATE to an intermediate table, as you describe, perform faster than a straight SELECT. It's most often seen when the developer has missed something.
“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.”
- Gail Shaw
For fast, accurate and documented assistance in answering your questions, please read
this article
.
Understanding and using APPLY, (I)
and
(II)
Paul White
Hidden RBAR: Triangular Joins
/
The "Numbers" or "Tally" Table: What it is and how it replaces a loop
Jeff Moden
Exploring Recursive CTEs by Example
Dwain Camps
Post #1356014
Michael Valentine Jones
Michael Valentine Jones
Posted Friday, September 07, 2012 1:20 PM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 10:01 PM
Points: 2,944,
Visits: 10,504
dwilliscp (9/7/2012)
Michael Valentine Jones (9/7/2012)
You haven't provided enough information for anyone to begin to answer that question.
You should just try each way to see which is faster.
The problem with that is.. before the second run I would need to make sure the data is flushed from memory... not sure how to do that. Otherwise the second run should always be faster since it does not have hard drive I/O.
CHECKPOINT;
DBCC DROPCLEANBUFFERS;
Post #1356207
Alexander Suprun
Alexander Suprun
Posted Friday, September 07, 2012 2:08 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 3:15 PM
Points: 160,
Visits: 802
dwilliscp (9/7/2012)
To write new data using three outer joins or to use one outer join, and get most of the data, then use three updates to load the other three columns?
Usually the 1st approach is faster.
If any of these 3 columns have variable length (say varchar) then your update statement will cause a lot of page splits and therefore fragmentation.
Alex Suprun
Post #1356233
dwilliscp
dwilliscp
Posted Monday, September 10, 2012 8:04 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 9:52 AM
Points: 187,
Visits: 332
Alexander Suprun (9/7/2012)
dwilliscp (9/7/2012)
To write new data using three outer joins or to use one outer join, and get most of the data, then use three updates to load the other three columns?
Usually the 1st approach is faster.
If any of these 3 columns have variable length (say varchar) then your update statement will cause a lot of page splits and therefore fragmentation.
I did run some tests.. but the results were not steady.. there is a lot of activity on this box. The updates do tend to have less variation, thus it can take 5% longer or up to 20% less time.. depending on the test. Again due to the load on the box, I just do not put any faith in the tests.
All the fields from the join are 50 - 200 varchar. So that could explain why this had the widest variation of run times. So since we have I/O pressure.. on this box and the production one this will get released too, I am going to go with the updates.
Post #1356754
ChrisM@Work
ChrisM@Work
Posted Tuesday, September 11, 2012 2:06 AM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 4:43 AM
Points: 5,609,
Visits: 10,974
dwilliscp (9/10/2012)
Alexander Suprun (9/7/2012)
dwilliscp (9/7/2012)
To write new data using three outer joins or to use one outer join, and get most of the data, then use three updates to load the other three columns?
Usually the 1st approach is faster.
If any of these 3 columns have variable length (say varchar) then your update statement will cause a lot of page splits and therefore fragmentation.
I did run some tests.. but the results were not steady.. there is a lot of activity on this box. The updates do tend to have less variation, thus it can take 5% longer or up to 20% less time.. depending on the test. Again due to the load on the box, I just do not put any faith in the tests.
All the fields from the join are 50 - 200 varchar. So that could explain why this had the widest variation of run times. So since we have I/O pressure.. on this box and the production one this will get released too, I am going to go with the updates.
Why not post the actual plan for both versions here?
“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.”
- Gail Shaw
For fast, accurate and documented assistance in answering your questions, please read
this article
.
Understanding and using APPLY, (I)
and
(II)
Paul White
Hidden RBAR: Triangular Joins
/
The "Numbers" or "Tally" Table: What it is and how it replaces a loop
Jeff Moden
Exploring Recursive CTEs by Example
Dwain Camps
Post #1357185
« 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.