[쿼리성능비교테스트]where절에서 타입이 다른경우 비교시... varchar2 컬럼을 숫자와 비교시 묵시적 형변환일어난다.
myemp1은 2000만건의 레코드가 있다. deptno 컬럼은 아래처럼 인덱스를 만들고...
create index idx_myemp1_deptno on myemp1(deptno)
alter index idx_myemp1_deptno invisible
-- 인덱스를 숨기니 20초 이상 걸린다.
select count(*) from myemp1 where deptno = '1'
alter index idx_myemp1_deptno visible
-- 인덱스 태우니 1초안팎
select count(*) from myemp1 where deptno = '1'
-- 아래는 문제 쿼리.. deptno가 varchar2 TYPE 이므로 to_number(deptno)가 되어
-- 인덱스가 있더라도 사용할 수 없게된다.
-- where절에서 문자, 숫자 타입이 다른것이 비교되면 오라클은 숫자로 형변환 한다는 것을 잊지말자.
select count(*) from myemp1 where deptno = 1
결국 아래와 같은 쿼리문이 된다.
select count(*) from myemp1 where to_number(deptno) = 1 --묵시적 형변환으로 인한...
myemp1은 2000만건의 레코드가 있다. deptno 컬럼은 아래처럼 인덱스를 만들고...
create index idx_myemp1_deptno on myemp1(deptno)
alter index idx_myemp1_deptno invisible
-- 인덱스를 숨기니 20초 이상 걸린다.
select count(*) from myemp1 where deptno = '1'
alter index idx_myemp1_deptno visible
-- 인덱스 태우니 1초안팎
select count(*) from myemp1 where deptno = '1'
-- 아래는 문제 쿼리.. deptno가 varchar2 TYPE 이므로 to_number(deptno)가 되어
-- 인덱스가 있더라도 사용할 수 없게된다.
-- where절에서 문자, 숫자 타입이 다른것이 비교되면 오라클은 숫자로 형변환 한다는 것을 잊지말자.
select count(*) from myemp1 where deptno = 1
결국 아래와 같은 쿼리문이 된다.
select count(*) from myemp1 where to_number(deptno) = 1 --묵시적 형변환으로 인한...
| 12-27 | 2380 | |||
| 12-11 | 1727 | |||
| 53 | 03-15 | 1548 | ||
| 52 | 01-31 | 1641 | ||
| 51 | 01-31 | 2196 | ||
| 50 | 01-31 | 1300 | ||
| 49 | 01-19 | 1602 | ||
| 48 | 01-11 | 1443 | ||
| 47 | 01-03 | 1991 | ||
| 46 | 12-27 | 2380 | ||
| 45 | 12-19 | 1710 | ||
| 44 | 12-14 | 1688 | ||
| 43 | 12-11 | 1727 | ||
| 42 | 12-09 | 1371 | ||
| 41 | 12-01 | 1596 | ||
| 40 | 12-01 | 1770 | ||
| 39 | 12-01 | 1248 | ||
댓글 없음:
댓글 쓰기