설문조사
PostgreSQL/PPAS 관련 듣고 싶은 교육은


총 게시물 73건, 최근 0 건
   

PostgreSQL CTID 와 오라클 ROWID

글쓴이 : PostgresDBA 날짜 : 2015-03-23 (월) 10:47 조회 : 11160
데이터베이스 사랑넷에 ctid 와 오라클 rowid 에 관한 질문이 올라왔네요.

오라클의 rowid 는 해당로우가 삭제되고, 재 insert 되지 않는 이상 rowid 값이 변하지는 않습니다.
update 시에도 rowid 값은 변하지 않습니다.
하지만 table move 명령등을 이용한 테이블 reorg 시에는 rowid 값이 바뀌게 됩니다.

기타 변경되는 경우 - 오라클)
alter table t shrink space compact..
alter table t move..
flashback table t...

PostgreSQL 경우 ctid 가 오라클의 rowid 와 비슷한 개념이기는 합니다만, 큰차이가 있습니다.
update 시에 ctid 값이 오라클 rowid 와 달리 바뀌어 버린다는 점입니다.


PostgresDBA 2017-10-25 (수) 17:14
ctid 값은 tid 라는 특이한 컬럼타입을 사용합니다.

만약 특정 테이블에 ctid 값을 저장할 일 있으면 아래와 같이 text 컬럼타입으로 저장하시는게 편합니다.

create table x(cid text);

insert into values select ctid::text from xxxx;

text 의 타입의 ctid 값은 tid 타입으로 불러올수 있습니다.

select cid::tid from x;
댓글주소
PostgresDBA 2017-10-25 (수) 17:30
ctid is of type tid (tuple identifier), called ItemPointer in the C code. Per documentation:
This is the data type of the system column ctid. A tuple ID is a pair (block number, tuple index within block) that identifies the physical location of the row within its table.

page number 구하기

SELECT (ctid::text::point)[0]::bigint AS page_number FROM t

SELECT (ctid::text::point)[0]::int                              --  25 ms
      ,right(split_part(ctid::text, ',', 1), -1)::int          --  28 ms
      ,ltrim(split_part(ctid::text, ',', 1), '(')::int          --  29 ms
      ,(translate(ctid::text,'()', '{}')::int[])[1]            --  45 ms
      ,(replace(replace(ctid::text,'(','{'),')','}')::int[])[1] --  51 ms
      ,substring(right(ctid::text, -1), '^\d+')::int            --  52 ms
      ,substring(ctid::text, '^\((\d+),')::int                  -- 143 ms
FROM tbl;

발췌: https://dba.stackexchange.com/questions/65964/how-do-i-decompose-ctid-into-page-and-row-numbers
댓글주소
   

postgresdba.com