반응형

/**********************************************************************************************
-- Title : [2k5] CHECKSUM을 이용한 해쉬 인덱스
-- Reference : dbrang.com
-- Key word : checksum hash index 체크섬 해쉬 인덱스
**********************************************************************************************/

-- 주. tempdb에서는 ARITHABORT 옵션이 없어서 select checksum() 값이 틀리다.
-- 즉, ARITHABORT 옵션이 설정된 일반 DB에서 처리해야 where절에서 비교된다.
-- tempdb에서 set arithabort on; 옵션은 먹히지 않드라..ㅡㅡ;; 사용할 줄 모르는 것일까???
-- 어쨌든 큰 값의 필드를 대신하여 인덱스를 잡을 때 유용하다.
-- 여기에서는 키값이 크기에 대체키로 활용할 수 있다.

-- 대소문자는 구분 안하는데... ANSI/Unicode는 구분함으로 N에 주의한다.

use adventureworks;
go

drop table product2;
go

select * into product2
from adventureworks.production.product;
go

--check_sum 필드 추가
alter table dbo.product2
add chksum_col as checksum(name);
go

-- check_sum 필드 타입 확인
select type_name(user_type_id) from sys.columns
where object_id = object_id('product2')
and name = 'chksum_col';
go

-- check_sum 필드 인덱싱
create index ik_product2
on product2(chksum_col)
go

--실행 계획 확인(index seek)
set showplan_all on;

select *
from product2
where chksum_col = checksum(N'Bearing Ball')
and name = N'Bearing Ball';

반응형

+ Recent posts