GIN Fastupdate Pending List Behavior

Explain the GIN fastupdate pending list: bulk writes batch there, queries pay a periodic merge cost, and fastupdate off trades write speed for smooth reads.

SqlData Integrity

Code

snippet
-- GIN 索引默认 fastupdate=on:批量写入先进 pending list 暂存,
-- 查询撞上待合并的 pending list 时要先合并进主结构,出现周期性尖峰
CREATE TABLE docs (
    id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    search tsvector NOT NULL
);

CREATE INDEX docs_search_gin ON docs USING gin (search);

-- pending list 上限由该 GUC 控制(默认 4MB)
SHOW gin_pending_list_limit;

-- 写多读少的场景可以关掉 fastupdate:写入即时合并,查询无尖峰
CREATE INDEX docs_search_gin_nobatch ON docs USING gin (search)
    WITH (fastupdate = off);

-- 手动触发 pending list 清理,返回移除的页数
SELECT gin_clean_pending_list('docs_search_gin');

Inside the snippet

Several statements share this file — SELECT / CREATE, with `` among the objects involved.

Concretely, the SQL combines: NOT NULL qualifiers on the required columns; a PRIMARY KEY that enforces row identity; a GENERATED ALWAYS/GENERATED BY clause that computes the column value.

Core lines

CREATE INDEX docs_search_gin_nobatch ON docs USING gin (search)
WITH (fastupdate = off);
CREATE TABLE docs (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
search tsvector NOT NULL
);
CREATE INDEX docs_search_gin ON docs USING gin (search);

Interactive Tools for This Topic