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 Talk Box는 개발자용 자유게시판입니다. 관리자 2006.06.16 24064
262 1등놀이 해도 되나요? ㅎㅎ 2 신기배 2006.06.16 25895
261 제품 다운로드 경험 2 김평철 2006.06.17 22562
260 FreeBSD는 지원할 예정 없나요? 1 손님 2006.06.19 23597
259 .net app 지원도 되나요..?? 1 file 바람따라 2006.06.20 21036
258 Visual-SQL에서 데이타베이스명까지 저장과 ... 2 채광수 2006.06.21 20289
257 cubrid를 잠깐 사용해 보고.. 7 신기배 2006.07.02 23089
256 CUBRID 무료 DBMS 선언에 대한 외부 개발자 코멘트... 정병주 2006.07.05 21225
255 전기 적게 먹는 DBMS 개발은 가능하나요? 4 최원기 2006.07.20 20554
254 "Fedora 5에서 설치 실패" 문제 해결 이민구 2006.07.21 21368
253 decimal(4,1)어케 설정하나요? & 몇가지 불편사항 3 임철수 2006.07.31 21491
252 NHN DB 개발 관련 질문들 김평철 2006.08.01 21036
251 큐브리드 vs. UniSQL 김평철 2006.08.01 25165
250 [기사] 공개SW 유지보수 가이드라인 만들어진다. 정병주 2006.08.08 18964
249 큐브리드 사용 중 개선 되었음 하는 것 5 이영민 2006.08.14 17752
248 큐브리드 최초 웹호스팅??? 1 정병주 2006.08.19 19193
247 귀사의 라이센스 정책을 알고 싶습니다. 1 김광오 2006.09.22 18523
246 큐브리드용 제로보드 4.1 다운로드 1 정병주 2006.10.12 20862
245 '컴퓨터사이언스' 지고 '서비스사이언스' 뜬다 정병주 2006.10.17 18940
244 11/21(화) 무료 교육 참가신청은 여기에... 1 관리자 2006.11.04 18304
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