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
번호 제목 글쓴이 날짜 조회 수
263 "Fedora 5에서 설치 실패" 문제 해결 이민구 2006.07.21 21368
262 "내일을 위한 PHP" PHP Fest 2011 정병주 2011.05.13 25796
261 '컴퓨터사이언스' 지고 '서비스사이언스' 뜬다 정병주 2006.10.17 18940
260 (+)는 무슨의미인가요?? 1 이지은 2021.07.23 7713
259 (+)는 무슨의미인가요?? 9 멍멍거리지마라 2018.05.10 3433
258 (CUBRID 후원) 우분투 사용자 커뮤니티 안내 2 file CUBRID_DEV 2009.05.20 23310
257 (CUBRID후원) 여성개발자모임터 커뮤니티 세미나 CUBRID_DEV 2009.05.20 20163
256 ********큐브리드 오픈소스화 1주년 축하드려요~~!!^^****** 파란나란디 2009.12.09 13198
255 .net app 지원도 되나요..?? 1 file 바람따라 2006.06.20 21036
254 11/21(화) 무료 교육 참가신청은 여기에... 1 관리자 2006.11.04 18304
253 11월 5일은 공개 SW의 날 정병주 2009.09.16 20891
252 1년 축하 드립니다. 리눅스 2009.11.26 11411
251 1등놀이 해도 되나요? ㅎㅎ 2 신기배 2006.06.16 25895
250 1주년 정말 축하드립니다. tro0918 2009.11.27 11525
249 1주년 축하드립니다. 봉단 2009.11.26 11348
248 1주년 축하드립니다. 아이티초짜 2009.11.27 11351
247 1주년을 정말 축하 드리며.. 아기사자 2009.11.26 11408
246 2009 3rd CUBRID Inside를 다녀와서! 2 시난 2009.05.27 36974
245 2010 4th 공개SW 개발자대회 - 1차 기술세미나 정병주 2010.06.30 26406
244 2010 한국 자바 개발자 페스티벌 정병주 2010.06.24 22372
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