More Efficient Primary Keys

#1

Can you give us a recommendation as we can represent the Key (UUID) most efficient?
Both in terms of memory usage of the database files, memory usage of the JVM and efficiency for queries.

We already need the key before the entities are persisted so that we can build even references.

a) Composite Primary Key  with two Longs
b) Embedded Primary Key with two Longs
c) Furthermore, as String (but reduced to a 22 char instead of actual 36 char)
  - Would it bring someting to specify the length with the Column annotation?
d) Or would you recommend something else?

Finally, how much performance improvement would bring a switch to a single long?

#2

Unfortunately it is impossible to evaluate the impact of different methods on a specific application without a proper benchmark that reflects the activity of that application.

Options (a) and (b) are equivalent for the database engine. In both cases it is a composite primary key with the same size and structure. (b) requires instantiation of an additional Java object (the embedded key) so theoretically it is slower, but probably this difference is negligible.

String keys are slower than numeric keys, and a single long is more efficient (and better if allocated sequentially rather than randomly). It is unclear if a composite of two longs can produce any performance gain over a single string.

ObjectDB Support

Reply