For efficient IP address range query, thank you.

Source: Internet
Author: User
For efficient IP address segment query, thank you for the MYSQL database:

User table (user), which contains about 2000 pieces of data, has an IP field (which has been converted to an integer );
Ip address table (IP address), 0.44 million data records, an IP address start Field, an IP address end field (which has been converted to an integer), and an ip address physical address field;

Now we need to use an SQL script to find the physical address corresponding to the IP address of each record in user table. it is too slow to use the following SQL script to query data.

select user.*, ip.addressfrom user left join ipon user.ip between ip.ipstart and ip.ipend



How to query data more efficiently? thank you.


Reply to discussion (solution)

Adjust according to EXPLAIN information

Adjust according to EXPLAIN information



What do you mean? thank you!

Execute EXPLAIN your query command
Mysql will tell you where to optimize it.


Adjust according to EXPLAIN information



What do you mean? thank you!


The moderator means that you explain/desc SQL statement analysis

Too complicated, too complicated,

1 + 1 = 2 is very simple, but only 1 + 1 = 2 is not eaten
1 + 1 = 1 is very complicated. people who study 1 + 1 = 1 will always have meals.

The moderator's words are too esoteric...

Insightful

The moderator taught me how to optimize it. I will learn from you,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.