Background Image
조회 수 28483 추천 수 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
번호 분류 제목 글쓴이 날짜 조회 수
46 기타 CUBRID 2008 주요 명령어 admin 2008.11.21 30806
45 Install CUBRID기반으로 XE 운영하기 – 설치가이드 file cubebridge 2012.04.13 30933
44 PHP apache, PHP 설치하기 - LINUX file 남재우 2011.03.08 31308
43 Install CUBRID 2008 을 하나의 머신에 여러번 설치하기(multi instance) admin 2008.11.21 31459
42 기타 CUBRID 매니저 R3.1에서 웹호스팅 서버의 CUBRID R2.1 접속하는 방법 (큐브리드 매니저에서 다른 버전의 큐브리드 서버 접속 방법) file admin 2011.07.14 31509
41 Install CUBRID 설치 및 매니저 구동하기(CUBRID 2008 R1.x) CUBRID_DEV 2009.07.18 31532
40 PHP MySQL,PHP 기반에서 CUBRID,PHP 기반으로 포팅하기 시난 2009.07.02 32190
39 Java SELECT ~ FOR UPDATE 대체 방법 손승일 2009.12.30 32381
38 기타 대량의 데이터 입력 방법 admin 2008.11.21 32655
37 기타 CUBRID 데이터베이스와 연동하여 Qt어플리케이션 개발하기 - 1 김대진 2010.01.14 32878
36 기타 제로보드 XE 사용하기 file admin 2008.11.21 33069
35 Linux cron을 이용한 백업 자동화 admin 2009.04.01 33122
34 기타 CUBRID 관련 유용한 기술 자료... 정병주 2010.02.19 33462
33 기타 CUBRID 2008 + XE 설치 가이드 [R1.x] Prototype 2009.03.13 34326
32 Java SQuirreL SQL Client에서 CUBRID 사용하기 3 Prototype 2009.04.18 34534
31 기타 자동증가 속성 사용 방법 및 주의 사항 남재우 2010.02.26 35688
30 기타 CUBRID와 타 데이터베이스 기능 비교 9 admin 2008.11.21 36163
29 Java log4jdbc를 사용한 JDBC 로그 분석 시난 2009.07.02 36394
28 Linux CUBRID 2008 사용법 admin 2008.11.21 36762
27 PHP LINUX에서 PHP 사용하기 - phpize를 이용한 설치 1 admin 2008.11.21 37461
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