mysql reverse lookup optimization record

There are problems related to the database, I have a table, there are three, after the customer to simplify the table structure is as follows:

id name source
1 Customer 1 a channel
2 Customer 1 b Channel
3 Customer 2 a channel
4 Customer 3 a channel
5 Customer 1 c channels

I now find the logic is passed in accordance with the id name, and then to find the id based on name; for example: id is passed in 1 and 3, according to the two id name is found in the customer 1 and customer 2, then according to this two name to query id, available 1,2,3,5, translated into sql is below.

select id,name from customer where name in(select name from customer where id in(1,3));

There are thousands of customers, there are about repeat customers about 1200, there is no better way to optimize? Particularly passed in id, about forty thousand id, so the implementation is slow. Now id and name index has been done.
This problem record it, I'm trying to find a good solution to this problem is that multiple iterations systems, docking, old issues left over. Changes to the original data, then a lot of influence!

The solution is not to limit, the external cache can redis like.

Guess you like

Origin blog.csdn.net/zhezhebie/article/details/91985121
Recommended