我想阅读据说用我的 GIN 索引创建的三元组列表,但我似乎在任何地方都找不到该命令:我尝试了di+
、dv+
、dm+
或没有+
的每个。什么都没有回来。
我是否误解了某些内容或我的索引为空?它显示的是 16ko 大小,但据我所知,它可能是空的标准大小。
使用纯 SQL 无法查看存储在索引中的数据(并且 psql 反斜杠命令只是简单地转换为 SQL(。
如果要检查索引块的内部,则需要安装扩展 pageinspect ,该扩展也具有一些专门针对 GIN 索引的功能
有一种间接方法可以获取此信息,但前提是您在 tsvector 列上使用 GIN 索引。
表结构
CREATE TABLE bench(
id bigserial,
f1 text,
f2 text,
f3 text,
f4 text
);
用一些数据填充桌子长凳。添加 tsvector 列并更新它:
ALTER TABLE bench
ADD COLUMN ts tsvector;
UPDATE bench
SET ts =
strip(to_tsvector('simple',coalesce(f1,''))
||to_tsvector('simple',coalesce(f2,''))
||to_tsvector('simple',coalesce(f3,''))
||to_tsvector('simple',coalesce(f4,''))
)
;
创建杜松子酒索引
CREATE INDEX ooz_gin ON bench USING GIN (ts) WITH (fastupdate=on);
列出 ts 列(以及索引(中的所有已知单词及其三元组:
SELECT word,show_trgm(word) as trigrams
FROM ts_stat('SELECT ts FROM bench');
结果(包含我的测试数据(:
word | trigrams
---------------------+-----------------------------------------------------------------------------------------
zworykin | {" z"," zw","in ",kin,ory,ryk,wor,yki,zwo}
zulu | {" z"," zu","lu ",ulu,zul}
zorch | {" z"," zo","ch ",orc,rch,zor}
zoning | {" z"," zo",ing,"ng ",nin,oni,zon}
zips | {" z"," zi",ips,"ps ",zip}
zipping | {" z"," zi",ing,ipp,"ng ",pin,ppi,zip}
zippered | {" z"," zi","ed ",ere,ipp,per,ppe,red,zip}
ziploc | {" z"," zi",ipl,loc,"oc ",plo,zip}
zion | {" z"," zi",ion,"on ",zio}