이 페이지 http://technet.microsoft.com/en-us/library/dd425070(v=sql.100).aspx 에 대한 클레임을 테스트하는 스크립트를 작성했는데 최소 로깅이 발생하거나 발생하지 않습니다.
이 스크립트를 사용하여 각기 다른 유형의 인서트에 대한 로그 레코드 길이의 합은 다음과 같습니다.
- 힙 비우기 tablock 60000
- tablock 56000으로 비어있는 힙
- 비어 있지 않은 힙 비 탭록 60000
- tablock 56000으로 비어 있지 않은 힙
- 힙 플러스 색인이 비어 있지 않음 탭록 없음 126188
- tablock 114188을 사용하여 힙 플러스 색인이 비어 있음
- 힙 플러스 색인 비 공백 없음 탭록 138696
- tablock 112000을 사용하여 힙 플러스 색인이 비어 있지 않음
- 클러스터 비우기에서 탭록 없음 주문 6464
- Tablock 56168과 함께 주문 된 클러스터 비어 있음
- 클러스터가 비어 있으며 순서가 없습니다. 탭록 없음 73388
- Tablock 65388을 사용하여 클러스터 비 정렬 비 순서
- 클러스터 비 비어 있음 탭록 없음 63912
- 탭 잠금이있는 비 클러스터 클러스터 55944
- 클러스터 더하기 인덱스가 비어 있지 않음 탭록 없음 124336
- 탭 잠금이있는 클러스터 플러스 인덱스가 비어 있음 108336
- 클러스터 더하기 인덱스 비 비어 없음 tablock 123876
- Tablock 107924를 사용하여 클러스터 + 색인이 비어 있지 않음
이 숫자 중 일부는 technet 페이지의 표와 일치하지 않는 것 같습니다. 특히:
- 비어있는 테이블과 비어 있지 않은 테이블에 삽입하는 경우 로깅에는 차이가 없지만 탭이없는 비어 있지 않은 클러스터에 삽입 할 때 전체 로깅이 있어야한다고 페이지에서 주장합니다.
- tablock을 사용하여 및를 사용하여 힙 또는 클러스터에 삽입하면 로깅이 줄어드는 것처럼 보이지만 페이지에 전체 로깅이 있어야한다고 주장합니다.
- 삽입의 SELECT INTO 메소드를 사용하는 경우 fn_dblog에 조작이 삽입 된 행이 없지만 페이지에이 메소드가 테이블에 설명 된 동작을 가져야하는 벌크로드 조작으로 나열됩니다.
참고로 이것은 SQL Express 데이터베이스에서 실행되었으며 DBCC TRACESTATUS (610)를 실행하면 모든 것이 0입니다.
왜 내가 이러한 불일치를 볼 수 있는지 설명해 줄 수 있습니까?
참고로 코드는 다음과 같습니다.
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