postgresql - 具有数千个分区的 Postgres 表
问题描述
我有一个 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 语句都需要非常多的锁和打开文件。这不会很好地工作。
将几个键集中到一个分区中(然后索引可能有意义)。
推荐阅读
- c# - .NET 5 - 当用户未使用身份框架授权时重定向到自定义登录页面
- esp32 - 通过 MQTT 从 ESP32-Cam 模块发送有效载荷
- python - 用于连接字段的 CSV 模块
- c# - Nuget 在管道部署中找不到本地源
- python - 用于匹配固定宽度的浮点数的正则表达式
- c# - .NET 中 Char.Latin1CharInfo 表的实现
- javascript - React Native:错误消息未定义不是对象(评估'navigation.navigate')
- sql-server - 是否可以创建一个新模式而不是创建一个新的数据库实例?
- swift - 带有父模型和子模型的 RealmSwift @ObservedResults,不能在写事务之外修改托管 RLMArray
- python - 当行内容是相关键的键值(每列的标题)时,如何用python在csv中编写嵌套字典?