Skip to the content.

Partition

조회

--데이터 조회
SELECT * FROM owner_name.table_name PARTITION (partition_name);

--파티션 테이블 조회
SELECT * FROM DBA_PART_TABLES;

--파티션 테이블의 파티션 조회
SELECT * FROM DBA_TAB_PARTITIONS;

--파티션 인덱스 조회
SELECT * FROM DBA_PART_INDEXES;

--파티션 인덱스의 파티션 조회
SELECT * FROM DBA_IND_PARTITIONS;

--각 파티션 테이블별 용량
SELECT SEGMENT_NAME, PARTITION_NAME, (SUM(BYTES) / 1024 / 1024) AS MB
FROM DBA_SEGMENTS
WHERE OWNER = 'owner_name' AND SEGMENT_NAME = 'table_name'
GROUP BY SEGMENT_NAME, PARTITION_NAME
ORDER BY PARTITION_NAME;


파티션 테이블 구성

--Range
CREATE TABLE owner_name.table_name (
  column_name1   type_name   constraint_name,
  column_name2   type_name   constraint_name,
  ...
  column_name8   type_name   constraint_name,
  column_name9   type_name   constraint_name
)
PARTITION BY RANGE (column_name1, column_name2, column_name3)
(
  PARTITION partition_name1 VALUES LESS THAN (value1_1, value1_2, value1_3),
  PARTITION partition_name2 VALUES LESS THAN (value2_1, value2_2, value2_3),
  ...
  PARTITION partition_name8 VALUES LESS THAN (value8_1, value8_2, value8_3),
  PARTITION partition_name9 VALUES LESS THAN (MAXVALUE)
);

--Hash
PARTITION BY HASH (column_name1, column_name2, column_name3)
(
  PARTITION partition_name1,
  PARTITION partition_name2,
  ...
  PARTITION partition_name8,
  PARTITION partition_name9 VALUES LESS THAN (MAXVALUE)
)

--Composite (서브 파티션)
PARTITION BY RANGE (column_name1, column_name2)
SUBPARTITION BY HASH (column_name3)
(
  PARTITION partition_name1 VALUES LESS THAN (value1, value2),
  PARTITION partition_name2 VALUES LESS THAN (value1, value2) (
    SUBPARTITIONS sub_partition_name1,
    SUBPARTITIONS sub_partition_name2,
    ...
    SUBPARTITIONS sub_partition_name8,
    SUBPARTITIONS sub_partition_name9 VALUES LESS THAN (MAXVALUE)
  ),
  ...
  PARTITION partition_name8 VALUES LESS THAN (value1, value2),
  PARTITION partition_name9 VALUES LESS THAN (MAXVALUE)
);

--List (단일 컬럼만 가능)
PARTITION BY LIST(column_name1)
(
  PARTITION partition_name1 VALUES(value1),
  PARTITION partition_name2 VALUES(value2),
  ...
  PARTITION partition_name8 VALUES(value8_1,value8_2,...value8_8,value8_9),
  PARTITION partition_name9 VALUES(value9),
);


파티션 테이블 기타 구성