Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:11:24+00:00 2026-06-16T05:11:24+00:00

I am working with a geospatial database from geonames.org . I currently have an

  • 0

I am working with a geospatial database from geonames.org. I currently have an autocompletion input field on my website which forwards search terms to the database and returns appropriate results. One important thing is, that the results must be ordered by country.

The table from which i select is about 900.000 rows large and is created with:

CREATE TABLE IF NOT EXISTS `geonames` (
`id` integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
`country_code` char(2) NOT NULL,
`postal_code` varchar(20) NOT NULL,
`place_name` varchar(180) NOT NULL,
...
FULLTEXT(country_code),
FULLTEXT(postal_code),
FULLTEXT(place_name)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

A typical statement looks like this:

SELECT postal_code, place_name FROM geonames WHERE LOWER(`place_name`)
LIKE 'washin%' ORDER BY FIELD (country_code, 'JE', 'GB', 'FR', 'LI', 'CH',
'DK', 'LU', 'BE', 'NL', ... many more countries in that list ... ) DESC;

I use the FULLTEXT indices for speeding up the WHERE place_name LIKE 'washin%' part. But still the query is somewhat slow. The task of the SQL query is to search for every place_name in the table which matches 'washin%' and then sort the results according to the countries specified. Is the query slow because of the large amount of data being requested at one time? If yes, how could i decrease the runtime at this bottleneck?

I am no expert in MySQL by any means, so i would be glad if someone more experienced could help me out to speed up the shown SQL query or at least point me in a direction where to go for optimization.

Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:11:25+00:00Added an answer on June 16, 2026 at 5:11 am

    You should avoid LOWER in your where clause because then an index can’t be used efficiently:

    SELECT postal_code, place_name FROM geonames
    WHERE `place_name` LIKE 'washin%'
    ORDER BY FIELD(country_code, 'JE', 'GB',  ...) DESC;
    

    Instead you should use a case insensitive collation. The collations ending in _ci are case insensitive. Case sensitive collations end in _cs.

    Also your full text index will not help you for queries using LIKE. You should use a B-TREE index on place_name.

    B-Tree Index Characteristics

    A B-tree index can be used for column comparisons in expressions that use the =, >, >=, <, <=, or BETWEEN operators. The index also can be used for LIKE comparisons if the argument to LIKE is a constant string that does not start with a wildcard character.

    You could also choose to include country_code and postal_code in the index (but not as the first column). This will then give you a covering index for your query.

    The ORDER BY will also be unable to use an index efficiently because of the FIELD call, but if the number of results returned is relatively small it shouldn’t be a problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Access 2010 database with information from Geonames. The table name is
I'm working on a Geo/Spatial search where I'm looking for nearby points. I have
I'm working on a a database schema to store geospatial datas, I need to
How can we have Solr 3.6.1 return the Geospatial search results both filtered by
i'm working on an application that lets users search for trips from point A
Working in iOS 5 I have read a list of file names from my
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working on game where plates will be falling from top to bottom. Some plates
Working with cakePHP this is my situation: I have Users and Order s. Order
Working with some basic java apps on CentOS 5 linux and I have my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.