Multiple @ID

#1

I have an entity with 2 @ID

@Entity public class TheTable extends AbstractMMODataObject {

@Id String userId;

@Id long range;

It was a mistake, I really should have just made range an @Index but it already has millions of records in it.

I am wondering if I query select t from TheTable t where range<:bla

without querying the userId.. will this be bad for performance?

From my understanding, if the range were an index that would have been fine.. but since it's a primary key, I'm not sure if it would perform well like an index, or would it be slow?

 

#2

Retrieval by range only is expected to be less efficient. Actually it may be worse than retrieval by the second field of a composite index. The objects are probably ordered with userId as the primary key and range as the secondary key, so retrieval by range will require a full scan rather than just a lookup. But this is a full scan of the data pages not of index pages, so probably more pages and more work (unless you need to retrieve many objects, e.g. 10% of the total objects, in that case scanning the data may be more efficient).

It is recommended to repair the database. Unfortunately you cannot change existing primary keys, so you may have copy all the existing objects to a new class and later discard the old class (taking care of references, etc.).

An easier solution could be to copy the range value to a new indexed field and put 0 in the current range. The primary key will still not be optimal, but the performance hit may be negligible.

ObjectDB Support

Reply