data modeling - App engine datastore denormalization: index properties in the main entity or the denormalized entity? -
consider classic example of blog data modelling, have blog
entity many properties, , want list latest blogs in page.
it makes sense denormalize blogpost
entity blogpostsummary
entity shown in list view, avoiding fetching , deserializing many unwanted properties.
class blogpost(db.model): title = db.stringproperty() content = db.textproperty() created = db.dateproperty() ... class blogpostsummary(db.model): title = db.stringproperty() content_excerpt = db.textproperty()
the question is: entity should hold indexed properties? there 3 options:
1. index properties in both
- pros:
- easy query on both entities.
- cons:
- maintaining denormalized indexes expensive.
2. index properties in main entity only
- pros:
- indexing properties in main entity more safe, denormalized entity treated redundancy.
- cons:
- querying list view need double roundtrip datastore: 1 key-only query
blogpost
entities, followed batchblogpostsummary
.
- querying list view need double roundtrip datastore: 1 key-only query
3. index in denormalized entity only
- pros:
- the list view can built single query.
- cons:
- the main entity cannot queried properties anymore.
- the indexes occupy more space when denormalized entity child of main entity.
which option work better? there other options?
would double round trip datastore in option 2 problem?
this abstract question not have "correct" answer. choice of data model depends on specific requirements of project, including:
- usage patterns (how need access different data)
- update patterns (e.g. separating updated properties stable properties in order reduce write costs)
- average performance , extreme-case performance requirements (e.g average blog may have 10 posts, popular blog may have 10,000 posts)
- ability use memcache reduce datastore trips , improve performance
- data complexity (i.e. how many different kids of entities depend on particular entity kind)
- transaction requirements
- security , access roles considerations (e.g. not exposing private data mistake)
by way, there way model data in datastore - using child entities. example, blog posts may child entities of blog entity. way can retrieve blog posts single query providing parent key - without storing post ids or keys in blog entity or blog id/key in post entities.
Comments
Post a Comment