Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Adding new data file to tempdb, leads to data incorrection Expand / Collapse
Author
Message
Posted Wednesday, December 19, 2012 11:08 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 5:03 AM
Points: 2,840, Visits: 3,975
In one of the tempdb blog Here is link , it is stated that sometimes when we add a new file to tempdb to improve the performane it might lead to data incorrection (in context of data sorting or order) what i was thinking here is it could happen where multiple CPUs (multiple threads) are handling that particuler query (parallelism ) and combine the result at the end (not in order). am i on thr right page ?

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1398782
Posted Thursday, December 20, 2012 3:28 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 7:43 AM
Points: 40,438, Visits: 36,894
Depends what you mean by 'not in order'

Neither parallelism, nor multiple tempDB files are going to result in a query with an order by returning data out of order. Any time there's a query without an order by, no order is ever guaranteed and hence no order should ever be assumed, no matter what the server setup is.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1398885
Posted Thursday, December 20, 2012 4:26 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 5:03 AM
Points: 2,840, Visits: 3,975
OK thanks for explanation . can you please explain the phrase
We Added a Tempdb Data File, and Data Was Wrong
from http://www.brentozar.com/archive/2011/08/tempdb-multiplefiles-sort/


-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1398905
Posted Thursday, December 20, 2012 5:48 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 8:48 AM
Points: 2,077, Visits: 3,608
The data wasn't wrong, what's wrong is the assumption that the data would be ordered when no order was specified.

That whole blog post could be rewritten into a fairly good demonstration of why assuming an order when an order by is not used is false. Setting it up as multiple temp db files causes a problem is pretty misleading IMO.

"a high severity production incident was caused by adding an additional data file to the tempdb database." -> "adding an additional data file to the tempdb database caused a false assumption in the application to become evident when it caused a high severity production incident."

That's more like it
Post #1398929
Posted Thursday, December 20, 2012 7:09 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 7:43 AM
Points: 40,438, Visits: 36,894
Bhuvnesh (12/20/2012)
OK thanks for explanation . can you please explain the phrase
We Added a Tempdb Data File, and Data Was Wrong
from http://www.brentozar.com/archive/2011/08/tempdb-multiplefiles-sort/


Why don't you read the blog post? It was explained in there.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1398957
Posted Thursday, December 20, 2012 7:35 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 3:34 PM
Points: 3,109, Visits: 11,516
The order of the data could have changed without adding a file to tempdb, so that problem could have started happening anytime.

You should always have an ORDER BY unless you are absolutely sure that the order does not matter.

It's very common to assume that because you see the data from a query returned in the order you wanted that it will continue to be returned in that order in the future.

It's a common wrong assumption that when you select from a table the data will be returned in the order of the clustered index.










Post #1398973
Posted Thursday, December 20, 2012 5:00 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 8:51 PM
Points: 35,606, Visits: 32,190
Kendra's example was purely to show unintended consequences of making seemingly harmless changes to databases. Despite appearances, there is absolutely nothing that she's done that demonstrates that having multiple temp files affects the order in which data is imported. She did, however, do a great job demonstrating an accident just waiting to happen.

To wit, the REAL problem with the code (which she hasn't explained because that wasn't the objective of the article) is the addition of an IDENTITY column after the table is populated. The order of the IDENTITY values that will appear in such an "after the fact" manner is absolutely NOT guaranteed to be in what people think is the correct order according to the data present.

And, YES!!! I have the proof in the form of code! I'm in the process of writing it up.

Another set of unintended lessons that I believe you need to learn from her fine post is to expect the unexpected, knowing more about T-SQL before you decide "good enough" really is, and taking the time to make your code as bullet proof as possible.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1399134
Posted Thursday, December 20, 2012 10:49 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 5:03 AM
Points: 2,840, Visits: 3,975
I had read the article but couldnt able to extract the pure juice thats why i added a post here to have more and clear insight.

Jeff Moden (12/20/2012)
I believe you need to learn from her fine post is to expect the unexpected, knowing more about T-SQL before you decide "good enough" really is, and taking the time to make your code as bullet proof as possible.
thanks jeff.. i loved the quote you used here "Expect the unexpected".


-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1399191
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse