繁体   English   中英

具有数千个分区的 Postgres 表

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM