Background Image
조회 수 1542 추천 수 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
번호 제목 글쓴이 날짜 조회 수
203 Query Browser 미흡한 점 1 GGG특별대원 2011.04.04 23597
202 큐브리드 3.1 다운로드 링크가 잘못되어 있는거 같습니다 1 유니콘 2011.03.16 19721
201 한국DB진흥원 주최 DB Tech seminar 발표자료 file admin 2011.03.01 26520
200 2011 소프트웨어 자산관리 가이드라인 cubrid 2011.02.16 26507
199 레퍼런스 자랑 게시판에 광고글이 있네요 1 유니콘 2011.02.15 15488
198 [도서 소개] 김태용의 JSP 웹 프로그래밍 입문 file cubrid 2011.01.21 22641
197 웹서핑하다보니 큐브리드 관련 뉴스 있어서 올립니다...^^ 1 지니보이 2010.12.28 14760
196 개발자 소스 접근 1 하승수 2010.12.25 16764
195 [좌담회] 자발적 커뮤니티 `SW 두레활동` 확산시켜야 cubrid 2010.12.24 23294
194 큐브리드 제품 다운로드 10만건 돌파기념 축하 메시지를 남겨주세요 87 file admin 2010.12.15 101178
193 큐브리드 + 아파치 + php 설치 및 연동 2 하하보이 2010.12.15 17181
192 외국사용자들에 라이센스가 별도로 있나요? 1 흑묘백묘 2010.11.06 15511
191 Open Source Software Week 2010 행사 cubrid 2010.10.28 21299
190 상단 search 에 검색어에 "(" 또는 ")" 를 입력하면 에러납니다~~ 1 몽삼아 2010.10.13 13338
189 R3.0질문입니다. 2 겜기능되거든 2010.10.07 12271
188 cubrid 3.0 버그. 1 file 코딩하는자아 2010.10.07 12530
187 Q&A 신속한 답변 부탁 드립니다. 1 스마트 2010.09.27 11692
186 국내 최초 오픈소스 SW 법센터 문연다 정병주 2010.09.01 26568
185 전자정부 표준프레임워크 오픈커뮤니티 창립세미나 안내 정병주 2010.08.17 39654
184 큐브리드 활용 개발 용역 모집 정병주 2010.08.06 28728
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