5
批量查询,例如 List<User>的 name 和 age,去 DB 中查询出 List<People>...
source link: https://www.v2ex.com/t/816381
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
批量查询,例如 List<User>的 name 和 age,去 DB 中查询出 List<People>,怎么处理这个?
shadow1949 · 1 天前 · 1074 次点击name 和 age 才能唯一标识 People 中的一条数据。 这种批量查询怎么实现性能比较好?代码或者 SQL 什么都可以。
16 条回复 • 2021-11-19 15:30:18 +08:00
c6h6benzene 11 小时 50 分钟前 via iPhone
zgc27wo 7 小时 11 分钟前
要不这样?
1. 先数据库获取所有的<People> name,age,id 的组合
2. 基于 name-age 分组的[分组 A]
3. 然后匹配自己<User>的 name 和 age 获取 name-age 去[分组 A]找到对应的 Id 集合
4. 再去数据库通过 id 集合查找对应的<People>
相当于给 name,age,id 打了联合索引
1. 先数据库获取所有的<People> name,age,id 的组合
2. 基于 name-age 分组的[分组 A]
3. 然后匹配自己<User>的 name 和 age 获取 name-age 去[分组 A]找到对应的 Id 集合
4. 再去数据库通过 id 集合查找对应的<People>
相当于给 name,age,id 打了联合索引
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK