Database Manual / Data Modeling / Schema Design Patterns

Handle Computed Values处理计算值

If you want to return calculated data values to your application, you can improve performance by running computations in your database rather than when the data is requested. 如果你想将计算出的数据值返回给应用程序,你可以通过在数据库中运行计算来提高性能,而不是在请求数据时运行。The application may require either precise calculations or approximate results. By using the Computed and the Approximation schema patterns, you can pre-compute and store the resulting values ahead of time (for example on insert or with a periodic task) so they are readily available when you request the data.应用程序可能需要精确计算或近似结果。通过使用ComputedApproximation模式,您可以提前预计算和存储结果值(例如在插入或周期性任务时),以便在您请求数据时随时可用。

Use Cases用例

Scenario场景Design Pattern Application设计模式应用
A consumer reporting company compiles data from several different sources to create rank-ordered lists like the "100 Best-Reviewed Gadgets".一家消费者报告公司汇编了来自几个不同来源的数据,以创建排名有序的列表,如“100个最佳评论小工具”。Use the computed pattern to update the list periodically while the underlying data is updated independently.在独立更新基础数据的同时,使用计算模式定期更新列表。
Your application tracks the population of a city that contains 40,000 people.应用程序跟踪一个拥有40000人的城市的人口。Use the approximation pattern to update the population value in increments of 100. The computations are not precise but they are statistically valid.使用近似模式以100为增量更新人口值。这些计算并不精确,但在统计上是有效的。

Get Started开始使用

To learn how to apply design patterns for computed values, see these pages:要了解如何将设计模式应用于计算值,请参阅以下页面:

Learn More了解更多