[쿼리성능비교테스트]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 | 2948 | |
![]() | ![]() ![]() | 12-11 | 2158 | |
53 | ![]() ![]() | 03-15 | 2029 | |
52 | ![]() ![]() | 01-31 | 2150 | |
51 | ![]() ![]() | 01-31 | 3130 | |
50 | ![]() ![]() | 01-31 | 1664 | |
49 | ![]() ![]() | 01-19 | 1984 | |
48 | ![]() ![]() | 01-11 | 1850 | |
47 | ![]() ![]() | 01-03 | 2488 | |
46 | ![]() ![]() | 12-27 | 2948 | |
45 | ![]() ![]() | 12-19 | 2064 | |
44 | ![]() ![]() | 12-14 | 2028 | |
43 | ![]() ![]() | 12-11 | 2158 | |
42 | ![]() ![]() | 12-09 | 1669 | |
41 | ![]() ![]() | 12-01 | 1893 | |
40 | ![]() ![]() | 12-01 | 2149 | |
39 | ![]() ![]() | 12-01 | 1533 |
댓글 없음:
댓글 쓰기