SQL Server Storage Engine

Minimal Logging changes in SQL Server 2008

Please refer to the earlier post for the background information on minimal logging. Starting with SQL Server 2008, the minimal logging has been enhanced. These enhancements are available to regular TSQL Insert as well. One of the key customer scenario was to be able to transfer data from a staging table to the target table. The only choice the customers had was to use SELECT * INTO <target> from <staging-table> if they wanted minimal logging. The limitation of this solution was that customers had no control on DDL aspect of the target table. WIth this new enhancement, this restriction is now removed. 

I used a flavor of the following query to find log records

 

select top 10 operation,context, [log record fixed length], [log record length], AllocUnitId, AllocUnitName

from fn_dblog(null, null)

where allocunitname='dbo.t_heap'

order by [Log Record Length] Desc

(1)    Insert into a HEAP is minimally logged under TABLOCK but fully logged without TABLOCK. This is one of the features that customers have been asking for. By the way, the only drawback is that it holds X lock, unlike Bulk Insert which holds BU lock, so you cannot insert using multiple threads.

 

-- create the source table

create table t_source (c1 int, c2 int, c3 char (100), c4 char(1000))

go

 

declare @i int

select @i = 1

while (@i < 1000)

begin

            insert into t_source values (@i, @i+10000, 'indexkey', 'hello')

            select @i= @i + 1

end

 

 

 

-- create the target heap

create table t_heap (c1 int, c2 int, c3 char(100), c4 char(1000))

go

 

-- this is minimally logged.

-- LOCK: X lock on the table

-- this behavior is same even when ‘t_heap’ is not empty

begin tran

insert into t_heap with (TABLOCK) select * from t_source

 

-- here are the top-10 log records. You can see that it is minimally logged

 

 

-- this is fully logged

insert into t_heap select * from t_source

 

-- here are the top 10 log records. You can see that it is fully logged

 

 

 

Thanks

Sunil 

 

 

 

 

 

Published Thursday, March 06, 2008 5:12 AM by Sunil Agarwal
Filed under:

Comments

 

SQL Server Storage Engine said:

March 24, 2008 1:05 PM
 

Chad Boyd said:

Given some of the &quot;larger&quot; features being introduced with Sql 2008 which are getting lots of

May 21, 2008 2:36 AM
 

Chadhoc.net said:

Katmai (Sql 2008) - Transaction Logging Enhancements

May 21, 2008 2:37 AM
 

SQL Server Storage Engine said:

As part of SQL2008 release, you can get minimal logging when bulk importing into a HEAP using the following

August 11, 2008 2:07 PM
 

JungSun said:

Thank you for useful post.

I'm going to post it to my blog by Korean ^^

March 15, 2009 11:06 AM
 

JungSun said:

March 16, 2009 9:49 PM
Anonymous comments are disabled

About Sunil Agarwal

Sunil Agarwal is a Program Manager in the SQL Server Storage Engine Group at Microsoft. He is responsible for concurrency, indexes, tempdb, LOBS, supportability, and bulk import/export. Prior to joining Microsoft, Sunil worked at DEC, Sybase, BMC Software and DigitalThink, focusing primarily on core database engine technologies and related applications.

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker