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 6629563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:16:43+00:00 2026-05-25T22:16:43+00:00

I have a InnoDB MySql Geo ID table that has ~ 1 million rows.

  • 0

I have a InnoDB MySql Geo ID table that has ~ 1 million rows. The table structure is this:

CREATE TABLE `geoid` (
   `start_ip` int(11) NOT NULL,
   `end_ip` int(11) NOT NULL,
   `city` varchar(64) NOT NULL,
   `region` char(2) NOT NULL,
   PRIMARY KEY (`start_ip`,`end_ip`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

There will only be one type query ran against this table:

SELECT city, region FROM geoid WHERE 1259650516 BETWEEN start_ip AND end_ip

This query takes about ~ .4228 sec, which is not super slow but not incredibly fast ether.

My question is: How can I further optimize my table for this single query?

I have tried the following things:

  1. Change the Storage Engine to MyISAM, this made the query take about 1.9 sec.
  2. Use the WHERE statement ‘WHERE geoid.start_ip <= 1259650516 AND 1259650516 <= geoid.end_ip’. But that takes about .5 sec to execute instead of .4 ish.

I have removed all useless rows from the table to make it smaller. I need all 1 million rows.

UPDATE / SOLUTION

Thanks to the article below, here is what I did to fix this problem. (just to complete this answer for anyone else interested)

I added a new column to the above table:

ALTER TABLE `geoid` ADD `geoip` LINESTRING NOT NULL

I then filled the new column with the geo data from start_ip and end_ip

GeomFromText(CONCAT('LINESTRING(', start_ip, ' -1, ', end_ip, ' 1)'))

I then created the SPATIAL INDEX on the new column

CREATE SPATIAL INDEX geoip_index ON geoid(geoip);

From there, all you have to do is change your query to:

SELECT city, region FROM geoid WHERE MBRContains(geoip, GeomFromText(CONCAT('POINT(', 1259650516, ' 0)')));

AND YOUR DONE. This took the query down from .42 sec to .0003 sec!!!!!!!

I love this INDEX. Thank you. Hope it helps.

  • 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-05-25T22:16:43+00:00Added an answer on May 25, 2026 at 10:16 pm

    Try adding an index on end_ip. This should make the query about twice as fast in some cases.

    For much better perfomance you need to use a SPATIAL index, as explained in this article.

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

Sidebar

Related Questions

I have a MySQL InnoDB table, events , with 3 rows: event_id ---> int
I have a MySQL-InnoDB table with 350,000+ rows, containing a couple of things like
I have a MySQL InnoDB table laid out like so: id (int), run_id (int),
I have a MySQL(innodb) table 'items' with the following characteristics Large number of rows,
I have an InnoDB table in MySQL which used to contain about 600k rows.
I have an PHP/MySQL eCommerce application that has a few innoDB tables (for the
I have a MySQL InnoDB table on a RedHat Enterprise Linux 4 server, and
I have a MySQL InnoDB table with a status column. The status can be
I have a MySQL InnoDB table with 238 columns. 56 of them are TEXT
I have an enormous MySQL (InnoDB) database with millions of rows in the sessions

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.