1
votes

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. 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)

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.

What is your advice ?

2
What makes a custom index costly? They are very efficient. - Rick Mangi
Additional Datastore Writes are performed for every custom index you create, so that's where new costs come in. - alex

2 Answers

1
votes

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. It will be very fast. The index will be created for you automatically, no extra work on your part.

0
votes

I've double checked in the Objectify mailing list and there is no restriction to use getBookingsByDate with Parent and without 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.