简体   繁体   English

Appengine数据存储区父级或索引

[英]Appengine datastore parent or index

I'm designing my application data model and I have a doubt, whether to use parent or a simple index. 我正在设计我的应用程序数据模型,并且不确定是使用父级还是简单索引。

Site{
  @Id Long id;
}

Booking{
  @Id Long id;
  @Index/Parent Key<Site> site;
  @Index Date date;
}

My 2 entities are Bookings and Sites . 我的2个实体是Bookings and Sites The relationship is that a Site has many Bookings . 关系是一个站点有很多预订 I want to retrieve bookings in 2 ways: getBookingBySiteAndDate (Key site,Date date) and getBookingsByDate (Date date) 我想以两种方式检索预订: getBookingBySiteAndDate (关键站点,日期)和getBookingsByDate (日期)

The s*econd query* is not efficient if I use Parent since I need the Booking's site to retrieve all the bookings. 如果使用父母,第二个查询*效率不高,因为我需要预订的网站来检索所有预订。 This Site might have been deleted. 该站点可能已被删除。

The first query is not efficient if I use Index since I need a custom index in (date, site) and is costly. 如果我使用索引,第一个查询效率不高,因为我需要在(日期,网站)中使用自定义索引,而且成本很高。 Appart of that the creations are not consistent since the bookings don't have entity group and I have a limitation of 1w/s. 由于预订没有实体组并且我的限制为1w / s,因此创作不一致。

What is your advice ? 您有什么建议?

I would not use a parent. 我不会使用父母。 The only value I've seen for parents is if you need to create a transaction group. 我为父母看到的唯一价值是您是否需要创建交易组。 In your example I would just store the id for the Site in the booking table and create an index for the getBookingBySiteAndDate query. 在您的示例中,我只将站点的ID存储在预订表中,并为getBookingBySiteAndDate查询创建索引。 It will be very fast. 很快。 The index will be created for you automatically, no extra work on your part. 索引将自动为您创建,无需您做任何额外的工作。

I've double checked in the Objectify mailing list and there is no restriction to use getBookingsByDate with Parent and without Site Id. 我已经在Objectify邮件列表中进行了双重检查,并且没有将getBookingsByDate与Parent一起使用且没有Site Id的限制。

The solution they recommended me is to use @Parent since is faster and you don't need a double index on Site-Date. 他们推荐我的解决方案是使用@Parent,因为它速度更快,并且您不需要Site-Date上的双索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM