Background Image
?

단축키

Prev이전 문서

Next다음 문서

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

1. 참고사항

1-1. Release Note
  - 8.2.2버전에서 'CACHE <cached_num> / NOCACHE' 기능 추가

CUBRID 2008 Release Note / CUBRID 2008 R2.2 Release Note / 2 What's New in CUBRID 2008 R2.2 / New Features
CUBRIDSUS-1961 Added SERIAL CACHE feature to improve serial performance

A CACHE option is supported, which can cache a specified number of serials when defining SERIAL objects.
--------------------------------------------------------------------------------
CREATE SERIAL order_no
START WITH 10000 INCREMENT BY 2 MAXVALUE 20000
CACHE 100;
--------------------------------------------------------------------------------

1-2. Manual
  - 8.3.x 버전 메뉴얼부터 'ALTER SERIAL ... CACHE <cached_num> / NOCACHE' 기능설명 및 예제 추가
      8.2.1 버전 한글 메뉴얼에는 'ALTER SERIAL ... CACHE <cached_num> / NOCACHE' 관련 설명이 있으나 영문 메뉴얼에는 설명이 없음



2. 'ALTER SERIAL ... CACHE <cached_num> / NOCACHE' ERROR 확인

2-1. 대상 : CUBRID 8.2.2 ~ 8.4.x 버전

2-2. 재현절차

-- CREATE SERIAL
CREATE SERIAL order_no START WITH 10000 INCREMENT BY 2 MAXVALUE 20000 CACHE 3;

-- '<serial_name>' 뒤에 다른 옵션을 주지 않고 단독 옵션으로 'CACHE <cached_num> / NOCACHE' 옵션을 주었을 때
ALTER SERIAL order_no CACHE 5; -- ERROR 발생
ALTER SERIAL order_no NOCACHE; -- ERROR 발생

-- ERROR
ERROR: Specify alter serial option.

-- '<serial_name>' 뒤에 다른 옵션과 함께 'CACHE <cached_num> / NOCACHE' 옵션을 주었을 때
-- 'CACHE <cached_num>'은 정상적인 기능 수행을 하지만 'NOCACHE'는 정상적인 기능 수행을 하지 않음

ALTER SERIAL order_no START WITH 10000 INCREMENT BY 2 MAXVALUE 20000 CACHE 5;
-- '<cached_num>' 값이 5로 바뀜

ALTER SERIAL order_no START WITH 10000 INCREMENT BY 2 MAXVALUE 20000 NOCACHE;
-- '<cached_num>' 값이 0이 되지 않고 5로 유지



3. 해결방법

3-1. 'ALTER SERIAL ... CACHE <cached_num>'
  - '<serial_name>' 뒤에 다른 옵션과 함께 'CACHE <cached_num>' 옵션 사용

ALTER SERIAL order_no INCREMENT BY 1 CACHE 100;

  - db_serial 테이블을 UPDATE 해서 <cached_num> 값을 주면 아래와 같은 문제 발생 (사용하면 안 됨, ALTER SERIAL 사용)
    ① 메모리에 <cached_num> 값을 가지고 있어서 100 → 50 으로 UPDATE 하더라도 DB 재구동 전까지 100 값을 사용

-- CREATE SERIAL
CREATE SERIAL order_no START WITH 1 INCREMENT BY 1 MAXVALUE 100000000 CACHE 100;

-- UPDATE SERIAL <cached_num> : 100 → 50
UPDATE db_serial SET cached_num = 50 WHERE name ='order_no'; -- 사용하면 안 됨

-- db_serial 테이블 SELECT
<00001> name         : 'order_no'
        owner        : db_user
        current_val  : 100 -- 초기 <cached_num> 값대로 100 확인
        increment_val: 1
        max_val      : 100000000
        min_val      : 1
        cyclic       : 0
        started      : 1
        class_name   : NULL
        att_name     : NULL
        cached_num   : 50 -- UPDATE SERIAL Query로 100 → 50 변경

-- tbl 테이블에 ROW 입력 중
...
98 2017-03-08 10:14:55.053
99 2017-03-08 10:14:55.560
101 2017-03-08 10:14:56.067
102 2017-03-08 10:14:56.574
...

-- db_serial 테이블 SELECT
<00001> name         : 'order_no'
        owner        : db_user
        current_val  : 200 -- db_serial 테이블의 <cached_num> 값은 무시하고
                              초기 <cached_num> 값대로 100씩 증가
        increment_val: 1
        max_val      : 100000000
        min_val      : 1
        cyclic       : 0
        started      : 1
        class_name   : NULL
        att_name     : NULL
        cached_num   : 50

    ② 'CACHE → NOCACHE →  CACHE' 사용할 경우 메모리에 남아있던 CACHE 값부터 사용하면서 SERIAL 값 중복 ERROR 발생

