知识卡片
查询拆分须按候选量权衡
把通用到期发票先从数据库查出,再在内存用拖欠规格过滤,可让仓储查询更通用、规格更清楚;代价是多取回并遍历候选。原书强调能否接受取决于实际情况,也给出专门 SQL 或存储过程等选择。这里是设计成本判断,没有实测性能结论。参见[[同一规格查询可有不同执行路径]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第09章|How to Model Less Obvious Kinds of Concepts · 查看原书依据
That is acceptable, but depending on the relative numbers of Invoices that are overdue compared to those that are delinquent, an intermediate solution that leaves the REPOSITORY methods more generic may still give good performance, while keeping the SPECIFICATION more self-explanatory.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第70章《How to Model Less Obvious Kinds of Concepts》,Selection (or Querying)(源文件:_epub-src/0321125215_ch09lev1sec2_split_000.html)
- 结论依据:原文明确指出先广查再内存过滤的额外代价取决于具体场景。
- 原始内容:The REPOSITORY now has a very specialized query that most likely will be used only in this case. That is acceptable, but depending on the relative numbers of Invoices that are overdue compared to those that are delinquent, an intermediate solution that leaves the REPOSITORY methods more generic may still give good performance, while keeping the SPECIFICATION more self-explanatory. [...] We'll take a performance hit with this code, because we pull out more Invoices and then have to select from them in memory. Whether this is an acceptable cost for the better factoring of responsibility depends entirely on circumstances. There are many ways to implement the interactions between SPECIFICATIONS and REPOSITORIES , to take advantage of the development platform, while keeping the basic responsibilities in place. Sometimes, to improve performance, or more likely to tighten security, queries may be implemented on the server as stored procedures.