views:

25

answers:

3

Hi, I need to organize cache in mySql database for address - coordinates. What is the best practice to store address? Do i need to compress address string or use it as is?

edit: Ok, let's I reassert my question. How to store long (up to 512) string in database if I need to search by exactly this string in future.

+1  A: 

MySql can manage coordinates and operates on these values, try looking at http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html

If you want something simpler, personnaly I usually store separately the city code, the city name and the rest of the adress string. Then I can index and search on these fields (one by one, or with a combination).

If you want a simple use of coordinates, you can simply store the latitude/longitude and do basic comparisons

Matthieu
Interesting info but I need something simple.
Orsol
I edited the answer, but your question is not that clear
Matthieu
+2  A: 

If you are absolutely certain your search string can be normalized (e.g.: stripping all the extra spaces, forcing lower case etc.) so to avoid ambiguity and that you need to search for full match (i.e. you either find exactly the normalized string or not, and don't need to search by substring, soundex, partial match, sort by it etc. - this is how I read your "by exactly this string" ) you could consider calculating the hashcode of the string, put it in the DB and indexing that.

If you use an hashcode function that returns a number, you will have a very efficient access index. And of course you can still keep the original string field for printing and different access approaches.

Possible problems: while hashcode can minimize the chance of a hash collision, they cannot be guaranteed not to happen, so you should manage that, too.

Also, unless you have lots and lots of addresses, I doubt that the speedup gain will be worth the trouble.

p.marino
the hash code (as number) is a great idea. You'll just have to check the results to verify that this is the same string (avoid hash collision)
Matthieu
A: 

Answer can be found here

Orsol
And this differs from my answer in what, exactly?
p.marino