Background Image
조회 수 1523 추천 수 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
번호 제목 글쓴이 날짜 조회 수
263 큐브리드 다운로드 4만건 돌파 기념 간식 배달 이벤트 - 축하 메시지 남기기 ^^ 291 2 file admin 2009.05.13 219640
262 큐브리드 제품 다운로드 10만건 돌파기념 축하 메시지를 남겨주세요 87 file admin 2010.12.15 101176
261 큐브리드 오픈소스화 1주년 기념 이벤트 156 1 file admin 2009.11.25 70977
260 NHN DeView 2008 후기 - CUBRID 2008 1 정병주 2008.11.25 56413
259 큐브리드 매니저 2008 R2 - 맛뵈기 프리뷰 정병주 2009.06.16 49179
258 큐브리드 면접 문제들... 19 김평철 2007.05.04 45386
257 큐브리드양을 소개합니다. 1 정병주 2009.04.07 44695
256 Mysql 그리고 큐브리드... 1 들뿔 2007.04.11 44531
255 오픈소스 SW 저작권 인식제고를 위한 논문 공모전 정병주 2010.07.02 42830
254 CUBRID 다운로드가 6만 건을 넘었습니다!!! 정병주 2009.11.03 42452
253 오픈소스SW 저작권 인식제고를 위한 공모전 3 정병주 2009.05.22 41812
252 오과장님 DeView 2009 가다 정병주 2009.09.22 40546
251 오픈소스SW 저작권 인식제고를 위한 이벤트 정병주 2009.09.15 40500
250 메뉴얼에 예제를 많이 넣어 주셨으면 ... rgboard 2007.07.10 39945
249 전자정부 표준프레임워크 오픈커뮤니티 창립세미나 안내 정병주 2010.08.17 39653
248 큐브리드 매니저 splash 이미지 변경 예정입니다. ^^ 4 file 정병주 2008.12.20 39266
247 NHN DeView 2009 영상 자료 file 정병주 2009.09.26 37651
246 2009 3rd CUBRID Inside를 다녀와서! 2 시난 2009.05.27 36970
245 구인: 자바개발자를 구합니다 정병주 2008.05.06 36433
244 남궁성님의 Java 동영상 강의 문학청년 2009.12.24 34545
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 14 Next
/ 14

Contact Cubrid

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