Background Image
조회 수 28478 추천 수 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 •

  1. CUBRID 2008 R4.0 GA 버전의 주요 기능만 요약한 PPT 문서

    Date2011.07.14 Category기타 Byadmin Views15460
    Read More
  2. CUBRID 2008 R4.0 파라미터 변경 사항 (일부)

    Date2011.07.14 Category기타 Byadmin Views13154
    Read More
  3. CUBRID 볼륨 공간 재사용률 비교 - 2008 R3.1 vs. 2008 R4.0

    Date2011.07.14 Category기타 Byadmin Views16555
    Read More
  4. SNS 유형 서비스에서 CUBRID와 MySQL 조회 성능 비교

    Date2011.07.14 Category튜닝 Byadmin Views21188
    Read More
  5. CUBRID 2008 R4.0의 커버링 인덱스(covering index)는 무엇인가?

    Date2011.07.14 Category튜닝 Byadmin Views29883
    Read More
  6. [질의튜닝]order by desc가 인덱스 타게 하려면

    Date2011.07.14 Category튜닝 Byadmin Views28478
    Read More
  7. CUBRID 세미나 자료(개요 및 SQL 활용)

    Date2011.07.14 Category튜닝 Byadmin Views22771
    Read More
  8. apache, php rpm package 생성 시 필요한 rpm 스펙

    Date2011.07.14 CategoryPHP Byadmin Views25236
    Read More
  9. CUBRID Windows버전 삭제 및 재설치 실패시 강제 삭제하는 방법입니다.

    Date2011.07.14 CategoryInstall Byadmin Views29549
    Read More
  10. MySQL,PHP 기반에서 CUBRID,PHP 기반으로 포팅하기(CUBRID 2008 R3.1)

    Date2011.03.30 CategoryPHP By손승일 Views24446
    Read More
  11. phpize 를 이용한 PHP 모듈 설치 - LINUX

    Date2011.03.08 CategoryPHP By남재우 Views23089
    Read More
  12. apache, PHP 설치하기 - LINUX

    Date2011.03.08 CategoryPHP By남재우 Views31308
    Read More
  13. CUBRID에서의 BLOB/CLOB 타입 사용법

    Date2011.03.08 Category기타 Bycubebridge Views30453
    Read More
  14. CUBRID 설치 안내 - LINUX

    Date2011.03.08 CategoryInstall By남재우 Views30414
    Read More
  15. 데이터베이스 생성하기

    Date2011.03.07 Category기타 By남재우 Views29105
    Read More
  16. CUBRID 활용 - 질의 튜닝 사례 중심

    Date2010.12.02 Category기타 Bycubrid Views45962
    Read More
  17. CUBRID Migration Toolkit 튜토리얼

    Date2010.10.22 Category기타 Bycubrid Views30477
    Read More
  18. CUBRID 2008 R3.0 추가기능

    Date2010.09.03 Category기타 Byjanus Views15455
    Read More
  19. 트랜잭션과 LOCK 초급과정

    Date2010.07.01 Category기타 By정만영 Views20760
    Read More
  20. CUBRID DB와 Broker 분리방안

    Date2010.04.28 CategoryLinux By정만영 Views28412
    Read More
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