Background Image
조회 수 1543 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
5월 큐브리드 정기교육 2일차 개발자 쿼리 튜닝 교육 문제입니다.

--준비
drop table if exists t1;
create table t1 (col1 int, col2 int, col3 int, col4 int, col5 varchar(100), col6 date);
insert into t1 select rownum, 1,mod(rownum,5), mod(rownum,1000), rownum, sysdate - mod(rownum,100000)
                  from table({0,1,2,3,4,5,6,7,8,9}) a, table({0,1,2,3,4,5,6,7,8,9}) b, table({0,1,2,3,4,5,6,7,8,9}) c, table({0,1,2,3,4,5,6,7,8,9}) d, table({0,1,2,3,4,5,6,7,8,9}) e, table({0,1,2,3,4,5,6,7,8,9}) f 
                  limit 1000000;

insert into t1 select rownum, 2,mod(rownum,5), mod(rownum,1000), rownum, sysdate - mod(rownum,100000)
                  from table({0,1,2,3,4,5,6,7,8,9}) a, table({0,1,2,3,4,5,6,7,8,9}) b, table({0,1,2,3,4,5,6,7,8,9}) c, table({0,1,2,3,4,5,6,7,8,9}) d, table({0,1,2,3,4,5,6,7,8,9}) e, table({0,1,2,3,4,5,6,7,8,9}) f 
                  limit 1000;

create index idx1 on t1(col1);
create index idx2 on t1(col6);
create index idx3 on t1(col3,col4,col5);
create index idx4 on t1(col2);

--통계정보 갱신
update statistics on t1 with fullscan;

--실행계획 및 통계 정보확인
set trace on;

show trace;

--스키마 확인
;sc t1

-- 다음 질의를 11.2버전에서 튜닝하세요. (사용된 t1 테이블이 모두 다른 테이블이라고 가정. 동일테이블이기 때문에 재작성 가능한 경우는 고려하지 않는다.)
1. (기대 속도 : 1 sec) 
  select col1
         ,col2
         ,col4
         ,2 max_col
         ,(select col6 from t1 where col1 = a.col1 limit 1) col6
         ,decode(col2, 1, 'yes', 'no') yesno
   from t1 a
  where col4 = 1
    and exists (select 1 from t1 where col4 = 1 and col1 = a.col1)
union all
  select 
          col1
         ,col2
         ,col4
         ,(select max(col1) from t1 where col3 = a.col3) max_col
,(select col6 from t1 where col1 = a.col1 limit 1) col6
         ,decode(col2, 1, 'yes', 'no') yesno
   from t1 a
  where col2 = 1
    and exists (select 1 from t1 where col4 = 1 and col1 = a.col1);

List of Articles
번호 제목 글쓴이 날짜 조회 수
143 큐브리드 1주년 진심으로 축하드립니다. 로냐르 2009.11.27 11392
142 1주년 정말 축하드립니다. tro0918 2009.11.27 11525
141 오픈소스 큐브리드 한살 축하합니다. onionmen 2009.11.26 11393
140 축하드립니다 써니v 2009.11.26 11487
139 1년 축하 드립니다. 리눅스 2009.11.26 11411
138 축하드립니다 ^^ 마누 2009.11.26 11848
137 1주년을 정말 축하 드리며.. 아기사자 2009.11.26 11408
136 진전한 오픈소스DB의 세상에서 빛나기를~~ 불사조 2009.11.26 11406
135 국산 객체관계형 DBMS로서 최고가 되는 그날을 기대합니다. 오픈소스 1주년 축하드립니다. kgwlover 2009.11.26 12159
134 1주년 축하드립니다. 봉단 2009.11.26 11348
133 큐브리드 오픈소스화 1주년 기념 이벤트 156 1 file admin 2009.11.25 70988
132 Cubrid와의 첫 번째 만남 1 ping 2009.11.10 11387
131 CUBRID 다운로드가 6만 건을 넘었습니다!!! 정병주 2009.11.03 42452
130 DB 링크 가능한가요 ? 1 용이 2009.11.01 13159
129 파란무료전자세금계산서 itsme 2009.10.20 13498
128 GNU 무료 모델링 툴 DB Designer 소개 1 정순영 2009.10.01 18854
127 NHN DeView 2009 영상 자료 file 정병주 2009.09.26 37653
126 오과장님 DeView 2009 가다 정병주 2009.09.22 40547
125 Sphinx 라는 검색엔진을 지원했으면 합니다. 2 정순영 2009.09.18 19656
124 PHP 로컬 검색 엔진 Orca Search을 큐브리드가 지원되었으면... 2 정순영 2009.09.16 15538
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 ... 14 Next
/ 14

Contact Cubrid

대표전화 070-4077-2110 / 기술문의 070-4077-2113 / 영업문의 070-4077-2112 / Email. contact_at_cubrid.com
Contact Sales