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.
Code
-- 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
PostgreSQL EXPLAIN AnalyzerAnalyze PostgreSQL EXPLAIN ANALYZE text or FORMAT JSON plans locally to flag Seq Scans, slow nodes, row misestimates, disk sorts, and index hints.SQL DDL to TypeScript ConverterConvert SQL CREATE TABLE DDL statements into strict TypeScript interfaces with nullable, array, enum, JSONB, and Date or ISO string column mappings.Multi-Mode Escape & Unescape CodecEscape and unescape strings safely across JSON, JavaScript, SQL single-quoted literals, POSIX shell single quotes, and RFC 4180 CSV cells in your browser.SQL FormatterReformat SQL by uppercasing reserved words and breaking lines before SELECT, FROM, WHERE, and other clauses.
Report a problem with this exampleOpens a pre-filled issue on GitHub.