New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch for enablig/disabling typeName (entity) index in MongoDB #519

Closed
croffler opened this Issue Mar 13, 2017 · 8 comments

Comments

Projects
None yet
2 participants
@croffler

croffler commented Mar 13, 2017

The mongoSchemaManager drops the following index on startup:
dropIndexIfExists(snapshots, GLOBAL_ID_ENTITY);

To speed up some of my queries I created an index on globalId.entity. Unfortunately every time I restart my app the index gets dropped.

Can this made configurable, to drop or not to drop ?

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Mar 13, 2017

Are you sure that javers still uses this index?

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Mar 13, 2017

I mean, this is only the name of a class, like Person. Index on this field wouldn't be selective in most cases and would be useful only when quering byClass. Do you have lot of different classes?

@croffler

This comment has been minimized.

croffler commented Mar 13, 2017

Yes I have about 150 different entities and growing.

For example:
List snapshots = getJavers().findSnapshots(QueryBuilder.byClass(klass).build());

JQL produces this:
{ $orderby: { commitMetadata.id: -1 }, $query: { $or: [ { globalId_key: /^rw.gov.ifmis.payment.domain.PaymentOrder/.*/, globalId.entity: { $exists: true } } ] } }
You can now imagine that this is very slow with 20million snapshots(and growing) and 150 different classes.

Here is my use case:
I want to find all snapshots for a PaymentOrder with paymentOderNumber="xxx"

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Mar 13, 2017

ok, so as a quick fix, lets remove this statement:

//schema migration script from JaVers 2.0 to 2.1
        dropIndexIfExists(snapshots, GLOBAL_ID_ENTITY);

and you will be able to add index on your own

would you create a Pull Request?

@croffler

This comment has been minimized.

croffler commented Mar 13, 2017

Hang on here ... there was a reason why thats implemented the way it is ...
Let me just create an index with a different name on that property in mongo .... and I should be ok.
In the meantime we have time to think about this a bit more .... perhaps this could be a configuration property that can be set with spring property injection ....(dropIndexes="${javers.dropIndexes}")

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Mar 14, 2017

ok, switch would be better. I would call it useTypeNameIndex, with default value false

@croffler

This comment has been minimized.

croffler commented Mar 14, 2017

sounds good

@bartoszwalacik bartoszwalacik changed the title from Drop indexes on startup to Switch for enablig/disabling typeName (entity) index in MongoDB Mar 14, 2017

bartoszwalacik added a commit that referenced this issue Dec 20, 2017

bartoszwalacik added a commit that referenced this issue Dec 20, 2017

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Dec 20, 2017

released in 3.7.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment