How to optimize MySQL in query

Source: Internet
Author: User
MySQL Range query:

$id_list = implode(',',$arr);$sql = "select name,id from user where id in ($id_list)";//可能还会left join连表//如果$arr数组非常大会很慢,对这种查询如何优化?

Reply content:

MySQL Range query:

$id_list = implode(',',$arr);$sql = "select name,id from user where id in ($id_list)";//可能还会left join连表//如果$arr数组非常大会很慢,对这种查询如何优化?

Several scenarios are available:

1) If the memory is sufficient (the table is not particularly large), you can use MySQL's memory engine, that is, to put the query in RAM in the line. The memory engine can use the hash index.

2) using Memcache or Redis as the cache, the equivalent of every query should be multi_get once, no hit back to MySQL check, can greatly reduce the number of MySQL in the back. Once the query comes back, Multi_set once more. If Memcache or Redis is sharding, then this is not very efficient, because it is part of a server query.

3) can be used in some distributed key-value storage, such as can be subscribed to or follow situation, such as data a modified, then all of the subscribers to a subscription A is written into their own inbox, the inbox every time as long as O (1) Get OK. In some large v a lot of places (a few users of follower particularly many), will be a bunch of followers the most people data sheet out of the cache with a similar in-method query, the remaining few newsfeed directly into the Inbox, this one in storage and time compromise.

I have seen Csdn's in, that big long-channeling in numbers, I was scared to pee.
Although I do not know how to optimize this, but I know the general need for this is the best consideration with a layer of high-speed cache, or simply put all these I/O in Redis, and regularly write to the database.
Then, wait for the great God to answer this question.

  • Related Article

    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.