分表 - mysql分库后做关联查询的疑问?
黄舟
黄舟 2017-04-17 11:26:51
0
1
662

是这样的,我们的现在对数据库做了水平拆分。把用户和订单分在两个库中,由于之前没接触过分库,对关联查询有些疑问。现在有一个需求,查询所有用户及其相关的订单列表,首先查询所有订单,然后在根据每个订单关联的用户查询用户表,这样的不就是有多少条订单就要产生多少条查询用户信息的SQL了。这个做法是不是通用的做法,有没有其他好的办法?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
黄舟

1. I think it would be better to check all users first and then check the order table information based on users, except of course if the order is smaller than the number of users.
2. When checking orders first and then users, users who have already checked do not need to check again
3. If it is a cross-database join on the same machine, you can use [database name].[table name] to join cross-database, pay attention to the permissions.
4. If they are on different machines, you can link the remote tables through the federated engine.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template