1

I'm curious what the most efficient way to index this would be in the context of, for instance, a map-based store locator.

  1. The user pans/zooms the map to the region they would like to view.
  2. The application determines the bounds of the viewport, aka max/min for lat/lng.

A query is issued in the basic form:

SELECT *
FROM locations
WHERE lat BETWEEN $min_lat AND $max_lat
    AND lng BETWEEN $min_lng AND $max_lng

Is it best to use a single composite INDEX(lat, lng), or two separate indexes like INDEX(lat), INDEX(lng)?

amelvin
  • 8,819
  • 4
  • 37
  • 59
Sammitch
  • 27,459
  • 7
  • 46
  • 75

1 Answers1

1

Since lat and lng are independant from each other and you are using them in your where clause seperately and not combined I would go for seperate indexes.

juergen d
  • 195,137
  • 36
  • 275
  • 343
  • Your answer got things clearing up in my mind, and then I came across [this similar question](http://stackoverflow.com/questions/1823685/when-should-i-use-a-composite-index) which tied everything up for me nicely. Thanks! – Sammitch Nov 21 '12 at 23:27