GiST index: Generalised Search Tree (Postgres) — for geometric, range, and nearest-neighbour queries (PostGIS, ranges). A GiST index, short for Generalised Search Tree, is a flexible PostgreSQL index type for data that does not sort neatly in one dimension. Geographic shapes, date ranges and nearest-neighbour searches are its main uses. With PostGIS, a GiST index makes queries like "all shops within five kilometres" fast. For range types, it speeds up checks for overlapping periods, which is exactly what a booking system needs to prevent double bookings.
PostgreSQL can even enforce such rules with an exclusion constraint backed by GiST, so two bookings for the same room can never overlap, whatever the application code does. For ordinary columns like IDs, names and dates, the default B-tree index remains the right choice. GiST is for the specialised cases where B-tree cannot help.
What does an example of GiST index look like?
CREATE INDEX idx_shapes_geom ON shapes USING gist (geom);
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.
Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and schedule