当前位置:网站首页>DGS之N+1选择问题
DGS之N+1选择问题
2022-07-23 23:30:00 【你好y】
N+1选择问题
[ORM(对象关系映射)中的“N+1 选择问题”是什么?](https://stackoverflow.com/questions/97197/what-is-the-n1-selects-problem-in-orm-object-relational-mapping)
假设你有一个汽车对象的集合(数据库行),而每个汽车都有一个车轮对象的集合(也是行)。换句话说,汽车→车轮是一个1对多的关系。
现在,假设你需要遍历所有的汽车,并为每个汽车打印出一个车轮的列表。天真的O/R实现将做以下工作。
SELECT * FROM Cars;
之后遍历每个车
SELECT * FROM Wheel WHERE CarId = ?
换句话说,你有一个关于汽车的选择,然后有N个额外的选择,其中N是汽车的总数。
另外,我们也可以得到所有的轮子,并在内存中进行查找。
SELECT * FROM Wheel
这就把到数据库的往返次数从N+1减少到2。大多数ORM工具给你几种方法来防止N+1选择。
获取按 CarId 排序的所有车轮(1 个选择),如果需要比 CarId 更多的详细信息,请对所有汽车进行第二次查询(总共 2 个查询)。现在打印出来是最佳的,不需要索引或辅助存储
边栏推荐
- FreeRTOS personal notes - suspend / unhook tasks
- 48: Chapter 5: develop admin management service: 1: create sub project [imooc news dev Service Admin], management service module;
- Navicat15 download and installation
- Redis管道技术/分区
- ES6 other syntax and extended syntax summary
- Lu Xia action | Source Kai Digital: Existing Mode or open source innovation?
- PHP(2)
- This article will show you what typescript is
- TAP 系列文章4 | 基于 Backstage 的 TAP 开发者门户
- [nuxt 3] (IX) server routing
猜你喜欢

Basic operations of AutoCAD

二,数字逻辑功能单元

AutoCAD advanced operation

TAP 系列文章9 | 应用开发加速器

pwn1_sctf_2016

Analysis of video capability and future development trend based on NVR Technology

Getting started database days3

Tap series article 7 | easy to manage pipeline configuration

Redis pipeline technology / partition

Esp8266 nodemcu - get real-time weather from Suning API
随机推荐
Classification model - logistic regression, Fisher linear discriminant (SPSS)
Merge.Avhd into.Vhd manually in Hyper-V
二,数字逻辑功能单元
jarvisoj_level0
[第五空间2019 决赛]PWN5
Finding all paths between two points in a directed graph
cannot meet the needs of the people? How can programmers take private jobs to effectively increase their income?
Tap series article 5 | cloud native build service
Esp8266 nodemcu - get real-time weather from Suning API
ciscn_2019_c_1
[SSM]前后台协议联调①
ciscn_2019_n_8
[redis] redis installation and client redis cli use (batch operation)
Solidity-delegateCall插槽冲突分析与解决
Remember an experience of being cheated by the Internet
BGP选路,MPLS
Getting started database days2
dried food! Implicit sparse regularization effect in neural networks
Strncat () strncmp ()
Open source embedded sig in the openeuler community. Let's talk about its multi OS hybrid deployment framework