postgresql - 行或列的大小是否会影响 Postgresql 中的聚合查询?
问题描述
考虑下面的表定义:
Column | Type | Collation | Nullable | Default
-----------------+--------------------------+-----------+----------+-------------
id | uuid | | not null |
reference_id | text | | |
data | jsonb | | |
tag | character varying(255) | | |
created_at | timestamp with time zone | | |
updated_at | timestamp with time zone | | |
is_active | boolean | | not null | true
status | integer | | | 0
message | text | | |
batch_id | uuid | | not null |
config | jsonb | | |
总表大小超过 500M,并且表中的每一行都包含一个数据列,其 JSON 超过 50MB。
问题 -
列的大小是否会data
影响聚合,例如count
?假设我们正在运行以下查询 -
select count(*)
from table
where batch_id = '88f30539-32d7-445c-8d34-f1da5899175c';
列的大小是否会data
影响聚合,例如sum
?假设我们正在运行以下查询 -
查询 1 -
select sum(data->>'count'::int)
from table
where batch_id = '88f30539-32d7-445c-8d34-f1da5899175c';
查询 2 -
select sum(jsonb_array_length(data->'some_array'))
from table
where batch_id = '88f30539-32d7-445c-8d34-f1da5899175c';
解决方案
最好的了解方法是测量。
一旦数据足够大以始终进行 TOAST,那么它的大小将不再影响不需要访问 TOAST 数据内容的查询的性能,例如您的第一个。您的最后两个确实需要访问内容,它们的性能将取决于大小。
推荐阅读
- .net-core - 简单场景中的 net core 3.1 dep inj 错误,ILogger 奖金问题
- python - Pandas - 重新索引仅对具有唯一值的索引对象有效
- sql - PostgreSQL——是否可以在查询的 ORDER BY 子句中使用命名窗口?
- python - TypeError: 不支持的操作数类型 -: 'datetime.time' 和 'datetime.timedelta'
- javascript - 从 Webpack 2 升级到 Webpack 4 - 如何构建错误
- python - 如何使用 python 在列表中的中心索引位置周围均匀分布唯一项目?
- javascript - 将 div 附加到带有 Jquery 附加的 html 后隐藏 [已解决]
- r - R - 如何使用包含 id 的向量列表对数据帧进行子集化和求和?
- database - Postgresql 卡在恢复模式
- c# - 菜单没有从数据库中显示