Background Image
조회 수 1540 추천 수 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 회사의 무궁한 발전을기원하면서 다음을 제안하고싶습니다. 2 전승연 2008.01.10 17033
262 회사소개 -> 협력사에 nhn이 빠져 있어요 ㅎㅎ 1 신기배 2006.11.21 13055
261 홈페이지가 새 옷을 입었네요!! 2 진이 2009.07.14 19714
260 홈페이지 이미지 수정하셔야 할 듯... 1 큐르비드 2014.01.22 10154
259 홈페이지 오류(?) 제보 2 flypig 2010.01.05 12824
258 홈페이지 Cubrid 에서 글씨체 관련이요 1 hane 2022.05.19 295
257 헛...;; 2 secret 혜꽁이양 2009.05.13 6
256 함수 질문입니다. 1 wook 2020.09.14 416
255 한국의 개발자들, 오픈소스를 논하다 12 정병주 2007.06.29 16228
254 한국DB진흥원 주최 DB Tech seminar 발표자료 file admin 2011.03.01 26520
253 하위버전 다운로드 항몫 1 정정미 2022.11.02 220
252 편집 화면이 bit(1)인 경우에도 B' '가 아니라 X' ' 식으로 16진수를 기본으로 채워서 1 날밤샘아님 2010.04.15 11693
251 파란무료전자세금계산서 itsme 2009.10.20 13498
250 큐브리드의 철학은? 5 초보대왕 2008.07.24 29550
249 큐브리드의 오픈소스화 1주년 진심으로 축하의 인사 드립니다~~! 달새벽 2009.12.09 13008
248 큐브리드의 오픈소스 전환 첫돌 기념 이벤트 당첨자 발표 admin 2009.12.11 27037
247 큐브리드의 1주년 진심으로 축하드려요 앙마녀석 2009.12.07 11374
246 큐브리드용 제로보드 4.1 다운로드 1 정병주 2006.10.12 20861
245 큐브리드양을 소개합니다. 1 정병주 2009.04.07 44698
244 큐브리드매니저 관련 문의 2 12345 2024.01.05 101
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