-- CREATE SERIAL
CREATE SERIAL order_no START WITH 1 INCREMENT BY 1 MAXVALUE 100000000 CACHE 100;

-- db_serial 테이블 SELECT
<00001> name         : 'order_no'
        owner        : db_user
        current_val  : 100
        increment_val: 1
        max_val      : 100000000
        min_val      : 1
        cyclic       : 0
        started      : 1
        class_name   : NULL
        att_name     : NULL
        cached_num   : 100

-- tbl 테이블에 ROW 입력 중
1 2017-03-08 10:52:15.162
2 2017-03-08 10:52:15.680
3 2017-03-08 10:52:16.186
...



-- UPDATE SERIAL : NOCACHE
UPDATE db_serial SET cached_num = 0 WHERE name ='order_no';

-- db_serial 테이블 SELECT
<00001> name         : 'order_no'
        owner        : db_user
        current_val  : 103
        increment_val: 1
        max_val      : 100000000
        min_val      : 1
        cyclic       : 0
        started      : 1
        class_name   : NULL
        att_name     : NULL
        cached_num   : 0

-- tbl 테이블에 ROW 입력 중
-- NOCACHE가 되면서 db_serial 테이블의 current_val 값부터 SERIAL 값으로 사용
...
78 2017-03-08 10:52:54.113
79 2017-03-08 10:52:54.617
80 2017-03-08 10:52:55.122
101 2017-03-08 10:53:05.224
102 2017-03-08 10:53:05.729
103 2017-03-08 10:53:06.233
...



-- UPDATE SERIAL : CACHE
UPDATE db_serial SET cached_num = 50 WHERE name ='order_no'; -- 사용하면 안 됨

-- db_serial 테이블 SELECT
<00001> name         : 'order_no'
        owner        : db_user
        current_val  : 160
        increment_val: 1
        max_val      : 100000000
        min_val      : 1
        cyclic       : 0
        started      : 1
        class_name   : NULL
        att_name     : NULL
        cached_num   : 50

-- tbl 테이블에 ROW 입력 중
...
158 2017-03-08 10:53:20.873
159 2017-03-08 10:53:21.377
160 2017-03-08 10:53:21.881
81 2017-03-08 10:53:22.386
82 2017-03-08 10:53:22.890
83 2017-03-08 10:53:23.395
...
99 2017-03-08 11:06:08.570
100 2017-03-08 11:06:09.076

SQLException : Operation would have caused one or more unique constraint violations.
               INDEX pk_tbl_cnt(B+tree: 0|133|580) ON CLASS tbl(CLASS_OID: 0|522|5).
               key: 137(OID: 0|541|387).

3-2. 'ALTER SERIAL ... NOCACHE'
  - csql에 sysadm 권한으로 접속해서 db_serial 테이블의 cached_num 값을 0으로 UPDATE Query 수행

UPDATE db_serial SET cached_num = 0, current_val = SERIAL_CURRENT_VALUE(order_no) WHERE name ='order_no';

  - 'current_val = SERIAL_CURRENT_VALUE(order_no)' current_val를 수정하지 않아도 되지만 SERIAL 값의 공백을 없애기 위해서 사용 권장

-- CREATE SERIAL
CREATE SERIAL order_no START WITH 1 INCREMENT BY 1 MAXVALUE 100000000 CACHE 100;

-- UPDATE SERIAL : NOCACHE
UPDATE db_serial SET cached_num = 0 WHERE name ='order_no';

-- db_serial 테이블 SELECT
<00001> name         : 'order_no'
        owner        : db_user
        current_val  : 103
        increment_val: 1
        max_val      : 100000000
        min_val      : 1
        cyclic       : 0
        started      : 1
        class_name   : NULL
        att_name     : NULL
        cached_num   : 0

-- tbl 테이블에 ROW 입력 중
1 2017-03-08 11:21:29.518
2 2017-03-08 11:21:30.037
3 2017-03-08 11:21:30.543
...
17 2017-03-08 11:21:37.623
18 2017-03-08 11:21:38.129
19 2017-03-08 11:21:38.635
101 2017-03-08 11:21:39.139 -- 19 → 101로 SERIAL 값 건너뜀. SERIAL 값의 공백 발생
102 2017-03-08 11:21:39.643
103 2017-03-08 11:21:40.148



-- UPDATE SERIAL : NOCACHE, current_val 수정
UPDATE db_serial SET cached_num = 0, current_val = SERIAL_CURRENT_VALUE(order_no) WHERE name ='order_no';

-- db_serial 테이블 SELECT
<00001> name         : 'order_no'
        owner        : db_user
        current_val  : 100
        increment_val: 1
        max_val      : 100000000
        min_val      : 1
        cyclic       : 0
        started      : 1
        class_name   : NULL
        att_name     : NULL
        cached_num   : 100

