[英]Postgres table with thousands of partition
我有一個 postgres 表(在 postgres12 中),它應該在不久的將來有數千個分區(至少 200k)。
這是我創建父表的方式:
create table if not exists content (
key varchar(20) not NULL,
value json not null default '[]'::json
) PARTITION BY LIST(key)
然后添加任何給定的子表,例如:
create table if not exists content_123 PARTITION OF content for VALUES in ('123');
我還在子表頂部添加了一個索引以便快速訪問(因為我將直接訪問子表):
create index if not exists content_123_idx on content_123 using btree(key)
這是我的問題:我過去從未在 postgres 表中管理過這么多分區,所以我只是想知道做我正在做的事情有什么缺點嗎? 另外,(如上所述)我不會直接從父表中查詢,而是直接從各個子表中讀取。
有了這些表定義,索引就完全沒用了。
有了 200000 個分區,查詢計划將變得非常慢,並且每個 SQL 語句都需要非常多的鎖和打開文件。 這不會很好地工作。
將幾個鍵集中到一個分區中(然后索引可能有意義)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.