💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
N+1一般是一对多关系中常见的: 如顾客表和订单表,一个客户对应多个订单 N+1查询 的表达式如下: ``` select * from user; select * from orders where user_id=1; select * from orders where user_id=2; select * from orders where user_id=3; select * from orders where user_id=4; .... ``` >[danger]上面很消耗性能:解决办法是 in 或者 join连接查询 >TP框架中的with就是组装in或者left 解决N+1查询的 ``` select * from user left outer join orders on user.id=orders.user_id; //in select * from user; select * from orders where user_id in(1,2,3,4,...); ```