This topic describes how to work with indexes in VMware Tanzu GemFire, and provides links to documentation that explains working with indexes in greater detail.
The Tanzu GemFire query engine supports indexing. An index can provide significant performance gains for query execution.
A query run without the aid of an index iterates through every object in the collection. If an index is available that matches part or all of the query specification, the query iterates only over the indexed set, and query processing time can be reduced.
Tips and Guidelines for Using Indexes
Optimizing your queries with indexes requires a cycle of careful planning, testing, and tuning. Poorly-defined indexes can degrade the performance of your queries instead of improving it. This section gives guidelines for index usage in the query service.
Creating, Listing, and Removing Indexes
The Tanzu GemFire QueryService
API provides methods to create, list and remove the index. You can also use gfsh
command-line interface to create, list and remove indexes, and use cache.xml to create an index.
Creating a key index is a good way to improve query performance when data is partitioned using a key or a field value. You can create key indexes by using the createKeyIndex
method of the QueryService or by defining the index in cache.xml
. Creating a key index makes the query service aware of the relationship between the values in the region and the keys in the region.
Hash indexes are deprecated. Tanzu GemFire supports the creation of hash indexes for the purposes of performing equality-based queries.
Creating Indexes on Map Fields (“Map Indexes”)
To assist with the quick lookup of multiple values in a Map (or HashMap) type field, you can create an index (sometimes referred to as a “map index”) on specific (or all) keys in that field.
Creating Multiple Indexes Concurrently
In order to speed and promote efficiency when creating indexes, you can define multiple indexes and then create them all at once.
Maintaining Indexes (Synchronously or Asynchronously) and Index Storage
Indexes are automatically kept current with the region data they reference. The region attribute IndexMaintenanceSynchronous
specifies whether the region indexes are updated synchronously when a region is modified or asynchronously in a background thread.
You can use the hint keyword to allow Tanzu GemFire’s query engine to prefer certain indexes.
Using Indexes on Single Region Queries
Queries with one comparison operation may be improved with either a key or range index, depending on whether the attribute being compared is also the primary key.
Using Indexes with Equi-Join Queries
Equi-join queries are queries in which two regions are joined through an equality condition in the WHERE clause.
Using Indexes with Overflow Regions
You can use indexes when querying on overflow regions; however, there are caveats.
Using Indexes on Equi-Join Queries using Multiple Regions
To query across multiple regions, identify all equi-join conditions. Then, create as few indexes for the equi-join conditions as you can while still joining all regions.
This topic provides code samples for creating query indexes.