-- tbl 테이블에 ROW 입력 중
1 2017-03-08 11:27:18.203
2 2017-03-08 11:27:18.724
3 2017-03-08 11:27:19.230
...
27 2017-03-08 11:27:31.361
28 2017-03-08 11:27:31.867
29 2017-03-08 11:27:32.372 -- SERIAL 값 건너뜀 없이 ROW 입력. SERIAL 값의 공백 없음

-- db_serial 테이블 SELECT
<00001> name         : 'order_no'
        owner        : db_user
        current_val  : 29 -- 'current_val = SERIAL_CURRENT_VALUE(order_no)'으로 current_val 수정
        increment_val: 1
        max_val      : 100000000
        min_val      : 1
        cyclic       : 0
        started      : 1
        class_name   : NULL
        att_name     : NULL
        cached_num   : 0



4. 결론
  - CUBRID 8.2.2 ~ 8.4.x 버전에서 'ALTER SERIAL ... CACHE <cached_num> / NOCACHE' 기능 수행 시
  - 'ALTER SERIAL ... CACHE <cached_num>'는 다른 옵션과 함께 사용
  - 'ALTER SERIAL ... NOCACHE'는 csql에 sysadm 권한으로 접속해서 db_serial 테이블에 UPDATE Query 수행

-- CREATE SERIAL
CREATE SERIAL order_no START WITH 1 INCREMENT BY 1 MAXVALUE 100000000 CACHE 100;

-- 'ALTER SERIAL ... NOCACHE' 기능 수행
UPDATE db_serial SET cached_num = 0, current_val = SERIAL_CURRENT_VALUE(order_no) WHERE name ='order_no';

-- 'ALTER SERIAL ... CACHE <cached_num>' 기능 수행
ALTER SERIAL order_no INCREMENT BY 1 CACHE 50;



  1. synonym에 대하여

    Date2023.09.07 Category질의작성 By김민종 Views250
    Read More
  2. VALUES 절 활용하기

    Date2020.05.13 Category질의작성 By황영진 Views811
    Read More
  3. CUBRID 브로커와 시스템 메모리

    Date2019.03.12 Category운영관리 By정만영 Views2355
    Read More
  4. 여러개의 컬럼을 하나로 묶어주는 함수 CONCAT_WS 사용방법

    Date2019.01.29 Category질의작성 By엄기호 Views7188
    Read More
  5. 입력된 날자를 이용하여 해당 주차의 모든 날자 구하기

    Date2018.04.10 Category질의작성 By성진 Views1104
    Read More
  6. CUBRID PHP 드라이버 빌드와 연동방법

    Date2018.03.07 Category응용개발 By정만영 Views3758
    Read More
  7. JAVA_SP를 이용해서 정규표현식을 이용해서 치환을 하자.

    Date2017.10.10 Category질의작성 By성진 Views1319
    Read More
  8. 윈도우 OS에서 java sp 사용 시 Java VM is not running 해결 방법

    Date2017.09.04 Category운영관리 By정훈 Views2224
    Read More
  9. 테이블 명세서 쿼리

    Date2017.08.04 Category질의작성 By성진 Views3158
    Read More
  10. loose index scan을 활용한 효과적인 쿼리 튜닝 방안

    Date2017.06.01 Category질의작성 By박세훈 Views2403
    Read More
  11. CUBRID 8.2.2 ~ 8.4.x 버전에서 'ALTER SERIAL ... CACHE <cached_num> / NOCACHE' ERROR 해결 방법

    Date2017.03.08 Category운영관리 By주영진 Views2158
    Read More
  12. CONNECT BY 절 포함 질의 튜닝 예제

    Date2017.02.28 Category질의작성 By박세훈 Views9744
    Read More
  13. UPDATE에서 조인을 통해, 결과값 수정하는 방법

    Date2016.12.27 Category질의작성 By박동윤 Views7163
    Read More
  14. subquery를 이용한 튜닝예제

    Date2016.12.27 Category질의작성 By김창휘 Views3320
    Read More
  15. Oracle import 시 character set 변경관련

    Date2016.12.26 Category기타 By김창휘 Views8657
    Read More
  16. JBoss 사용 시 statement pooling 설정

    Date2016.12.16 Category기타 By손승일 Views2920
    Read More
  17. Tomcat's JDBC Pool 사용 시 JNDI DataSource 설정

    Date2016.12.16 Category기타 By손승일 Views6481
    Read More
  18. CUBRID 와 DBCP의 관계

    Date2016.12.14 Category응용개발 By엄기호 Views2786
    Read More
  19. 입력된 년월 또는 두개의 날짜을 이용하여 달력 및 주차 구하기

    Date2016.08.10 Category질의작성 By성진 Views5570
    Read More
  20. 큐브리드 포트 정리

    Date2016.07.05 Category운영관리 By정만영 Views6081
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 14 Next
/ 14

Contact Cubrid

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