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
번호 분류 제목 글쓴이 날짜 조회 수
126 Java CUBRID에서 log4sql을 사용하자 정병주 2009.06.12 44305
125 기타 Oracle의 SYS_CONNECT_BY_PATH 함수 흉내내기 CUBRID_DEV 2009.06.15 26530
124 PHP cubrid_fetch_all 함수 추가하기 2 남재우 2009.06.16 20828
123 PHP CUBRID_기술문서_CUBRID PHP 함수 unisql_ 계열 cubrid_로 변환하기 file 남재우 2009.06.23 22355
122 CCI/DB API CCI-API 사용 예제 file 남재우 2009.07.01 25103
121 CCI/DB API CCI-API 에서 OID 사용 예제 file 남재우 2009.07.01 24861
120 ODBC/OLEDB ODBC드라이버를 이용한 2개 이상의 Statement 사용방법. file seongjoon 2009.07.02 23644
119 Java log4jdbc를 사용한 JDBC 로그 분석 시난 2009.07.02 36394
118 PHP MySQL,PHP 기반에서 CUBRID,PHP 기반으로 포팅하기 시난 2009.07.02 32190
117 기타 에러 메시지(error) 설명 및 조치 가이드 file CUBRID_DEV 2009.07.11 24454
116 Install CUBRID 설치 및 매니저 구동하기(CUBRID 2008 R1.x) CUBRID_DEV 2009.07.18 31532
115 Java JavaSP SampleCode(Pivot기능) cubebridge 2009.07.28 27554
114 Windows eclipse에서 python 및 CUBRID broker_log_top 사용하기 cubebridge 2009.07.28 27272
113 기타 CUBRID2008 실행계획 분석하기 file cubebridge 2009.07.28 15339
112 기타 CUBRID2008데이터타입, 함수와 힌트사용법 및 예약어 cubebridge 2009.07.28 18844
111 기타 CUBRID주요 사용 함수 및 연산자 비교 cubebridge 2009.07.28 23456
110 기타 CUBRID2008 쿼리 작성예제 cubebridge 2009.07.28 24905
109 Install CUBRID 2008 + Textyle 설치 가이드 3 1 Prototype 2009.07.29 18287
108 Java CUBRID GLO 사용하기 - JDBC 손승일 2009.08.15 23493
107 기타 CUBRID 스캔 이해하기 손승일 2009.08.15 15116
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