Announcement Announcement Module
Collapse
No announcement yet.
Index type Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Index type

    I am trying to create a functional index on EmailAddress class listed below. But finding that the index is not being used for the below query. What are the data types on which index can be created?

    Query:
    Code:
    customerTemplate.find("SELECT * from /customerRegion cust WHERE emailAddress=$1", emailAddress);
    Index:
    Code:
     <gfe:index id="customerRegionIndexOnEmail" expression="cust.emailAddress"
              from="/customerRegion cust" override="true" type="FUNCTIONAL" />
    Code:
     public final class EmailAddress  implements Serializable {
          private final String value;
       
       /* getter, setter and toString()*/
    }
    Code:
     public class Customer{
      private EmailAddress emailAddress;
      private String firstname, lastname;
       
    /* getter, setter and toString()*/
    }

  • #2
    @aryan_dear,

    A few things to note...

    1. RANGE Index is the new term for FUNCTIONAL Index (which is only used internally in GemFire now) when defining the Index and so this should probably be changed in SDG. However, what is important to know is that this translates to the QueryService.createIndex(indexName, indexedExpression, regionPath, [imports]) method API call in GemFire's Cache QueryService.

    2. KEY, or PRIMARY_KEY Indexes defined in SDG XML namespace config translate to the QueryService.createKeyIndex(..) methods.

    3. HASH Indexes defined in SDG XML namespace config translate to the QueryService.createHashIndex(..) methods.

    In your example, you might try using a HASH Index since you are performing an "equality" comparison in your Query, and make sure to override the equals/hashCode methods in your EmailAddress domain object.

    If you need to use a FUNCTIONAL, or rather RANGE Index, then you might try implementing Comparable<EmailAddress> on the EmailAddress since the RANGE Index is a relation comparison of the values, and internally, I was told calls the "compareTo" method on the cache value if it exists, otherwise resorts to a internally defined Comparator that performs some sort of hash (do not know all the details completely.)

    Also, not sure if it completely matters (I was told it should not with single Region access, but would/could matter for multi-Region access), but you defined the FUNCTIONAL Index 'expression' as "cust.emailAddress" and in the Query used "emailAddress=$1" without the Region shortcut qualifier. Not exactly certain "how" GemFire resolves the Index based on Query parsing, but like I said, it should not matter for single Region access.

    Hope this helps.

    Comment

    Working...
    X