---
title: "How and when to use btree_gist"
description: "Postgres's btree_gist extension lets a single GiST index combine one-dimensional B-Tree-style columns (like dates) with spatial PostGIS geometries, so queries filtering on both space and time can use one index scan."
url: "https://swe.quest/articles/how-and-when-to-use-btree-gist-a2bcb15ac54b481b"
canonical: "https://neon.com/blog/btree_gist"
source: "Neon"
published: "2024-07-08"
difficulty: "medium"
kind: "How-to"
reading_minutes: 10
tags: ["postgres","geospatial","performance","sql"]
---

# How and when to use btree\_gist

A post on [Neon](https://swe.quest/sources/neon.md), published 2024-07-08, 10 min read, How-to. Original: [https://neon.com/blog/btree\_gist](https://neon.com/blog/btree_gist)

## Summary

Postgres's btree\_gist extension lets a single GiST index combine one-dimensional B-Tree-style columns (like dates) with spatial PostGIS geometries, so queries filtering on both space and time can use one index scan. Using 38.6 million UK police crime records loaded via xsv and COPY, then transformed from WGS84 to British National Grid, a count of crimes within 1km of Stratford during the 2012 Olympics takes about 8 seconds unindexed. A GiST spatial index cuts that to about 32ms via a bitmap scan. A combined gist(location, month) index brings it to about 8ms with a plain Index Scan, roughly 1000x faster than no index.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Maps & geospatial](https://swe.quest/tags/geospatial.md) (Domains)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

- Postgres indexes ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- PostGIS basics
- EXPLAIN ANALYZE

## Keywords

btree\_gist, GiST, PostGIS, xsv, British National Grid, Neon

## Related posts

- [The side quest that freed 10% of our database](https://swe.quest/articles/the-side-quest-that-freed-10-of-our-database-649662623bb94a1e.md): incident.io · 2026-11-24 · Medium · 13 min read · PostgreSQL, Query engines, Performance engineering, SQL
  A single lateral-join query answering "who's on call for this rotation layer right now" consumed 34% of incident.io's Postgres replica CPU.
- [ClickHouse and PostgreSQL - a Match Made in Data Heaven - part 1](https://swe.quest/articles/clickhouse-and-postgresql-a-match-made-in-data-heaven-part-1-7c7668b9b4913b70.md): ClickHouse · 2022-12-20 · Medium · 18 min read · Analytics & OLAP, PostgreSQL, Query engines, Performance engineering, SQL
  ClickHouse can query PostgreSQL data in place through the postgresql table function and the PostgreSQL table engine.
- [pg\_search is Available on Neon](https://swe.quest/articles/pg-search-is-available-on-neon-98d919ff82afb749.md): Neon · 2025-03-18 · Medium · 8 min read · PostgreSQL, Search, Performance engineering
  ParadeDB's pg\_search extension, now available on Neon in AWS regions, adds a Tantivy-powered BM25 inverted index to Postgres, bringing relevance ranking, fuzzy matching, faceting, highlighting and JSON-aware search that native tsvector/GIN full-text search lacks.
- [Simplifying Time-Based Queries with Range Columns](https://swe.quest/articles/simplifying-time-based-queries-with-range-columns-42d3f987b6918835.md): Supabase · 2024-07-11 · Medium · 4 min read · PostgreSQL, SQL, Databases
  Postgres range types such as tstzrange replace separate start\_at/end\_at columns with a single range value, which makes time-window queries and overlap prevention simpler.
- [Hosting Postgres with GeoLite2: a practical guide to IP geolocation, data loading, and updates](https://swe.quest/articles/hosting-postgres-with-geolite2-a-practical-guide-to-ip-geolocation-data-loading-f98c61ed175d32d1.md): Railway · 2025-12-16 · Medium · 8 min read · PostgreSQL, Maps & geospatial, Data pipelines
  Loading MaxMind's GeoLite2 CSVs into Postgres pays off over the MMDB binary format when you need SQL joins, batch geolocation of many IPs, queries over the ranges themselves, or one copy shared across services; for simple single-IP lookups MMDB is easier.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
