💻 개발
Partition
Partition(파티션)
하나의 테이블을 2개 이상의 저장 구조로 분리하는 것.
⇒테이블이 커짐에 따라 발생하는 성능 저하를 해결하기 위함
⭐테이블이 파티션되면 index도 분리된다.
- terminal에서 partition 사용해보기
- startDay에 따라 파티션 분류
create table member(—생략—) -> partition by range(year(startDay)) ( -> partition p0 values less then (2000), -> partition p1 values less then (2010), -> partition p2 values less then maxvalue -> );
select table_name, partition_name, partition_method, partition_description, table_rows from information_schema.partitionos where table_name=’member’;
alter table member drop partition p2;
⭐partition을 삭제하게 되면 해당 partition의 record들이 함께 삭제된다.
alter table member add partition(partition p2 values less than(2015));
select * from member partition(p1);
alter table member reorganize partition p1, p2 into( partition n0 values less than(2001), partition n1 values less than(2002), partition n3 values less than(maxvalue) );
alter table member reorganize partition n3 into( partition n4 values less than(2003), partition n5 values less than(2004), partition n6 values less than(maxvalue) );
alter coalesce partition …
alter table … truncate partition
create table part(—생략—, primary key(pid, **level**)) partition by list(**level**) ( partition p0 values in (0,4,8), partition p1 values in(1,5,9) );
create table part(—생략—) partition by hash(sales) partitions 10;
create table product(pid int, pname varchar(10), kinds varchar(10), made DATE) -> partition by range(year(made)) -> subpartition by hash(to_days(made)) -> subpartitions 4( -> partition p0 values less than (2000), -> partition p1 values less than(2010), -> partition p2 values less than maxvalue -> );