Creating Hash Indexes
Geode supports the creation of hash indexes for the purposes of performing equality-based queries.
By creating a hash index, you can improve the memory usage of your index. If you are doing equality-based queries, your indexing footprint is significantly reduced. As an example, previously when you created an index that contained string fields, copies of the strings were included in the index. By using hash indexes, indexed expressions are canonicalized and stored in the index as pointers to the objects lying in the region. Improvements in the 30% range are expected, depending on the keys and data being used.
Note: Your performance results may vary depending on the keys and data being indexed.
The performance of put operations and recovery time when using a hash index will be worse than a range index. Queries are expected to be slower due to the implementation of hash index and the cost of recalculating the key on request, which is the trade-off for the space savings that using a hash index provides. If memory usage is not a concern, a range index is recommended.
The following limitations must be considered when creating hash indexes:
- You can only use hash indexes with equals and not equals queries.
- Hash index maintenance will be slower than the other indexes due to synchronized add methods.
- Hash indexes cannot be maintained asynchronously. If you attempt to create a hash index on a region with asynchronous set as the maintenance mode, an exception will be thrown.
- You cannot use hash indexes for queries with multiple iterators or nested collections.
- Using a hash index will degrade put operation performance and recovery time substantially. If memory is not a concern, use a range index instead of a hash index.
Using the Java API:
QueryService qs = cache.getQueryService(); qs.createHashIndex("myHashIndex", "mktValue", "/exampleRegion");
gfsh> create index --name=myHashIndex --expression=mktValue --region=/exampleRegion
<region name=exampleRegion> <region-attributes . . . > </region-attributes> <index name="myHashIndex" from-clause="/exampleRegion p" expression="p.mktValue" type="hash"/> ... </region>