조회 수 30051 추천 수 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
번호 분류 제목 글쓴이 날짜 조회 수
67 기타 조인 방법(Join Method) 설명 file 웁쓰 2009.12.31 29872
66 기타 스칼라 서브쿼리 사용 가이드 웁쓰 2009.12.31 29977
» 튜닝 [질의튜닝]order by desc가 인덱스 타게 하려면 admin 2011.07.14 30051
64 Java QuantumDB Eclipse Plugin을 사용하여 CUBRID연동하기 2 cubebridge 2009.10.06 30528
63 Linux 복제 따라하기 admin 2008.11.21 30590
62 Install CUBRID Ubuntu Launchpad Installation 방법 file 정만영 2011.07.19 31013
61 CCI/DB API embedded sql 사용법 admin 2008.11.21 31080
60 Linux CUBRID서비스 시스템 재구동시 자동 구동/종료 방법 1 admin 2009.04.01 31116
59 Install CUBRID 에 텍스트큐브 설치하기 file inureyes 2009.12.31 31141
58 기타 CUBRID와 타DBMS의 python 사용방법 비교 cubebridge 2009.05.19 31225
57 튜닝 CUBRID 2008 R4.0의 커버링 인덱스(covering index)는 무엇인가? file admin 2011.07.14 31245
56 Windows CUBRID2008R2.0 Windows BACKUP 자동화 설정하기 정만영 2009.08.17 31459
55 기타 데이터베이스 생성하기 file 남재우 2011.03.07 31503
54 Install CUBRID 설치 및 매니저 구동하기(CUBRID 2008 R2.0) CUBRID_DEV 2009.08.18 31543
53 PHP IIS에서 PHP, CUBRID 사용하기 file 남재우 2010.04.19 31627
52 Install CUBRID 설치 안내 - LINUX 남재우 2011.03.08 31746
51 Install CUBRID Windows버전 삭제 및 재설치 실패시 강제 삭제하는 방법입니다. admin 2011.07.14 31826
50 Install APC_Install-tools 구성 및 설치 방법 file Prototype 2009.03.13 31852
49 기타 CUBRID에서의 BLOB/CLOB 타입 사용법 cubebridge 2011.03.08 32077
48 PHP apache, PHP 설치하기 - LINUX file 남재우 2011.03.08 32483
Board Pagination Prev 1 2 3 4 5 6 7 8 9 Next
/ 9

Contact Cubrid

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

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

나눔고딕 사이트로 가기

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5