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.