Creating an index on a key

765 views
Skip to first unread message

0x6e6562

unread,
May 15, 2012, 1:17:53 PM5/15/12
to Hazelcast
Hi,

I've got a use case where I'm using an object with 3 fields as a key
of a map. I'd like to query the map by matching on one of the three
fields of the key. I've implemented a custom predicate to match the
particular field from the MapEntry object. I'd now like to add an
index to the map to improve the query performance, but it is not clear
to me from the API what call I should make. Is there an example
somewhere of indexing the key of a map?

Cheers,

Ben

0x6e6562

unread,
May 16, 2012, 7:13:15 AM5/16/12
to Hazelcast
On May 15, 6:17 pm, 0x6e6562 <0x6e6...@gmail.com> wrote:
> I'd now like to add an
> index to the map to improve the query performance, but it is not clear
> to me from the API what call I should make. Is there an example
> somewhere of indexing the key of a map?

To an extent, I think I may have answered my own question empirically
- I constructed a stripped down test suite that can just be run with a
simple mvn test (https://github.com/0x6e6562/hazelcase-key-index/blob/
master/src/test/java/com/acme/KeyIndexTest.java). This test indicates
a sublinear cost of querying the map using a predicate that matches on
the key portion of each MapEntry, without having to explicitly apply
an index to it.

I'm wondering whether somebody could confirm that this is the expected
behavior.

As a side note, my tests start off with inserting 200 elements into
the map, then ramp up to 200000 elements. If I go beyond that, I run
into an OutOfMemory error, which I assume is due to the fact that the
map has not been gc'ed, but I think that this kind of thing should be
discussed in a separate thread (and probably has been or is even in
the documentation somewhere).

Talip Ozturk

unread,
May 16, 2012, 8:55:00 AM5/16/12
to haze...@googlegroups.com
Only value attributes can be indexed at the moment. Queries without
indexes will scan the entire map and call your KeyPredicate.evaluate
for each map entry. So it is expensive.

http://twitter.com/oztalip
> --
> You received this message because you are subscribed to the Google Groups "Hazelcast" group.
> To post to this group, send email to haze...@googlegroups.com.
> To unsubscribe from this group, send email to hazelcast+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/hazelcast?hl=en.
>

Ben Hood

unread,
May 16, 2012, 9:11:27 AM5/16/12
to haze...@googlegroups.com
Hi Talip,

On Wed, May 16, 2012 at 1:55 PM, Talip Ozturk <ta...@hazelcast.com> wrote:
> Only value attributes can be indexed at the moment. Queries without
> indexes will scan the entire map and call your KeyPredicate.evaluate
> for each map entry. So it is expensive.

OK, this is good to know - I'll bear this in mind when querying for
key attributes. Just out of interest, the times I am seeing to query
the key attribute in my test (the one I linked in my previous post)
are:


Time to query 21 entries: 7
Time to query 201 entries: 20
Time to query 2001 entries: 121
Time to query 20001 entries: 424
Time to query 200001 entries: 1380

(All the times are in ms)

In this simple test, the results appear to indicate a sub-linear cost
- is there an explanation for this, or is it the case that my test is
bogus?

Cheers,

Ben
Reply all
Reply to author
Forward
0 new messages