How efficient is the in condition query of MYSQL? Is there a good query optimization solution? (Specific use cases are described in this section)

Source: Internet
Author: User
In my APP, there is a function similar to that of the Prestige circle of friends. Is to view the sharing of friends. The specific SQL statement is: selectphoto. * fromphotowhereuserIdin (1, 2, 3,...) in is my friend. This is obtained in advance .... In my APP, there is a function similar to that of the Prestige circle of friends. Is to view the sharing of friends.
The specific SQL statement is:

select photo.* from photo where userId in(1,2,3,.........)

In conditions are my friends. This is obtained in advance.
There is a confusion here, that is, if there are 1000 friends, will the query efficiency be slow?
I don't know how PHP SNS are made ..

Everybody should have used it!
I have nearly 1000 friends. So what is the sharing of everyone's friends?
Yesselect inIn this way?

Reply content:

In my APP, there is a function similar to that of the Prestige circle of friends. Is to view the sharing of friends.
The specific SQL statement is:

select photo.* from photo where userId in(1,2,3,.........)

In conditions are my friends. This is obtained in advance.
There is a confusion here, that is, if there are 1000 friends, will the query efficiency be slow?
I don't know how PHP SNS are made ..

Everybody should have used it!
I have nearly 1000 friends. So what is the sharing of everyone's friends?
Yesselect inIn this way?

Index + paging + ajax automatic loading

Now a lot of nosql to achieve, such as redis set, that set provides a rich set of parallel operations, so the implementation is very good, this is a case http://blog.nosqlfan.com/html/2938.html

Sina Weibo uses redis in large quantities for business processing. There are many articles on the Internet for reference.



You can use redis to focus on friends and other keywords to google. There should be a lot of results.

Adding an index won't be too slow, or you can try union

Nosql with high usage

You can also use exists, for example:

select photo.* from photo p where exists (select 1 from user u where u.id = p.userId )

If the volume of data in the photo table is larger than that in the user table, we recommend that you use in. On the contrary, using exists is faster.

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.