type
status
date
slug
summary
tags
category
icon
password
TL;DR:把在循环中的n次小查询转换为一次大查询可以节省大量性能。
(比如数据库会做优化,而n次小查询则不好做优化)
📝 主旨内容
简单来说,
1 → 有些业务逻辑会先进行一次查询,查询n个实体。
n → 接下来在一个循环中通过n个实体的字段去寻找其引用的实体。
这就产生了1次大查询和n次小查询,而n次的大查询实际上会更浪费数据库性能。 ‣
书籍类型表
category_id | category_name |
1 | 科幻 |
2 | 经典文学 |
… | … |
30 | 推理小说 |
书籍表
book_isbn | book_name | book_category_id |
2024012550 | 三体 | 1 |
2024012551 | 活着 | 2 |
… | … | … |
2024025542 | 血字的研究 | 30 |
不好的做法 (导致 N+1):
entity.memory_cache
观点2
引用的话语
🤗 总结归纳
总结文章的内容
📎 参考文章
- 一些引用
- 引用文章
有关Notion安装或者使用上的问题,欢迎您在底部评论区留言,一起交流~
- Author:Narohaz
- URL:https://narohaz.top/article/1d35fe46-04d5-80b4-a1cf-ea800aee8b94
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!