Background Image
조회 수 28456 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

테스트 버전: CUBRID 2008 R3.0 (8.3.0.0337)

 

요약
CUBRID에서는 Primary key를 생성하면 asc 순으로 생성됩니다. 따라서 desc로 order by를 하게 되면 index를 타지 못하게 되죠. Primary key 생성 시 desc로 별도로 생성하지는 못하고요, primary key를 desc 순으로 생성하려면, unique index를 desc로 생성하여야 합니다.

이렇게 하면 order by desc 시 추가된 unique index 를 사용할 수 있게 됩니다.

 

테스트

먼저 테이블을 생성하고 데이터를 넣습니다.

 

csql> create table member_tbl(id int primary key, name varchar(10));
csql> insert into member_tbl values (1, 'marry'), (2, 'john'), (3,'billy'), (4, 'willy');
csql> ;x
csql> ;plan simple
csql> select * from member_tbl order by id for orderby_num() between 1 and 2;
Query plan:
 Index scan(member_tbl member_tbl, pk_member_tbl_id, member_tbl.id range (-2147483648 ge_inf max))
           id  name
===================================
            1  'marry'
            2  'john'

 

여기서 desc로 조회한다면 (최신 회원가입 순으로 조회가 대부분) 다음과 같이 되는데, 인덱스를 타지 않고 순차 검색(sequential scan)을 하는 것을 확인할 수 있습니다.

 

csql> select * from member_tbl order by id desc for orderby_num() between 1 and 2;
Query plan:
 Sort(order by)
    Sequential scan(member_tbl member_tbl)
           id  name
===================================
            4  'willy'
            3  'billy'

 


이제 원하는 것은, desc로 unique key를 생성하여 desc 로 조회할 때도 인덱스를 타게 하는 것입니다.
primary key를 desc로 바로 생성하지는 않으므로, unique 인덱스를 추가로 생성합니다.

 

 

csql> create unique index idx_u_member_tbl_id on member_tbl(id desc);

 

이제 desc로 질의 수행 시 idx_u_member_tbl_id 인덱스를 타는 것을 확인할 수 있습니다.

 

csql> select * from member_tbl order by id desc for orderby_num() between 1 and 2;
Query plan:
 Index scan(member_tbl member_tbl, idx_u_member_tbl_id, member_tbl.id range (-2147483648 ge_inf max))
           id  name
===================================
            4  'willy'
            3  'billy'

TAG •

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
» 튜닝 [질의튜닝]order by desc가 인덱스 타게 하려면 admin 2011.07.14 28456
45 튜닝 CUBRID 2008 R4.0의 커버링 인덱스(covering index)는 무엇인가? file admin 2011.07.14 29880
44 튜닝 SNS 유형 서비스에서 CUBRID와 MySQL 조회 성능 비교 file admin 2011.07.14 21187
43 기타 CUBRID 볼륨 공간 재사용률 비교 - 2008 R3.1 vs. 2008 R4.0 file admin 2011.07.14 16554
42 기타 CUBRID 2008 R4.0 파라미터 변경 사항 (일부) file admin 2011.07.14 13154
41 기타 CUBRID 2008 R4.0 GA 버전의 주요 기능만 요약한 PPT 문서 file admin 2011.07.14 15460
40 기타 동시 접속자에 따른 파라미터 설정 admin 2011.07.14 25680
39 기타 CUBRID 매니저 R3.1에서 웹호스팅 서버의 CUBRID R2.1 접속하는 방법 (큐브리드 매니저에서 다른 버전의 큐브리드 서버 접속 방법) file admin 2011.07.14 31507
38 기타 [주의사항] CUBRID에서의 BLOB/CLOB 사용시 백업 및 복구에 대한 주의 점 admin 2011.07.14 52555
37 기타 자주 발생하는 큐브리드(cubrid) 에러 메시지 정리 admin 2011.07.14 81365
36 Install CUBRID Ubuntu Launchpad Installation 방법 file 정만영 2011.07.19 29604
35 Install LINUX CUBRID 4.0 매니저 설치방법 file 정만영 2011.07.19 23653
34 기타 select .. for update 처리를 위한 Stored Procudure 등록 및 사용법 남재우 2011.12.10 24870
33 Install CUBRID기반으로 XE 운영하기 – 설치가이드 file cubebridge 2012.04.13 30929
32 Java CUBRID와 Oracle의 Clob 타입 사용 방법 비교. seongjoon 2012.06.30 54549
31 ODBC/OLEDB VB에서 CUBRID ODBC/OLEDB 사용하는 방법 및 샘플코드. file seongjoon 2012.06.30 26917
30 기타 HA 환경 구성 시 데이터 복제 지연이 발생하는 경우 ECHO(7) port를 확인하자. 손승일 2012.11.29 26440
29 PHP Apache, PHP 설치 방법 file 이용미 2013.05.16 41246
28 PHP phpize를 이용한 PHP 모듈 연동 방법(CUBRID2008 R4.3 버전) file 이용미 2013.05.16 20853
27 Linux CUBRID Linux 부팅시 자동시작 서비스 설정 방법 정만영 2013.09.16 25454
Board Pagination Prev 1 2 3 4 5 6 7 8 9 Next
/ 9

Contact Cubrid

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