Spatial Indexes (GiST)
Make location queries fast.
Why Location Queries Get Slow
Imagine a table with millions of restaurant locations. If you ask "Find all restaurants within 5 km of me," the database must check every single row to compute the distance. This is called a sequential scan, and it becomes painfully slow as the table grows.
Spatial indexes solve this by organizing geometry data into a tree structure, letting the database skip large portions of the table instantly.
What Is a GiST Index?
GiST stands for Generalized Search Tree. It is a flexible index framework built into PostgreSQL that supports many data types, including geometric shapes and PostGIS geometry.
Unlike a B-tree index (which works on sortable values like integers or strings), GiST can index multi-dimensional data such as points, polygons, and lines. PostGIS uses GiST internally to build its spatial indexes.
All lessons in this course
- Spatial Data Types
- Distance and Nearest Neighbors
- Spatial Joins and Containment
- Spatial Indexes (GiST)