企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
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,...); ```