# Map bounding box..

**URL:** <https://forums.percona.com/t/map-bounding-box/157>\
**Category:** Other MySQL® Questions\
**Created:** [January 1, 2007, 1:20pm UTC](https://forums.percona.com/t/map-bounding-box/157 "2007-01-01T13:20:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![oordopjes](https://avatars.discourse-cdn.com/v4/letter/o/958977/32.png) [@oordopjes](https://forums.percona.com/u/oordopjes)\
**Post date:** [January 1, 2007, 1:20pm UTC](https://forums.percona.com/t/map-bounding-box/157/1 "2007-01-01T13:20:11Z")

</div>

Hi, I would really like any suggestions on the following concerning performance…:

I have 1.000.000 locations with:

- a name
- a latitude
- a longitude
- a score

I want to:

- select all locations on a particular (google)map. So a latitude BETWEEN (… AND …) AND longitude BETWEEN (… AND …)
- fulltext match name. So name MATCHES (…)
- ORDER BY score

How would I get the best performance? What indexes should I create? Should I split the data in two tables and then JOIN? Or should I put everything together in one table?

ANY help would be great!!

---

<div class="post-metadata">

**Author:** ![Peter](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/peter/32/2_2.png) [@Peter](https://forums.percona.com/u/Peter)\
**Post date:** [January 1, 2007, 2:17pm UTC](https://forums.percona.com/t/map-bounding-box/157/2 "2007-01-01T14:17:37Z")

</div>

1Million is not too much, depending on your traffic of course, you might simply be able to use MySQL Full Text Search plus extra filtering by distance.

If there are a lot of matches and they are filtered by distance match you’re stuck however.

Sphinx could be patched to do what you need to do really fast.

---

<div class="post-metadata">

**Author:** ![oordopjes](https://avatars.discourse-cdn.com/v4/letter/o/958977/32.png) [@oordopjes](https://forums.percona.com/u/oordopjes)\
**Post date:** [January 1, 2007, 5:40pm UTC](https://forums.percona.com/t/map-bounding-box/157/3 "2007-01-01T17:40:28Z")

</div>

I did not know of Sphynx… it seems as a good (extra) solution to my problem.

I want to do something similar to the search on [yelp.com](http://yelp.com) or as is specified here.

At this time I’m using MySQL 4.1 and the following query:

SELECT SQL\_CALC\_FOUND\_ROWS entries.\*  
FROM entries  
JOIN geolocations ON (entries.id = geolocations.entry\_id)  
WHERE  
( geolocations.wgs84\_lat BETWEEN 55.9920055076675 AND 57.0005291105997 ) AND  
( geolocations.wgs84\_lon BETWEEN 3.55064105987549 AND 3.57124042510986 ) AND  
MATCH (name) AGAINST (‘+name\*’ IN BOOLEAN MODE)  
ORDER BY score DESC  
LIMIT 0, 8;

I also tried putting lat and lng in the entries table…but that was not helping very much…

Great forum BTW! Seems to be much more active than the original MySQL forum…

---

<div class="post-metadata">

**Author:** ![bluesaga](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bluesaga](https://forums.percona.com/u/bluesaga)\
**Post date:** [January 4, 2007, 5:34am UTC](https://forums.percona.com/t/map-bounding-box/157/4 "2007-01-04T05:34:49Z")

</div>

try not using “SQL\_FOUND\_CALC\_ROWS” a friend of mine was using this with distance and it made the queries take a LOT longer than expected.

---

<div class="post-metadata">

**Author:** ![oordopjes](https://avatars.discourse-cdn.com/v4/letter/o/958977/32.png) [@oordopjes](https://forums.percona.com/u/oordopjes)\
**Post date:** [January 4, 2007, 5:48am UTC](https://forums.percona.com/t/map-bounding-box/157/5 "2007-01-04T05:48:48Z")

</div>

Does Sphinx allow you to use more FULLTEXT indexes? Or is it the same as with MySQL?

---

<div class="post-metadata">

**Author:** ![bluesaga](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bluesaga](https://forums.percona.com/u/bluesaga)\
**Post date:** [January 4, 2007, 5:54am UTC](https://forums.percona.com/t/map-bounding-box/157/6 "2007-01-04T05:54:44Z")

</div>

it allows you to use more than one index at a time. However it might not be how your thinking it would 😉

---

<div class="post-metadata">

**Author:** ![Peter](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/peter/32/2_2.png) [@Peter](https://forums.percona.com/u/Peter)\
**Post date:** [January 4, 2007, 6:28am UTC](https://forums.percona.com/t/map-bounding-box/157/7 "2007-01-04T06:28:31Z")

</div>

With Sphinx you can build as many indexes as you want and also you can search only some of the columns.

It is however External search system

---

<div class="post-metadata">

**Author:** ![oordopjes](https://avatars.discourse-cdn.com/v4/letter/o/958977/32.png) [@oordopjes](https://forums.percona.com/u/oordopjes)\
**Post date:** [January 4, 2007, 6:44am UTC](https://forums.percona.com/t/map-bounding-box/157/8 "2007-01-04T06:44:15Z")

</div>

I was thinking of doing something like:

- MATCH (colx, coly) AGAINST (‘+myname\* +moreinfo\*’ IN BOOLEAN MODE) (But this is als supported by MySQL I just found out!)
- MATCH (colx) AGAINST (‘this’) AND MATCH (coly) AGAINST (‘+that\*’ IN BOOLEAN MODE)

Or something…

I read everywhere that Sphinx is much better (read faster) in fulltext matching. Does it also support boolean matches?
