当前位置:网站首页>N+1 selection of DGS
N+1 selection of DGS
2022-07-23 23:39:00 【Hello y】
N+1 Choice problem
[ORM( Object relation mapping ) Medium “N+1 Choice problem ” What is it? ?](https://stackoverflow.com/questions/97197/what-is-the-n1-selects-problem-in-orm-object-relational-mapping)
Suppose you have a collection of car objects ( Database line ), Each car has a set of wheel objects ( It's OK ). let me put it another way , automobile → The wheel is a 1 Relationship to many .
Now? , Suppose you need to traverse all the cars , And print out a list of wheels for each car . Naive O/R The implementation will do the following .
SELECT * FROM Cars;
Then traverse each car
SELECT * FROM Wheel WHERE CarId = ?
let me put it another way , You have a choice about cars , Then there is N Two additional options , among N Is the total number of cars .
in addition , We can also get all the wheels , And search in memory .
SELECT * FROM Wheel
This reduces the number of round trips to the database from N+1 Reduced to 2. majority ORM Tools give you several ways to prevent N+1 choice .
Get by CarId Sort of all wheel (1 A choice ), If you need to compare CarId More details , Yes, please. all The car makes a second query ( in total 2 A query ). It's best to print it out now , No indexing or secondary storage is required
边栏推荐
- [redis] redis installation and client redis cli use (batch operation)
- strncat() strncmp()
- Sql156 average completion rate of each video
- Flask框架中如何进行数据库的迁移
- ret2text
- Android金九银十的面试你准备的怎么样了?最新Android面试真题汇总助你备战
- YOLOv4: Optimal Speed and Accuracy of Object Detection
- ciscn_ 2019_ n_ eight
- 1、 Simplification of digital logic
- Practical learning of SQL statements
猜你喜欢
随机推荐
anchor free yolov1
DDD思维架构学习
[audio and video technology] video quality evaluation MSU vqmt & Netflix vmaf
正则表达式及绕过案例
Software architecture
树形DP
STM32 can initialization details
第五章、实现Web适配器
ret2shellcode
ArraysList 与顺序表 ——模拟实现
USB to can device in nucleic acid extractor high performance USB interface can card
Basic operations of AutoCAD
在openEuler社区开源的Embedded SIG,来聊聊它的多 OS 混合部署框架
TOPSIS method (matlab)
Chapter III Organization Code
This article will show you what typescript is
Application of merging and sorting thought
[OGeek2019]babyrop
bjdctf_2020_babystack
pwn1_sctf_2016









