V2EX  ›  英汉词典

Eager Loading

定义 Definition

在软件开发中,“eager loading(预先加载/立即加载)”指在查询主对象时同时把相关联的数据一次性取回(而不是等到真正访问关联数据时才再去查询)。常用于 ORM(对象关系映射)以减少“多次小查询”(如 N+1 查询问题)。在不同框架里也可能被称为 prefetchincludejoin fetch 等;与之相对的是 lazy loading

发音 Pronunciation (IPA)

/ˈiːɡər ˈloʊdɪŋ/

例句 Examples

She enabled eager loading to fetch the user and their posts in one query.
她启用了预先加载,用一条查询同时取回用户及其帖子。

In high-traffic endpoints, eager loading can prevent the N+1 problem by loading related records upfront, but it may also increase memory usage if you load too much.
在高流量接口中,预先加载可以通过提前加载关联记录来避免 N+1 问题,但如果加载过多,也可能增加内存占用。

词源 Etymology

Eager 原意是“急切的、迫不及待的”,在计算机语境中可理解为“立即执行/提前做”;loading 是“加载”。合起来表示“在需要之前就先把数据加载好”。这个说法在数据库与 ORM 实践中逐渐固定,用来对比 lazy loading(延迟加载)

相关词 Related Words

文学与著作中的用例 Literary Works

  • Patterns of Enterprise Application Architecture(Martin Fowler)
  • Hibernate in Action(常讨论 fetch strategy,包括 eager/lazy)
  • Ruby on Rails Guides(Active Record Associations 中涉及 includes/eager loading)
  • Django Documentationselect_related/prefetch_related 常与 eager loading 对应)
  • SQLAlchemy Documentation(Loader Strategies 中包含 eager loading 相关策略)
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   683 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms · UTC 22:11 · PVG 06:11 · LAX 14:11 · JFK 17:11
♥ Do have faith in what you're doing.