Data Structure Simulators

R-Tree Visualizer

Enter a latitude and longitude and watch an R-tree — the spatial index MySQL and PostGIS actually use — find the places near you. Instead of a fixed grid, it groups nearby points into bounding boxes and only opens the boxes that overlap your search area.

How an R-tree works

An R-tree groups objects into minimum bounding rectangles (MBRs) — boxes inside boxes, up to the root. It splits a node when the node gets too full, not when space gets crowded, so the tree stays balanced (every leaf at the same depth) and each node maps neatly onto one disk page. That is exactly why databases pick an R-tree over a quadtree for spatial indexes.

The trade-off

Full write-up: MySQL Internals.