postgres로 데이터웨어하우스를 구축했으니
대량의 데이터를 다뤄보자
데이터를 대충 보니
연도별로 천만 단위의 row가 나올 것 같다.
쿼리 성능 향상을 위해 range 파티션이 필요할 것 같다.
이왕 하는거 파티셔닝에 대해 알아보자.
create table product(
id int not null,
product_name varchar(255) not null,
created_date date,
primary key (id)
) partition by range(created_date);
create table product_2019 partition of product for values from ('2019-01-01') to ('2020-01-01');
create table product_2020 partition of product for values from ('2020-01-01') to ('2021-01-01');
create table product_2021 partition of product for values from ('2021-01-01') to ('2022-01-01');
create table product_2022 partition of product for values from ('2022-01-01') to ('2023-01-01');
CREATE TABLE User (
id INT NOT NULL,
name VARCHAR(30),
date DATE NOT NULL DEFAULT '1970-01-01',
region VARCHAR(30) NOT NULL)
PARTITION BY LIST (region) (
PARTITION p0 VALUES IN ('KR/Seoul') ,
PARTITION p1 VALUES IN ('KR/Busan') ,
PARTITION p2 VALUES IN ('KR/Daejeon') ,
PARTITION p3 VALUES IN (NULL));
CREATE TABLE User (
id INT NOT NULL,
name VARCHAR(30),
date DATE NOT NULL DEFAULT '1970-01-01')
PARTITION BY HASH (id) PARTITIONS 10;