Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

How to make this query run faster? Table contains over 2 million rows of data and takes around 30 to 120 seconds to process the query.

SELECT
  INET_NTOA(blocks.startIpNum),
  INET_NTOA(blocks.endIpNum), 
  locations.country, 
  locations.city
FROM blocks
  JOIN locations
  ON blocks.locId = locations.locId
WHERE locations.country = 'US'
LIMIT 0, 10
share

migration rejected from stackoverflow.com Apr 29 at 15:44

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as too broad by ypercube, Paul White, RolandoMySQLDBA, Mark Storey-Smith, Max Vernon Apr 29 at 15:44

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Run an explain and go from there. –  Mike B Mar 27 at 19:20
2  
Do your tables have indexes? Is caching a possibility? –  rednaw Mar 27 at 19:20
3  
If you want us to help optimize a query, you need to show us the table and index definitions, as well as row counts for each of the tables. Maybe your tables are defined poorly. Maybe the indexes aren't created correctly. Maybe you don't have an index on that column you thought you did. Without seeing the table and index definitions, we can't tell. We also need row counts because that can affect query optimization greatly. If you know how to do an EXPLAIN or get an execution plan, put the results in the question as well. If you have no indexes, visit use-the-index-luke.com ASAP. –  Andy Lester Mar 27 at 20:41