GiST Index (Generalized Search Tree for Ranges and Geometry)

Last updated: 2026-11-04

GiST Index (Generalized Search Tree for Ranges and Geometry)

GiST (Generalized Search Tree) is an extensible index framework: instead of requiring sorted data, it pairs each data type with a set of "might match" predicates. Only summaries live in the index, so GiST plans typically show a Recheck Cond. Among the built-in types, tsrange (time ranges), box, circle, point, polygon, inet and tsvector all have GiST operator classes.

Kindindex
Example LanguageSQL

📝 Syntax

CREATE INDEX <index_name> ON <table_name> USING gist ( <column> )

⚙️ Parameters

index_nameName of the new index.
table_nameThe table to index.
column_nameThe indexed column; its type needs a GiST operator class, e.g. tsrange, tstzrange, int4range, inet, point, box, polygon or tsvector.

Returns:No return value. On success the command tag is CREATE INDEX.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

CREATE TABLE
INSERT 0 3000
CREATE INDEX
ANALYZE

-- EXPLAIN: the && overlap predicate hits the GiST index
Bitmap Heap Scan on idx_demo_gist  (cost=4.61..30.36 rows=60 width=7)
  Recheck Cond: (booked && '["2026-03-01 00:00:00","2026-03-05 00:00:00")'::tsrange)
  Heap Blocks: exact=15
  Buffers: shared hit=15 read=2
  ->  Bitmap Index Scan on idx_gist_booked  (cost=0.00..4.60 rows=60 width=0)
        Index Cond: (booked && '["2026-03-01 00:00:00","2026-03-05 00:00:00")'::tsrange)
        Index Searches: 1
        Buffers: shared read=2
Planning Time: 0.209 ms
Execution Time: 0.271 ms

-- Query result
 count 
-------
    50
(1 row)

(The EXPLAIN plans above come from a real PostgreSQL 18.6 run; actual time / Planning Time / Execution Time are indicative values and vary with machine load.)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QBoth GiST and GIN handle multi-valued and range data — how do I choose?
AGIN is optimized for exact containment: direct and fast, but a large index. GiST is optimized for possible overlap: smaller, at the price of a heap recheck. Use GIN for JSONB containment, GiST for ranges and geometry.
QWhy does every GiST plan show a Recheck Cond?
AA GiST index stores a summary of each object (for a range, its outer bounds), not the full value. The index narrows the candidates and the heap is rechecked with the exact predicate — that is the Recheck.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