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.
| Kind | index |
|---|---|
| Example Language | SQL |
📝 Syntax
CREATE INDEX <index_name> ON <table_name> USING gist ( <column> )
⚙️ Parameters
| index_name | Name of the new index. |
|---|---|
| table_name | The table to index. |
| column_name | The 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
- tsrange / tstzrange / int4range / int8range are built-in range types — no extension is needed for a GiST index.
- A GiST index is lossy: it stores summaries, so matching rows are rechecked in the heap. That is why the plan shows Recheck Cond and Bitmap Heap Scan.
- The built-in inet type has no default GiST operator class — creating one fails with no default operator class for access method "gist". GiST on inet requires the btree_gist extension.
- The geometric types (point, box, polygon, circle) use GiST as well; PostGIS builds extensively on top of that.
💡 Related Cases
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.