I am using rails
and geocoder
gem with postgres
database. Therefore I have to add the latitude
and longitude
fields to database. So generally speaking isnt it better to add indexing to those fields for faster querying?
If you end up querying database for records using latitude and longitude, you'll definitely benefit from adding an index. Indexes will be used not only for exact matching queries, but also for comparison queries, such as select * from table_name where latitude between 30 and 40 and longitude > 50
.
Depending on the queries and the number of records, postgres query planner will choose the most optimal way to find matching records (either sequential scan, or index scan).