DBCC show_statistics 설명

2019. 9. 20. 15:59SQL Server

DBCC show_statistics 설명

***********************************

DBCC SHOW_STATISTICS  는 테이블 또는 인덱싱 된 뷰에 대한 현재 쿼리 최적화 통계를 표시합니다. 기본적으로 SQL Server가 실행 계획을 생성하는 데 사용할 통계 또는 데이터 요약을 보여줍니다.

다음과 같은 Table을 만들었습니다.

CREATE Table tblAuthors

(

   Id int identity primary key,

   Author_name nvarchar(50),

   country nvarchar(50)

)

클러스터 인덱스는 자동으로 생성이 되지만, 다음과 같이 Non-Clustered Index를 생성 합니다.

USE Test

GO

CREATE NONCLUSTERED INDEX [IX_tblAuthors] ON [dbo].[tblAuthors]

(

     [ID] ASC

,    [Author_name] ASC

,    [country] ASC

)

        WITH

        (       PAD_INDEX  = OFF

               , STATISTICS_NORECOMPUTE  = OFF

               , SORT_IN_TEMPDB = OFF

               , IGNORE_DUP_KEY = OFF

               , DROP_EXISTING = OFF

               , ONLINE = OFF

               , ALLOW_ROW_LOCKS = ON

               , ALLOW_PAGE_LOCKS  = ON

        ) ON [PRIMARY]

GO

 

랜덤 데이터를 12,000개 정도 넣어 줍니다.

Declare @Id int

Set @Id = 1

While @Id <= 12000

Begin

   Insert Into tblAuthors values ('Author - ' + CAST(@Id as nvarchar(10)),

              'Country - ' + CAST(@Id as nvarchar(10)) + ' name')

   Print @Id

   Set @Id = @Id + 1

End

대략 아래와 같은 데이터들로 12,000개가 생성 됩니다.

 

dbcc show_statistics를 실행하고 출력을 볼 수 있습니다. 일부 행을 삽입했지만 출력이 표시되지 않습니다.

 

DBCC SHOW_STATISTICS (tblAuthors,[IX_tblAuthors])

GO

 

update statistics with fullscan 실행 후, DBCC SHOW_STATISTICS를 다시 실행하면 다음과 같이 삽입한 결과에 대한 내용이 나옵니다.

 

update statistics tblAuthors with fullscan

dbcc show_statistics('tblAuthors','IX_tblAuthors')

GO

 

각 항목에 대한 설명은 참조자료를 확인 하십시오.

 

[Reference]

What DBCC SHOW_STATISTICS tells me (https://blogs.msdn.microsoft.com/dbcc_show_statistics/2015/03/06/what-dbcc-show_statistics-tells-me/ )