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
번호 제목 글쓴이 날짜 조회 수
123 11월 5일은 공개 SW의 날 정병주 2009.09.16 20891
122 큐브리드 인사이드에... 2 초보대왕 2009.09.16 12535
121 오픈소스SW 저작권 인식제고를 위한 이벤트 정병주 2009.09.15 40501
120 log4sql에서 cubrid를 정식으로 지원하네요.(9월4일 업데이트) 1 미스트 2009.09.07 15273
119 NAVER iDoCode 대상 - CUBRID manager broker & web manager 사용 후기 1 file 시난 2009.09.04 19791
118 큐브리드 사이트 게시판 기능 버그인가요? 1 삐따기 2009.08.29 14027
117 넋두리... 4 2~40자? 2~40byte? 2009.08.22 13823
116 CUBRID 프로젝트 8월 소식지~ 1 CUBRID_DEV 2009.08.17 13332
115 여차저차 우분투에 설치 성공했습니다(감격) 터프키드 2009.07.31 16011
114 메뉴얼에 예제를 많이 넣어 주셨으면 ... rgboard 2007.07.10 39945
113 설치를 한 후, .. Hi. Cubrid 2007.06.02 14572
112 JDBC 드라이버만 다운로드 가능했으면... 2 멀더 2008.08.12 16450
111 linux에서 다운로드 지원에 대해.. 3 전창훈 2007.11.30 14880
110 다운좀 편하게 합시다 2 나그네 2007.11.29 15479
109 다음 버젼에서 바라는 점. 1 송우진 2007.09.28 15059
108 저장 프로시져의 기능을 좀더 편하게 구축할수 있으면.. 1 윤병진 2007.09.03 15603
107 질의편집기 관련 건의 1 madcat 2007.08.14 14161
106 SPRING+IBATIS+DWR 포팅 후기 3 장비맨 2009.04.23 20672
105 windows 2008 + CUBRID 2008 R 1.4 + ZBXE 1.2.0 + Autoset 4.3.2 설치 후기 1 file 윤희서 2009.04.02 32391
104 Windows 2003 + CUBRID 2008 R 1.4 + ZBXE 1.2.0 + Autoset 4.3.2 설치 후기 2 윤희서 2009.03.20 26949
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 14 Next
/ 14

Contact Cubrid

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