Bu sayfadaki iddiaları test etmek için bir komut dosyası yazdım http://technet.microsoft.com/en-us/library/dd425070(v=sql.100).aspx Ne zaman hakkında Minimum Kayıt Koşullarını Özetleme başlıklı tabloda yazdım en az günlük kaydı oluşur veya oluşmaz.
Bu komut dosyasını kullanarak, farklı ek türlerinin her biri için Günlük Kayıt Uzunluklarının toplamının aşağıdaki olduğunu buluyorum:
- Öbek boş tablock yok 60000
- Tablock 56000 ile yığın boş
- Yığın boş olmayan tablock 60000
- Tablock 56000 ile yığın boş değil
- Yığın artı dizin boş yok tablock 126188
- Tablock 114188 ile yığın artı dizini boş
- Yığın artı dizin boş olmayan tablock 138696
- Tablock 112000 ile yığın artı dizini boş değil
- Küme boş sipariş yok tablock 64168
- Küme boş tablock 56168 ile sipariş edildi
- Küme boş sıralanmamış yok tablock 73388
- Küme boş tablock 65388 ile sırasız
- Küme boş değil tablock 63912
- Tablock 55944 ile küme boş değil
- Küme artı dizin boş hayır tablock 124336
- Tablock 108336 ile Küme Artı Dizini Boş
- Küme artı dizini boş olmayan tablock 123876
- Tablock 107924 ile küme artı dizini boş değil
Bu numaralardan birkaçı technet sayfasındaki tabloyla eşleşmiyor gibi görünüyor. Özellikle:
- Boş ve boş olmayan tablolara ekleme arasında bir günlük kaydı farkı yoktur, ancak sayfa tablock olmadan boş olmayan bir kümeye eklerken tam günlük kaydı yapılması gerektiğini iddia ediyor
- Tablock ile ve öbeğine sahip bir kümeye veya indeks eklemek, günlüğe kaydetmeyi azaltmış gibi görünüyor, ancak sayfa tam günlüğe kaydetme gerektiğini iddia ediyor.
- SELECT INTO ekleme yöntemini kullanırken, fn_dblog dosyasında işlemi eklenen satırlar yoktur, ancak sayfa bu yöntemi tabloda açıklanan davranışa sahip olması gereken bir toplu yükleme işlemi olarak listeler
Başvuru için, bu bir SQL express veritabanında çalıştırıldı ve DBCC TRACESTATUS (610) çalıştırdığımda her şey 0.
Birisi neden bu tutarsızlıkları gördüğümü açıklamaya yardımcı olabilir mi?
Referans için kod aşağıdadır:
SET NOCOUNT ON
CREATE TABLE numbers (num INT)
CREATE TABLE numbersUnordered (num INT)
Declare @cnt int
Select @cnt=0
while (@cnt<500)
BEGIN
INSERT INTO NUMBERS(num) SELECT @cnt
SELECT @cnt=@cnt+1
END
Select @cnt=0
while (@cnt<250)
BEGIN
INSERT INTO numbersUnordered(num) SELECT @cnt*2
SELECT @cnt=@cnt+1
END
Select @cnt=0
while (@cnt<250)
BEGIN
INSERT INTO numbersUnordered(num) SELECT @cnt*2+1
SELECT @cnt=@cnt+1
END
---- heap empty without tablock
CREATE TABLE noKey1 (val INT)
INSERT INTO noKey1 (val)
SELECT * FROM numbers
DECLARE @heapEmptyNoTablock INT
SELECT @heapEmptyNoTablock = SUM([Log Record Length])
FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%noKey1%'
AND operation like '%insert%'
---- heap empty with tablock
CREATE TABLE noKey2 (val INT)
INSERT INTO noKey2 WITH(TABLOCK) (val)
SELECT * FROM numbers
DECLARE @heapEmptyTablock INT
SELECT @heapEmptyTablock = SUM([Log Record Length])
FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%noKey2%'
AND operation like '%insert%'
---- heap non empty without tablock
CREATE TABLE noKey3 (val INT)
INSERT INTO noKey3 WITH(TABLOCK) (val)
SELECT * FROM numbers
INSERT INTO noKey3 (val)
SELECT num+5 FROM numbers
DECLARE @heapNonEmptyNoTablock INT
SELECT @heapNonEmptyNoTablock = SUM(a.[Log Record Length])
FROM
(SELECT TOP 500 * FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%noKey3%'
AND operation like '%insert%'
ORDER BY [Current LSN] desc) a
---- heap non empty with tablock
CREATE TABLE noKey4 (val INT)
INSERT INTO noKey4 WITH(TABLOCK) (val)
SELECT * FROM numbers
INSERT INTO noKey4 WITH (TABLOCK) (val)
SELECT num+5 FROM numbers
DECLARE @heapNonEmptyTablock INT
SELECT @heapNonEmptyTablock = SUM(a.[Log Record Length])
FROM
(SELECT TOP 500 * FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%noKey4%'
AND operation like '%insert%'
ORDER BY [Current LSN] desc) a
--- heap plus index empty without tablock
CREATE TABLE noKey5 (val INT)
CREATE INDEX MSindex1
ON noKey5 (val)
INSERT INTO noKey5 (val)
SELECT * FROM numbers
DECLARE @heapIndexEmptyNoTablock INT
SELECT @heapIndexEmptyNoTablock = SUM([Log Record Length])
FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%noKey5%'
AND operation like '%insert%'
--- heap plus index empty with tablock
CREATE TABLE noKey6 (val INT)
CREATE INDEX MSindex2
ON noKey6 (val)
INSERT INTO noKey6 WITH(TABLOCK) (val)
SELECT * FROM numbers
DECLARE @heapIndexEmptyTablock INT
SELECT @heapIndexEmptyTablock = SUM([Log Record Length])
FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%noKey6%'
AND operation like '%insert%'
--- heap plus index non empty without tablock
CREATE TABLE noKey7 (val INT)
CREATE INDEX MSindex3
ON noKey7 (val)
INSERT INTO noKey7 WITH(TABLOCK) (val)
SELECT * FROM numbers
INSERT INTO noKey7 (val)
SELECT num+5 FROM numbers
DECLARE @heapIndexNonEmptyNoTablock INT
SELECT @heapIndexNonEmptyNoTablock = SUM(a.[Log Record Length])
FROM
(SELECT TOP 1000 * FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%noKey7%'
AND operation like '%insert%'
ORDER BY [Current LSN] desc) a
--- heap plus index non empty with tablock
CREATE TABLE noKey8 (val INT)
CREATE INDEX MSindex4
ON noKey7 (val)
INSERT INTO noKey8 WITH(TABLOCK) (val)
SELECT * FROM numbers
INSERT INTO noKey8 WITH(TABLOCK) (val)
SELECT num+5 FROM numbers
DECLARE @heapIndexNonEmptyTablock INT
SELECT @heapIndexNonEmptyTablock = SUM(a.[Log Record Length])
FROM
(SELECT TOP 1000 * FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%noKey8%'
AND operation like '%insert%'
ORDER BY [Current LSN] desc) a
--- cluster empty ordered without tablock
CREATE TABLE withKey1 (val INT PRIMARY KEY)
INSERT INTO withKey1 (val)
SELECT * FROM numbers
DECLARE @clusterEmptyNoTablock INT
SELECT @clusterEmptyNoTablock = SUM([Log Record Length])
FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%withKey1%'
AND operation like '%insert%'
--- cluster empty ordered with tablock
CREATE TABLE withKey2 (val INT PRIMARY KEY)
INSERT INTO withKey2 WITH(TABLOCK) (val)
SELECT * FROM numbers
DECLARE @clusterEmptyTablock INT
SELECT @clusterEmptyTablock = SUM([Log Record Length])
FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%withKey2%'
AND operation like '%insert%'
--- cluster empty unordered without tablock
CREATE TABLE withKey5 (val INT PRIMARY KEY)
INSERT INTO withKey5 (val)
SELECT * FROM numbersUnordered
DECLARE @clusterEmptyNoTablockUnordered INT
SELECT @clusterEmptyNoTablockUnordered = SUM([Log Record Length])
FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%withKey5%'
AND operation like '%insert%'
--- cluster empty undordered with tablock
CREATE TABLE withKey6 (val INT PRIMARY KEY)
INSERT INTO withKey6 WITH(TABLOCK) (val)
SELECT * FROM numbersUnordered
DECLARE @clusterEmptyTablockUnordered INT
SELECT @clusterEmptyTablockUnordered = SUM([Log Record Length])
FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%withKey6%'
AND operation like '%insert%'
--- cluster non empty no tablock
CREATE TABLE withKey7 (val INT PRIMARY KEY)
INSERT INTO withKey7 (val)
SELECT num FROM numbers
INSERT INTO withKey7 (val)
SELECT num+500 FROM numbers
DECLARE @clusterNonEmptyNoTablock INT
SELECT @clusterNonEmptyNoTablock = SUM(a.[Log Record Length])
FROM
(SELECT TOP 500 * FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%withKey7%'
AND operation like '%insert%'
ORDER BY [Current LSN] desc) a
--- cluster non empty with tablock
CREATE TABLE withKey8 (val INT PRIMARY KEY)
INSERT INTO withKey8 WITH(TABLOCK) (val)
SELECT num FROM numbers
INSERT INTO withKey8 WITH(TABLOCK) (val)
SELECT num+500 FROM numbers
DECLARE @clusterNonEmptyTablock INT
SELECT @clusterNonEmptyTablock = SUM(a.[Log Record Length])
FROM
(SELECT TOP 500 * FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%withKey8%'
AND operation like '%insert%'
ORDER BY [Current LSN] desc) a
--- cluster plus index empty no tablock
CREATE TABLE withKey9 (val INT PRIMARY KEY)
CREATE INDEX MSindex5
ON withKey9 (val)
INSERT INTO withKey9 (val)
SELECT * FROM numbers
DECLARE @clusterIndexEmptyNoTablock INT
SELECT @clusterIndexEmptyNoTablock = SUM([Log Record Length])
FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%withKey9%'
AND operation like '%insert%'
--- cluster plus index empty with tablock
CREATE TABLE withKey10 (val INT PRIMARY KEY)
CREATE INDEX MSindex6
ON withKey10 (val)
INSERT INTO withKey10 WITH(TABLOCK) (val)
SELECT * FROM numbers
DECLARE @clusterIndexEmptyTablock INT
SELECT @clusterIndexEmptyTablock = SUM([Log Record Length])
FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%withKey10%'
AND operation like '%insert%'
--- cluster plus index nonempty no tablock
CREATE TABLE withKey11 (val INT PRIMARY KEY)
CREATE INDEX MSindex7
ON withKey11 (val)
INSERT INTO withKey11 (val)
SELECT num FROM numbers
INSERT INTO withKey11 (val)
SELECT num+500 FROM numbers
DECLARE @clusterIndexNonEmptyNoTablock INT
SELECT @clusterIndexNonEmptyNoTablock = SUM(a.[Log Record Length])
FROM
(SELECT TOP 1000 * FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%withKey11%'
AND operation like '%insert%'
ORDER BY [Current LSN] desc) a
--- cluster plus index nonempty with tablock
CREATE TABLE withKey12 (val INT PRIMARY KEY)
CREATE INDEX MSindex8
ON withKey12 (val)
INSERT INTO withKey12 WITH(TABLOCK) (val)
SELECT num FROM numbers
INSERT INTO withKey12 WITH(TABLOCK) (val)
SELECT num+500 FROM numbers
DECLARE @clusterIndexNonEmptyTablock INT
SELECT @clusterIndexNonEmptyTablock = SUM(a.[Log Record Length])
FROM
(SELECT TOP 1000 * FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%withKey12%'
AND operation like '%insert%'
ORDER BY [Current LSN] desc) a
--- select into
/*SELECT *
INTO selectIntoTable
FROM numbers
SELECT * FROM sys.fn_dblog(null, null)
WHERE allocunitname like '%selectIntoTable%'
AND operation like '%insert%'
DROP TABLE selectIntoTable
*/
PRINT 'Heap empty no tablock ' + CAST(@heapEmptyNoTablock AS VARCHAR)
PRINT 'Heap empty with tablock ' + CAST(@heapEmptyTablock AS VARCHAR)
PRINT 'Heap non empty no tablock ' + CAST(@heapNonEmptyNoTablock AS VARCHAR)
PRINT 'Heap non empty with tablock ' + CAST(@heapNonEmptyTablock AS VARCHAR)
PRINT 'Heap plus index empty no tablock ' + CAST(@heapIndexEmptyNoTablock AS VARCHAR)
PRINT 'Heap plus index empty with tablock ' + CAST(@heapIndexEmptyTablock AS VARCHAR)
PRINT 'Heap plus index non empty no tablock ' + CAST(@heapIndexNonEmptyNoTablock AS VARCHAR)
PRINT 'Heap plus index non empty with tablock ' + CAST(@heapIndexNonEmptyTablock AS VARCHAR)
PRINT 'Cluster empty ordered no tablock ' + CAST(@clusterEmptyNoTablock AS VARCHAR)
PRINT 'Cluster empty ordered with tablock ' + CAST(@clusterEmptyTablock AS VARCHAR)
PRINT 'Cluster empty unordered no tablock ' + CAST(@clusterEmptyNoTablockUnordered AS VARCHAR)
PRINT 'Cluster empty unordered with tablock ' + CAST(@clusterEmptyTablockUnordered AS VARCHAR)
PRINT 'Cluster non empty no tablock ' + CAST(@clusterNonEmptyNoTablock AS VARCHAR)
PRINT 'Cluster non empty with tablock ' + CAST(@clusterNonEmptyTablock AS VARCHAR)
PRINT 'Cluster plus index empty no tablock ' + CAST(@clusterIndexEmptyNoTablock AS VARCHAR)
PRINT 'Cluster plus index empty with tablock ' + CAST(@clusterIndexEmptyTablock AS VARCHAR)
PRINT 'Cluster plus index non empty no tablock ' + CAST(@clusterIndexNonEmptyNoTablock AS VARCHAR)
PRINT 'Cluster plus index non empty with tablock ' + CAST(@clusterIndexNonEmptyTablock AS VARCHAR)
DROP TABLE numbers
DROP TABLE numbersUnordered
DROP TABLE noKey1
DROP TABLE noKey2
DROP TABLE noKey3
DROP TABLE noKey4
DROP TABLE noKey5
DROP TABLE noKey6
DROP TABLE noKey7
DROP TABLE noKey8
DROP TABLE withKey1
DROP TABLE withKey2
DROP TABLE withKey5
DROP TABLE withKey6
DROP TABLE withKey7
DROP TABLE withKey8
DROP TABLE withKey9
DROP TABLE withKey10
DROP TABLE withKey11
DROP TABLE withKey12