Note: Documentation for Pivotal GemFire 7.0.x is now available at http://docs.gopivotal.com/gemfire/index.html. Please reference the docs.gopivotal.com site for the latest and most up-to-date documentation on GemFire 7.0.x. The vFabric GemFire 7.0 documentation site will no longer be updated.

Creating Hash Indexes

Why Create a HashIndex

By creating a hash index, you can vastly 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, we ensure that indexed expressions are canonicalized and stored in the index as pointers to the PDX objects lying in the region. In internal test cases we have seen improvements in the 30% range depending on the keys and data being used.

Note: Your performance results may vary depending on the keys and data being indexed.

Performance Considerations

The performance of put operations when using a hash index should be comparable to other indexes or slightly slower. Queries themselves are expected to be slightly 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.

Limitations

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.

Examples of Creating a Hash Index

Using the Java API:
QueryService qs = cache.getQueryService();
 qs.createHashIndex("myHashIndex", "mktValue", "/exampleRegion");
Using gfsh:
gfsh> create index --name=myHashIndex --expression=mktValue --region=/exampleRegion
Using cache.xml:
<region name=exampleRegion>
 <region-attributes . . . >
 </region-attributes>
 <index name="myHashIndex" from-clause="/exampleRegion p" expression="p.mktValue" type="hash"/>
 ...
</region>