biscuit
使用IAM的高性能文本模式匹配
仓库
CrystallineCore/Biscuit
https://github.com/CrystallineCore/Biscuit
源码
Biscuit-2.2.2.tar.gz
Biscuit-2.2.2.tar.gz
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
pg_biscuit | 2.2.2 | FTS | MIT | C |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 2170 | biscuit | 否 | 是 | 否 | 是 | 否 | 否 | public |
| 相关扩展 | plpgsql hll rum pg_textsearch |
|---|
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 2.2.2 | 1817161514 | pg_biscuit | plpgsql |
| RPM | PIGSTY | 2.2.2 | 1817161514 | pg_biscuit_$v | - |
| DEB | PIGSTY | 2.2.2 | 1817161514 | postgresql-$v-biscuit | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 2.2.2 el8.x86_64.pg18 : pg_biscuit_18 pg_biscuit_18-2.2.2-1PIGSTY.el8.x86_64.rpm
| PIGSTY 2.2.2 el8.x86_64.pg17 : pg_biscuit_17 pg_biscuit_17-2.2.2-1PIGSTY.el8.x86_64.rpm
| PIGSTY 2.2.2 el8.x86_64.pg16 : pg_biscuit_16 pg_biscuit_16-2.2.2-1PIGSTY.el8.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el8.aarch64 | PIGSTY 2.2.2 el8.aarch64.pg18 : pg_biscuit_18 pg_biscuit_18-2.2.2-1PIGSTY.el8.aarch64.rpm
| PIGSTY 2.2.2 el8.aarch64.pg17 : pg_biscuit_17 pg_biscuit_17-2.2.2-1PIGSTY.el8.aarch64.rpm
| PIGSTY 2.2.2 el8.aarch64.pg16 : pg_biscuit_16 pg_biscuit_16-2.2.2-1PIGSTY.el8.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el9.x86_64 | PIGSTY 2.2.2 el9.x86_64.pg18 : pg_biscuit_18 pg_biscuit_18-2.2.2-1PIGSTY.el9.x86_64.rpm
| PIGSTY 2.2.2 el9.x86_64.pg17 : pg_biscuit_17 pg_biscuit_17-2.2.2-1PIGSTY.el9.x86_64.rpm
| PIGSTY 2.2.2 el9.x86_64.pg16 : pg_biscuit_16 pg_biscuit_16-2.2.2-1PIGSTY.el9.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el9.aarch64 | PIGSTY 2.2.2 el9.aarch64.pg18 : pg_biscuit_18 pg_biscuit_18-2.2.2-1PIGSTY.el9.aarch64.rpm
| PIGSTY 2.2.2 el9.aarch64.pg17 : pg_biscuit_17 pg_biscuit_17-2.2.2-1PIGSTY.el9.aarch64.rpm
| PIGSTY 2.2.2 el9.aarch64.pg16 : pg_biscuit_16 pg_biscuit_16-2.2.2-1PIGSTY.el9.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el10.x86_64 | PIGSTY 2.2.2 el10.x86_64.pg18 : pg_biscuit_18 pg_biscuit_18-2.2.2-1PIGSTY.el10.x86_64.rpm
| PIGSTY 2.2.2 el10.x86_64.pg17 : pg_biscuit_17 pg_biscuit_17-2.2.2-1PIGSTY.el10.x86_64.rpm
| PIGSTY 2.2.2 el10.x86_64.pg16 : pg_biscuit_16 pg_biscuit_16-2.2.2-1PIGSTY.el10.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el10.aarch64 | PIGSTY 2.2.2 el10.aarch64.pg18 : pg_biscuit_18 pg_biscuit_18-2.2.2-1PIGSTY.el10.aarch64.rpm
| PIGSTY 2.2.2 el10.aarch64.pg17 : pg_biscuit_17 pg_biscuit_17-2.2.2-1PIGSTY.el10.aarch64.rpm
| PIGSTY 2.2.2 el10.aarch64.pg16 : pg_biscuit_16 pg_biscuit_16-2.2.2-1PIGSTY.el10.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS |
| d12.x86_64 | PIGSTY 2.2.2 d12.x86_64.pg18 : postgresql-18-biscuit postgresql-18-biscuit_2.2.2-1PIGSTY~bookworm_amd64.deb
| PIGSTY 2.2.2 d12.x86_64.pg17 : postgresql-17-biscuit postgresql-17-biscuit_2.2.2-1PIGSTY~bookworm_amd64.deb
| PIGSTY 2.2.2 d12.x86_64.pg16 : postgresql-16-biscuit postgresql-16-biscuit_2.2.2-1PIGSTY~bookworm_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| d12.aarch64 | PIGSTY 2.2.2 d12.aarch64.pg18 : postgresql-18-biscuit postgresql-18-biscuit_2.2.2-1PIGSTY~bookworm_arm64.deb
| PIGSTY 2.2.2 d12.aarch64.pg17 : postgresql-17-biscuit postgresql-17-biscuit_2.2.2-1PIGSTY~bookworm_arm64.deb
| PIGSTY 2.2.2 d12.aarch64.pg16 : postgresql-16-biscuit postgresql-16-biscuit_2.2.2-1PIGSTY~bookworm_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
| d13.x86_64 | PIGSTY 2.2.2 d13.x86_64.pg18 : postgresql-18-biscuit postgresql-18-biscuit_2.2.2-1PIGSTY~trixie_amd64.deb
| PIGSTY 2.2.2 d13.x86_64.pg17 : postgresql-17-biscuit postgresql-17-biscuit_2.2.2-1PIGSTY~trixie_amd64.deb
| PIGSTY 2.2.2 d13.x86_64.pg16 : postgresql-16-biscuit postgresql-16-biscuit_2.2.2-1PIGSTY~trixie_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| d13.aarch64 | PIGSTY 2.2.2 d13.aarch64.pg18 : postgresql-18-biscuit postgresql-18-biscuit_2.2.2-1PIGSTY~trixie_arm64.deb
| PIGSTY 2.2.2 d13.aarch64.pg17 : postgresql-17-biscuit postgresql-17-biscuit_2.2.2-1PIGSTY~trixie_arm64.deb
| PIGSTY 2.2.2 d13.aarch64.pg16 : postgresql-16-biscuit postgresql-16-biscuit_2.2.2-1PIGSTY~trixie_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
| u22.x86_64 | PIGSTY 2.2.2 u22.x86_64.pg18 : postgresql-18-biscuit postgresql-18-biscuit_2.2.2-1PIGSTY~jammy_amd64.deb
| PIGSTY 2.2.2 u22.x86_64.pg17 : postgresql-17-biscuit postgresql-17-biscuit_2.2.2-1PIGSTY~jammy_amd64.deb
| PIGSTY 2.2.2 u22.x86_64.pg16 : postgresql-16-biscuit postgresql-16-biscuit_2.2.2-1PIGSTY~jammy_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| u22.aarch64 | PIGSTY 2.2.2 u22.aarch64.pg18 : postgresql-18-biscuit postgresql-18-biscuit_2.2.2-1PIGSTY~jammy_arm64.deb
| PIGSTY 2.2.2 u22.aarch64.pg17 : postgresql-17-biscuit postgresql-17-biscuit_2.2.2-1PIGSTY~jammy_arm64.deb
| PIGSTY 2.2.2 u22.aarch64.pg16 : postgresql-16-biscuit postgresql-16-biscuit_2.2.2-1PIGSTY~jammy_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
| u24.x86_64 | PIGSTY 2.2.2 u24.x86_64.pg18 : postgresql-18-biscuit postgresql-18-biscuit_2.2.2-1PIGSTY~noble_amd64.deb
| PIGSTY 2.2.2 u24.x86_64.pg17 : postgresql-17-biscuit postgresql-17-biscuit_2.2.2-1PIGSTY~noble_amd64.deb
| PIGSTY 2.2.2 u24.x86_64.pg16 : postgresql-16-biscuit postgresql-16-biscuit_2.2.2-1PIGSTY~noble_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| u24.aarch64 | PIGSTY 2.2.2 u24.aarch64.pg18 : postgresql-18-biscuit postgresql-18-biscuit_2.2.2-1PIGSTY~noble_arm64.deb
| PIGSTY 2.2.2 u24.aarch64.pg17 : postgresql-17-biscuit postgresql-17-biscuit_2.2.2-1PIGSTY~noble_arm64.deb
| PIGSTY 2.2.2 u24.aarch64.pg16 : postgresql-16-biscuit postgresql-16-biscuit_2.2.2-1PIGSTY~noble_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
构建
您可以使用 pig build 命令构建 pg_biscuit 扩展的 RPM / DEB 包:
pig build pkg pg_biscuit # 构建 RPM / DEB 包
安装
您可以直接安装 pg_biscuit 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
pig repo add pgsql -u # 添加仓库并更新缓存
使用 pig 或者是 apt/yum/dnf 安装扩展:
pig install pg_biscuit; # 当前活跃 PG 版本安装
pig ext install -y pg_biscuit -v 18 # PG 18
pig ext install -y pg_biscuit -v 17 # PG 17
pig ext install -y pg_biscuit -v 16 # PG 16
dnf install -y pg_biscuit_18 # PG 18
dnf install -y pg_biscuit_17 # PG 17
dnf install -y pg_biscuit_16 # PG 16
apt install -y postgresql-18-biscuit # PG 18
apt install -y postgresql-17-biscuit # PG 17
apt install -y postgresql-16-biscuit # PG 16
创建扩展:
CREATE EXTENSION biscuit CASCADE; -- 依赖: plpgsql
用法
biscuit 是 PostgreSQL 的一种索引访问方法,专为 LIKE 和 ILIKE 模式匹配优化,也支持多列检索。上游将其定位为一种确定性的位图索引,可避免基于 trigram 的搜索常见的误命中复查开销。
快速上手
创建扩展,并在一个或多个文本列上建立 Biscuit 索引:
CREATE EXTENSION biscuit;
CREATE INDEX idx_users_name ON users USING biscuit(name);
CREATE INDEX idx_products_search
ON products USING biscuit(name, description, category);
带通配符的常见查询同样可以使用该索引:
SELECT * FROM users WHERE name LIKE '%john%';
SELECT * FROM users WHERE name NOT LIKE 'a%b%c';
SELECT COUNT(*) FROM users WHERE name LIKE '%test%';
SELECT *
FROM products
WHERE name LIKE '%widget%'
AND description LIKE '%blue%'
AND category LIKE 'electronics%'
LIMIT 10;
索引行为
Biscuit 为每个字符串维护位图位置索引,能够同时匹配正向和反向字符位置。上游设计强调:
- 正向索引,用于匹配字符在精确位置上的出现
- 反向索引,用于按字符串末尾倒数位置匹配字符
ILIKE的大小写不敏感变体- 用于快速长度过滤的精确长度位图和最小长度位图
对于 LIKE 'abc%def' 这类模式,Biscuit 可以把前缀位图、后缀位图以及最小长度过滤合并起来,从而在不执行 heap 复查的情况下得到精确结果。
模式类型
上游文档对常见模式给出了优化路径:
- 精确匹配,例如
'abc' - 前缀匹配,例如
'abc%' - 后缀匹配,例如
'%xyz' - 子串匹配,例如
'%abc%' - 多列谓词,Biscuit 会按估计选择性重排谓词顺序
性能说明
上游 README 强调了纯位图求值及多项执行优化,包括:
- 中间位图为空时提前结束
- 对稀疏和稠密数据直接使用 roaring bitmap
- 后缀谓词使用反向位置查找
- 对 TID 做排序,以提高 heap 访问局部性
- 对聚合查询和
LIMIT的特殊处理
项目 README 还给出了一个 100 万行测试表的基准方案,用来比较 Biscuit 索引与 trigram 方案。
需求
当前上游 README 列出的源码构建要求包括:
- PostgreSQL 16 或更高版本
- 标准构建工具,如
gcc、make和pg_config - 可选的 CRoaring,用于提升性能
该项目通过 PGXN 发布包,并在 Read the Docs 上维护独立文档站。