1. 활용예시를 통한 SQL Server 2012 의
향상된 프로그래밍 기능 엿보기
DB 팀
임현수
2. 개요
향상된 프로그래밍 기능 P a rt 1
- 페이징 (O F FS E T/FE TC H )
- 효율적인 채번 (S E Q U E N C E )
- 경험치 비교 (An alytic F u n c tio n s )
향상된 프로그래밍 기능 P a rt 2
- 집계처리 가속화 (C o lu m n S to re In d e x)
- 쿼리분석기 1 20% 활용
- 유용한 함수
마무리
7. 페이징 (ro w_n u m b e r()) B e fo re
select x.*
from (
select
top ( @PageNo * @PageSize)
, row_number() over (order by col01 ) seqNo
, col01, col02
from dbo.tab01 with (readuncommitted)
where col01 > @startArticleNo
order by col01 ) x
where x.seqNo between (@PageNo-1) * @PageSize and @PageNo * @PageSize -1
order by x.col01;
8. 페이징 (O F F S E T/F E TC H )
A fte r
select *
from dbo.tab01 wtih (nolock)
where col01 >= @startArticleNo
order by col01
offset (@PageNo-1)*@PageSize rows
fetch next @PageSize rows only;
9. 페이징 ( 정리 )
항목 Row_number() OFFSET/FETCH
구문 복잡도 복잡 (11 lines) 단순 (6 lines)
성능 I/O 부하 동일
성능 개선효과는 없으나 ,
의견
개발생산성 증대
11. 효율적인 채번 ( 임시 테이블 )
B e fo re
-- 임시테이블 생성
create table SeqNo_tab (SeqNo int);
Insert into SeqNo_tab values (1);
-- 채번 성능 테스트
declare @seqval int = 0, @cnt int = 0;
while (@cnt <= 1000000)
begin
update SeqNo_tab set @seqval= SeqNo = SeqNo + 1;
set @Cnt = @Cnt + 1;
end
12. 효율적인 채번 (S e q u e n c e )
A fte r
-- 시퀀스 생성
Create sequence SeqNo_cache10
Start with 1
Increment by 1
Cache 10;
go
-- 채번 성능 테스트
declare @seqval int = 0, @Cnt int = 0;
while (@Cnt <= 1000000)
begin
SELECT @seqval = next value for SeqNo_cache10;
set @Cnt = @Cnt + 1;
end
13. 효율적인 채번 ( 정리 )
항목 임시테이블 SEQUENCE
구문 복잡도 유사
성능 21 초 (Nocache) or
3 분 49 초
(100 만건 ) 9 초 (Cache)
약 25 배 성능 개선 ,
의견
범위 처리 함수 제공
16. 경험치 비교 (s e lf j in )
o
B e fo re
select a.seqNo, a.CompareValue, b.CompareValue
from tab_01 a with (readuncommitted)
left outer join tab_01 b with (readuncommitted) on a.seqNo -1 = b.seqNo
order by a.seqNo
42 pages
17. 경험치 비교 (An alytic F u n c tio n : LAG )
A fte r
select
seqNo
, compareValue
, lag(compareValue, 1, 0) over (order by seqNo) as LagValue
from tab_01 with (readuncommitted)
order by seqNo
2 pages
18. 경험치 비교 ( 정리 )
항목 Self join Analytic Func (LAG)
구문 복잡도 유사
성능 42 pages 2 pages
약 21 배 성능 개선 ,
의견
활용 빈도는 낮으나 매우 유용함
22. 집계 쿼리 가속화 ( 정리 )
항목 Rowstore Index Columnstore Index
용량 1,500 MB 270 MB
성능
1 분 19 초 0초
(3500 만건 )
집계를 위한 최적의 솔루션임 .
의견
Columnstore Index 있는 경우 DML 사용 불가
27. 유용한 함수
카테고리 함수 설명
EMONTH() 해당월의 마지막 날짜 반환
날짜함수
날짜 / 시간 , 숫자값을 원하는 포맷으로
FORMAT()
변환
IIF() CASE 구문과 동일한 기능
비교함수
CHOOSE() Index 위치의 변수값을 돌려주는 구문
함수내의 문자열을 하나의 문장으로 연
CONCAT()
결
문자열함수
TRY_CONVERT() 문자열 -> 날짜로 전환이 가능한지 확인