I have 2 tables with more than 10 million rows.
create table TBL1 (
GUID UUID not null default gen_random_uuid(),
DT DATE not null,
...
constraint tbl1_pk primary key (GUID, DT)
)
partition by RANGE (dt);
create table TBL2 (
GUID UUID not null default gen_random_uuid(),
DT DATE not null,
TBL1_GUID UUID not null,
...
constraint tbl2_pk primary key (GUID, DT)
)
PARTITION BY RANGE (dt);
alter table TBL2
add constraint FK_TBL2__TBL1 foreign key (DT, TBL1_GUID)
references TBL1 (DT, GUID)
on delete restrict on update restrict;
There are 24 partition by month to each tables.
Does the order columns in the primary key matter? Does the order columns in the foreign key matter? Do I need to create fk for each partition, not on hole table? Queries are running slowly.
Queries are running slowly.