跳转到主要内容

istore

支持算术、聚合与 GIN 索引的整数键值类型

概览

扩展包名版本分类许可证语言
istore0.1.12TYPEMITC
ID扩展名BinLibLoadCreateTrustReloc模式
3710istore否是否是否是-

PGXN 0.1.12 source requires the PG16+ varatt/Datum compatibility patch. PostgreSQL 14-18 verified across all 16 PGSTY target platforms. Does not require hstore.

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY0.1.121817161514istore-
RPMPIGSTY0.1.121817161514istore_$v-
DEBPIGSTY0.1.121817161514postgresql-$v-istore-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
PIGSTY 0.1.12
PIGSTY 0.1.12
PIGSTY 0.1.12
PIGSTY 0.1.12
PIGSTY 0.1.12
u24.x86_64
u24.aarch64
PIGSTY 0.1.12
PIGSTY 0.1.12
PIGSTY 0.1.12
PIGSTY 0.1.12
PIGSTY 0.1.12
u26.x86_64
u26.aarch64

构建

您可以使用 pig build 命令构建 istore 扩展的 RPM / DEB 包:

pig build pkg istore         # 构建 RPM / DEB 包

安装

您可以直接安装 istore 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

安装
pig install istore;          # 当前活跃 PG 版本安装
pig
pig ext install -y istore -v 18  # PG 18
pig ext install -y istore -v 17  # PG 17
pig ext install -y istore -v 16  # PG 16
pig ext install -y istore -v 15  # PG 15
pig ext install -y istore -v 14  # PG 14
dnf
dnf install -y istore_18       # PG 18
dnf install -y istore_17       # PG 17
dnf install -y istore_16       # PG 16
dnf install -y istore_15       # PG 15
dnf install -y istore_14       # PG 14
apt
apt install -y postgresql-18-istore   # PG 18
apt install -y postgresql-17-istore   # PG 17
apt install -y postgresql-16-istore   # PG 16
apt install -y postgresql-15-istore   # PG 15
apt install -y postgresql-14-istore   # PG 14

创建扩展:

CREATE EXTENSION istore;

用法

来源:

istore 为 PostgreSQL 提供紧凑的整数键映射。istore 类型存储整数值,bigistore 存储 bigint 值;两者适用于以整数标识符为键的稀疏计数器、分布与分析聚合。

核心流程

文本输入类似 hstore,数组构造函数可以聚合重复键:

CREATE EXTENSION istore;

SELECT istore(ARRAY[1, 2, 1, 3, 2, 2]);
SELECT '1=>4,2=>5'::istore -> 1;
SELECT '1=>4,2=>5'::istore + '1=>4,3=>6'::istore;

CREATE INDEX metrics_keys_idx
  ON metrics USING gin (values istore_key_ops);

键查询使用 ->;?、?& 和 ?| 检查键是否存在。|| 连接映射,算术操作符则合并匹配键。istore_key_ops GIN 操作符类可加速键存在谓词。

重要对象与注意事项

构造与转换工具包括 istore(...)、bigistore(...)、akeys、avals、each、slice、compact、fill_gaps、accumulate、clamp 和删除辅助函数。sum_up 汇总值,SUM 聚合返回 bigistore,为总计提供更宽的值类型。扩展也提供逐键最小值和最大值聚合。

从 istore 到 bigistore 的转换是隐式的;窄化赋值可能溢出。算术与除法仍需应用检查溢出和零除数。大型值可能进入 TOAST,GIN 索引也会增加写入和维护成本,因此应针对实际分布与更新负载进行基准测试,不能把上游示例当作性能保证。

这个页面对您有帮助吗?