nitrite / nitrite-java

NoSQL embedded document store for Java
https://bit.ly/no2db
Apache License 2.0
836 stars 95 forks source link

array index in 4.3 #1051

Open catapop84 opened 1 month ago

catapop84 commented 1 month ago

Just tested your database to see if it's suited to be embedded in our app. We have a collection of users and each user can have one or more email addresses. So we created a field emails as an array of strings

We did a search without index on emails field and with index on emails field and the duration is roughly the same around 170-180ms for a 15k+ documents collection.

Does array index really work because I didn't saw any speed improvements with or without index. Tested also unique vs non unique index and the same result.

If we create a field email of type string (not array) the index works: 30-40ms with index vs 180-190ms without index.

Tested in java , version 4.3 with rocksdb module. The code we did the test is

        long start = System.nanoTime();
        collection.find(where("emails").elemMatch($.eq("example@gmail.com"))).forEach(System.out::println);
        long end = System.nanoTime();
        Log.info("Time taken: {} ms", (end - start) / 1_000_000);
anidotnet commented 1 week ago

I'll take a look at it.