쿼리플랜 문의

by asteroid posted Jan 23, 2009
다음과 같은 테이블을 생성하고 쿼리를 수행 해보았습니다.

create table tb ( bdate date, val varchar(100) );
create index ix_tb on tb ( bdate );
-- 각 날짜에 대해 약 십만개의 로우 입력 = 365 * 100,000 = 약 36,500,000 로우

-- 1) 날짜 조건을 범위로 주었을 때
select bdate from tb where bdate >= to_date('20090101', 'yyyymmdd') and bdate <= to_date('20090110', 'yyyymmdd');

-- 2) 날짜 조건을 equal로 주었을 때
select bdate from tb where bdate = to_date('20090101', 'yyyymmdd')
   or basic_date = to_date('20090102', 'yyyymmdd')
   or basic_date = to_date('20090103', 'yyyymmdd')
   or basic_date = to_date('20090104', 'yyyymmdd')
   or basic_date = to_date('20090105', 'yyyymmdd')
   or basic_date = to_date('20090106', 'yyyymmdd')
   or basic_date = to_date('20090107', 'yyyymmdd')
   or basic_date = to_date('20090108', 'yyyymmdd')
   or basic_date = to_date('20090109', 'yyyymmdd')
   or basic_date = to_date('20090110', 'yyyymmdd');

위의 조건에서 각 쿼리에 대한 수행속도 차이가 많이 나서 쿼리플랜을 확인 해봤습니다.

1) 의 쿼리플랜은
    subplan: iscan
                 class: tb node[0]
                 index: ix_tb term[0]
                 cost:  fixed 257(0.0/257.0) var 88873(380.7/88492.0) card 126911

2) 의 쿼리플랜은
    subplan: iscan
                 class: tb node[0]
                 index: ix_tb term[0]
                 cost:  fixed 81(0.0/81.0) var 13828(117.5/13710.0) card 1

와 같이 코스트 차이가 많이 나는데요, 왜 이런 수행속도의 차이가 발생하는지 알고싶네요.
그리고 같은 데이터에 대해 같은 인덱스 스캔을 수행하는데 보는 것과 같이 로우 수와 카디널리티의 차이가 많이 나는데요, 이런 결과가 발생하는 이유도 궁금합니다.



Articles

11 12 13 14 15 16 17 18 19 20