Hi,
I'm using Firebird and created a table, called EVENTS. The columns are:
id (INT) | name (VARCHAR) | category (INT) | website (VARCHAR) | lat (DOUBLE) | lon (DOUBLE)
Now a user wants to search for events in a certain radius around him, but entered only two or three letters of his home city. So we've got - lets say - 200 possible cities with their latitudes and longitudes. So my SQL query looks like:
SELECT id FROM events WHERE ((lat BETWEEN 30.09 AND 30.12) AND (lon BETWEEN 40.78 AND 40.81)) OR ((lat BETWEEN 30.09 AND 30.12) AND (lon BETWEEN 40.78 AND 40.81)) OR ...
So we get 200 constraints in the WHERE clause and it takes seconds to actually get the result.
I know the query might look horrible. But are the many constraints really the bottleneck? Can this query be optimized?
Thanks, Stefan