核心数据设计原则 [英] Core Data design principles

查看:171
本文介绍了核心数据设计原则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始阅读本指南:



我得到他们,但基本上,如果我遵循第一个实现一个自定义类到实体从哪个类代表子项也继承 -statement,那么我所有的实体将被放在同一个表中。这可能会导致性能问题,根据注意



我会遇到多少性能打击创建一个自定义超级实体?

解决方案

您可以使用继承机制获取默认数据库结构。从您的链接:


如果您有许多类似的实体,可以将公共属性确定为超级,也称为一个父实体。


没有矛盾。该文档只是告诉您使用某个设施时数据库结构将会是什么。 (而且它是用于继承的标准数据库表成语。)使用实体继承机制自动声明并实现默认的父 - 子类继承功能以及父表。否则你手工执行任何父子类的继承声明和实现。每个都具有一定的性能和其他特点。



设计涉及多个维度之间的成本和收益之间的权衡。 性能本身涉及多个维度,在给定的应用程序使用模式之外没有任何意义。其他与此相关的维度包括构建和维护的复杂性。



如果您将实体查询为足够多的父母,那么最好将所有父数据放在自己的表中。但是,如果在查询给定子类型时很少要求父数据,或者如果您足够频繁地需要子数据和父数据,则只能在子表或表中具有父数据。但请注意,每种设计在其他类型的查询中表现较差。


I just started reading this guide: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/KeyConcepts.html#//apple_ref/doc/uid/TP40001075-CH30-SW1

And it basically has (in my opinion) two big contradictions:

I get them both, but basically, if I follow the first "implement a custom class to the entity from which classes representing subentities also inherit"-statement, then ALL my entities will be put in the same table. Which could cause performance issues, according to the NOTE.

How big of a performance hit would I run into of it create a "custom super entity"?

解决方案

You can use the inheritance mechanism to get a default database structure. From your link:

If you have a number of entities that are similar, you can factor the common properties into a superentity, also known as a parent entity.

There is no contradiction. The documentation is just telling you what the database structure is going to be when you use a certain facility. (And it is the standard database table idiom for inheritance.) Using the entity inheritance mechanism automatically declares and implements default parent-child class inheritance functionality along with a parent table. Otherwise you do any parent-child class inheritance declaration and implementation by hand. Each comes with certain performance and other characteristics.

Design involves tradeoffs between costs and benefits over multiple dimensions. "Performance" itself involves multiple dimensions, and has no meaning outside of given application usage patterns. Other dimensions relevant here include complexity of both construction and maintenance.

If you query about entities as parents sufficiently frequently then it can be better to have all parent data in its own table. But if you sufficiently rarely ask for the parent data while querying about a given child type or if you sufficiently frequently need both child and parent data then it can be better to only have parent data in the child tables or table. But notice that each design performs worse at the other kind of query.

这篇关于核心数据设计原则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