Summary: Setting implicit indexing, extended indexing, and related options.

Overview

To improve performance, the space can maintain an index for entry field values. This speeds read and take operations, but consumes resources, so only fields used for matching should be indexed. GigaSpaces support hash based index used for equality matching (used by default) and B-tree index used for bigger/less than matching (need the Extended Indexing to be turned on). You can automatically index the first n fields of each class (implicit indexing) or index certain fields of a specific class (explicit indexing).

There are three types of indexing:

  • Explicit Indexing – allows you to specify programmatically which fields of a Space Class are indexed.
  • Implicit Indexing – when enabled, the implicit indexing automatically indexes all the class attributes that are not indexed programmatically. Implicit Indexing is managed through the number-implicit-indexes property.
  • Extended indexing – when enabled, a btree index is maintained for all space indexed class attributes.

Adding or dropping an index in runtime is not supported.

Explicit Indexing

This section is relevant for the JavaSpaces API only. JDBC API allows you to index attribute using the standard JDBC API.

Using XML

When using POJO as your Space Domain Class you can use the gs.xml to specify the indxed fields. See below example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gigaspaces-mapping PUBLIC "-//GIGASPACES//DTD GS//EN" "http://www.gigaspaces.com/dtd/6_0/gigaspaces-metadata.dtd">
<gigaspaces-mapping>
      <class name="com.j_spaces.examples.hellospacepojo.Employee" persist="false" replicate="false" fifo="false" >
            <version name="versionID" />
            <id name="employeeID" auto-generate="false" />
            <routing name="employeeID" />
            <property name="lastName" index="BASIC" />
            <property name="firstName" index="BASIC" />
      </class>
</gigaspaces-mapping>

Using Code

You can specify programmatically which fields of an Entry or POJO class are indexed.

The @SpaceProperty(index=IndexType.BASIC) should be used to index specefic field.
When placing Index annotation on a super class - all sub classes will also be indexed.
See below an example how to use the @SpaceProperty(index=IndexType.BASIC) annotation:

@SpaceClass(replicate=true,persist=false,fifo=false)
public class Person
{
	private String	lastName;private String	firstName;
	public Person(){}
	public Person(String lastName, String firstName){this.lastName = lastName;this.firstName = firstName;}

	@SpaceProperty(index=IndexType.BASIC)
	public String getFirstName(){return firstName;}

	public void setFirstName(String firstName){this.firstName = firstName;}

	@SpaceProperty(index=IndexType.BASIC)

	public String getLastName(){return lastName;}

	public void setLastName(String name) {this.lastName = name;}
}

Extended Indexing

Extended Indexing should be used when you have bigger/less than SQL queries used.
To turn on the btree index, use the following property (note the asterisk):

space-config.engine.extended-match.enabled-classes.enabled-classes=*
By default the btree index is not maintained for indexed class attributes. Leaving the btree index turned on impacts the write performance since there would be 2 index list maintained – the hash index and the btree index.

The space-config.engine.extended-match.enabled-classes.enabled-classes can have a list of class names separated with commas that you want to index using the btree index.
For example:

space-config.engine.extended-match.enabled-classes.enabled-classes=pack1.classA,pack2.classB

More Indexing Options

Property Description Default value
space-config.number-implicit-indexes if number-implicit-indexes=0, the default number of implicit indexes: for Memory Space = 2, Persistent Space = 1. 0 for default schema - 1 for cache schema.
space-config.engine.extended-match.enabled-classes Classes with extended indexing. * means all space classes. You can place a comma-separated list of class names.  
space-config.engine.extended-match.regular-expressions-cache-size When using regular expression queries – the space maintains a cache for pre-compiled regular expressions. 300

How Indexes are used?

When a read, take, readMultiple, or takeMultiple call is performed, a template is used to locate matching space objects. The template might have multiple field values – some might include values and some might not (i.e. null field values acting as wildcard). The fields that do not include values are ignored during the matching process. In addition, some class fields might be indexed and some might not be indexed.

When multiple class fields are indexed, the space looks for the field value index that includes the smallest amount of matching space objects with the corresponding template field value as the index key.

The smallest set of space objects is the list of objects to perform the matching against (matching candidates). Once the candidates space object list has been constructed, it is scanned to locate space objects that fully match the given template – i.e. all non-null template fields match the corresponding space object fields.

Class fields that are not indexed are not used to construct the candidates list.
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence