Page Splitting & Rollbacks
So while I was at the grocery store last night, my mind wandered to SQL Server. This time, I was pondering what happens to a page split if the transaction is rolled back. I didn't know the answer, but my guess was that the page split remained, since it would be less expensive for SQL Server to leave the data where it was sitting. Also, in theory, if the page split occurred once, it could need to occur again, so why undergo that same expense twice?
I decided to run a simple test to see what would happen. First, I created a really wide table and tossed 4 rows into it:
Create Table myTable ( id int Primary Key , wideColumn char(2000) ); Insert Into myTable Select 1, Replicate('A', 2000) Union All Select 2, Replicate('B', 2000) Union All Select 4, Replicate('C', 2000) Union All Select 5, Replicate('D', 2000);
I left an open spot for id=3, so I can force a page split. Next, I looked at the page data using the script I posted in February.
Here's what I saw:
Pay attention to the 2 items boxed in red. m_slotCnt tells us how many records are on the page, and m_nextPage tells us the address of the next page. As you may have guessed, a m_nextPage value of 0:0 means you're looking at the last page allocated to the object.
Now let's insert a record, roll it back, and see what happens:
Begin Transaction; Insert Into myTable Select 3, Replicate('E', 2000); Rollback Transaction;
I ran my DBCC Page command again and here's what I saw:
As you can see, m_slotCnt is now 2, and m_nextPage is no longer 0:0 (although your actual page number will probably be different than mine). If I pull up the new page, I find my 2 relocated records, id's 4 and 5.
So what's this all mean? In short, page splits are NOT reversed when a transaction is rolled back. Why should you care? Well, you probably wouldn't care much, unless you roll back a lot of transactions. But this is also a good thing to keep in mind if you have to abort a really large insert or update; if you don't plan to re-execute the aborted script, you may want to defrag your indexes to fix the splits.
Source: http://sqlfool.com/2009/04/page-splitting-rollbacks/
Categories
- Business Intelligence
- Internals
- Miscellaneous
- PASS
- Performance & Tuning
- Presentations
- SQL 2008
- SQL Tips
- Syndication
- T-SQL Scripts
Subscribe to my blog!
| Like what you see? Subscribe! |
![]() |
Around the Web
Recent Tweets
- RT @Phil_Factor: SQL Server table columns under the hood http://t.co/vp7gQ77B < what a great post
- @tradney haha that's awesome :)
- OH: @AdamMachanic's #sqlpass session was one of the best I've ever seen.
Archives
- November 2011
- October 2011
- September 2011
- July 2011
- June 2011
- May 2011
- April 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- July 2010
- June 2010
- May 2010
- April 2010
- February 2010
- January 2010
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008





April 9th, 2009 - 07:30
Very cool – thanks for the good info. I would’ve thought that it rolled everything back. Neat – thanks for sharing!
April 9th, 2009 - 10:16
Great post!
April 10th, 2009 - 09:27
Great post and interesting thing to keep in mind. I hope you didn’t forget the milk because you were thinking deep SQL Server thoughts in the grocery store.
April 10th, 2009 - 21:35
“So while I was at the grocery store last night, my mind wandered to SQL Server…” This is why I always end up with Maraschino Cherry and Mayonnaise sandwiches.
April 14th, 2009 - 00:31
Glad I’m not the only one who muses over SQL internals while shopping. It makes the entire shopping process so much less painful.
April 14th, 2009 - 11:45
Bookmarked. Thanks for the sharing.
May 3rd, 2009 - 19:06
Men always wonder what women are thinking about during… well.. now we know.