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

  • Home
  • SEARCH
  • 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 6134743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:23:38+00:00 2026-05-23T17:23:38+00:00

I have a mySQL query which takes a long time to process. I am

  • 0

I have a mySQL query which takes a long time to process. I am querying a large table of IP ranges which relate to country codes to discover the country of origin for each IP in the url_click table. (IP database from from hxxp://ip-to-country.webhosting.info/)

It works brilliantly, albeit slowly.

Is there a more efficient way to write this query?

Table and output JPG: http://tiny.cx/a4e00d

SELECT ip_addr AS IP, geo_ip.ctry, count(ip_addr) as count
FROM `admin_adfly`.`url_click`,admin_adfly.geo_ip
WHERE INET_ATON (ip_addr) 
BETWEEN geo_ip.ipfrom AND geo_ip.ipto 
AND url_id = 165 
GROUP BY ip_addr;
  • 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-23T17:23:38+00:00Added an answer on May 23, 2026 at 5:23 pm

    The use of a function in the join between the two tables is going to be slower than a normal join, so you probably want to defer that particular operation as long as possible. So, I’d summarize the data and then join it:

    SELECT S.IP_Addr, G.Ctry AS Country, S.Count
      FROM (SELECT ip_addr, COUNT(ip_addr) AS Count
              FROM admin_adfly.url_click 
             WHERE url_id = 165 
             GROUP BY ip_addr) AS S
      JOIN admin_adfly.geo_ip AS G
        ON INET_ATON (ip_addr) BETWEEN geo_ip.ipfrom AND geo_ip.ipto;
    

    If you can redesign the schema and are going to be doing a lot of this analysis, rework one of the two tables so that the join condition doesn’t need to use INET_ATON().

    Presumably, you have an index on the url_id column; that is the only one that will give you much benefit here.

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

Sidebar

Related Questions

I have a MySQL UPDATE query which takes a long time to complete. Am
I have a complicated MySQL query which takes a lot of time, selecting from
I faced with MySql query which takes too much CPU and time to execute
I have a SQL query that takes a very long time to run on
I have mysql Proxy running which takes a query, performs an md5 on it,
I have a MySQL query in which I want to include a list of
I have the following mysql query which I am running with php like so.
I have this query which works correctly in MySQL. More background on it here
I have a query which works fine in MySQL, but when I run it
I have the following query which works fine with MySQL but refuses to work

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.