Bounding box

A bounding box is a latitude and longitude rectangle around a centre that contains every point within a specified radius. It serves as a cheap, index-friendly prefilter before the exact distance check, reducing the number of candidate rows. Its longitude width grows by a factor of 1/cos(latitude) because longitude degrees represent shorter distances closer to the poles.

Minimal example

sql
SELECT id, name
FROM restaurants
WHERE is_active = 1
  AND lat BETWEEN ? AND ?
  AND lng BETWEEN ? AND ?;

Learn this concept

Lesson 2.25 · Haversine distance and geo indexes

Used in exercises

Exercise 2.26 · GET /v1/restaurants: sort by distance
Prerequisite conceptsSecondary indexEXPLAIN