Hash indexes are deprecated. Tanzu GemFire supports the creation of hash indexes for the purpose of performing equality-based queries.
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 the hash index and the cost of recalculating the key on request. A hash index can improve the memory usage of the index. So, the trade-off of the hash index space savings must be weighed against the performance penalty it imposes. If memory usage is not a concern, a range index is recommended.
Consider the memory usage when an index contains string fields. Copies of the strings are included in the index. With hash indexes, indexed expressions are canonicalized and stored in the index as pointers to the objects residing in the region, thereby using less memory. Tests achieved as high as a 30% reduction in memory footprint, but the savings depend on the keys and data being used.
The following limitations must be considered when creating hash indexes:
Hash indexes are deprecated.
Using the Java API:
QueryService qs = cache.getQueryService();
qs.createHashIndex("myHashIndex", "mktValue", "/exampleRegion");
Using gfsh:
gfsh> create index --name=myHashIndex --expression=mktValue --region=/exampleRegion
--type=hash
Using cache.xml:
<region name=exampleRegion>
<region-attributes . . . >
</region-attributes>
<index name="myHashIndex" from-clause="/exampleRegion p" expression="p.mktValue" type="hash"/>
...
</region>