# Range Optimization

**URL:** <https://forums.percona.com/t/range-optimization/940>\
**Category:** Other MySQL® Questions\
**Created:** [September 23, 2008, 1:04pm UTC](https://forums.percona.com/t/range-optimization/940 "2008-09-23T13:04:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliver88](https://avatars.discourse-cdn.com/v4/letter/o/71e660/32.png) [@oliver88](https://forums.percona.com/u/oliver88)\
**Post date:** [September 23, 2008, 1:04pm UTC](https://forums.percona.com/t/range-optimization/940/1 "2008-09-23T13:04:02Z")

</div>

Hi,

I have a MyISAM table with about 2400000 geonames. Ther are 2 decimal columns for latitude and longitude.

I use the following query to select all rows within a square area, in this case 10 x 10 km:

SELECT \* FROM geonames WHERE latitude \< 46.099099099099 AND latitude \> 45.900900900901 AND longitude \< 2.6422473920993 AND longitude \> 2.3577526079007

The problem is that MySQL is able to use index only on one of the lat/lng columns, so the query does not run as fast as I would need.  
I have tried all possible index combinations: (latitude), (longitude) and (latitude, longitude) but nothing seems to work.

Any help will be greatly appreciated.

Thanks,  
Oliver

---

<div class="post-metadata">

**Author:** ![nluv4hs](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@nluv4hs](https://forums.percona.com/u/nluv4hs)\
**Post date:** [September 25, 2008, 1:04pm UTC](https://forums.percona.com/t/range-optimization/940/2 "2008-09-25T13:04:35Z")

</div>

Similar to this.

---

<div class="post-metadata">

**Author:** ![MarkRose](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@MarkRose](https://forums.percona.com/u/MarkRose)\
**Post date:** [September 25, 2008, 5:44pm UTC](https://forums.percona.com/t/range-optimization/940/3 "2008-09-25T17:44:22Z")

</div>

Have you looked into the MySQL Spatial Extensions? I’m not too familiar with them myself, but they’re designed to make queries like yours (GIS) fast.

[http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.ht](http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.ht) ml
