Reviews
Oracle CoherenceOracle Coherence: Anatomy of an Index
A Coherence index is an instance of a class that implements the com.tangosol.util.MapIndex interface:
- public interface MapIndex {
- ValueExtractor getValueExtractor()
- boolean isOrdered()
- Map getIndexContents()
- Object get(Object key)
- }
The getValueExtractor method returns the value extractor used to extract the attribute that should be indexed from an object, while the isOrdered method returns whether the index is sorted or not.
The get method allows us to obtain a value of the indexed attribute for the specified key directly from an index, which avoids object deserialization and repeat value extraction.
Finally, the getIndexContents method returns the actual index contents. This is a map that uses the value extracted from the indexed attribute as a key, while the value for each index entry is a set of cache keys corresponding to that attribute value.
Looking at an example should make the previous paragraph much easier to understand.
Let's assume that we have the following entries in the cache:
- Key Value
- 1 Person(firstName = 'Aleksandar', lastName = 'Seovic')
- 2 Person(firstName = 'Marija', lastName = 'Seovic')
- 3 Person(firstName = 'Ana Maria', lastName = 'Seovic')
- 4 Person(firstName = 'Novak', lastName = 'Seovic')
- 5 Person(firstName = 'Aleksandar', lastName = 'Jevic')
If we create an index on the lastName attribute, our index contents will look like this:
- Key Value
- Jevic {5}
- Seovic { 1, 2, 3, 4 }
On the other hand, an index on the firstName attribute will look like this:
- Key Value
- Aleksandar { 1, 5 }
- Ana Maria {3}
- Marija {2}
- Novak {4}
Index internals
Keep in mind that while I'm showing the actual values in the previous examples, the Coherence index actually stores both keys and values in their internal binary format. For the most part you shouldn't care about this fact, but it is good to know if you end up accessing index contents directly.
The previous example should also make it obvious why indexes have such a profound effect on query performance.
If we wanted to obtain a list of keys for all people in the cache that have last name 'Seovic', without an index Coherence would have to deserialize each cache entry, extract the lastName attribute and perform a comparison, and if the comparison matches then it would add the cache entry key to the resulting list of keys.
With an index, Coherence doesn't need to do any of this--it will simply look up an index entry with the key Seovic and return the set of keys from that index entry.
Oracle Coherence
- Oracle Coherence 3.5
- Oracle Coherence: Distributed Caching
- Oracle Coherence: In-place and Parallel Processing
- Oracle Coherence: Coherence within the Oracle Ecosystem
- Oracle Coherence: Querying The Data Grid
- Oracle Coherence: Built-in Filters
- Oracle Coherence: Value and Reflection Extractor
- Oracle Coherence: Other built-in value extractors
- Oracle Coherence: Implementing Custom Value Extractor
- Oracle Coherence: Simplifying Coherence Queries
- Oracle Coherence: Obtaining Query Results
- Oracle Coherence: Controlling Query Scope Using Data Affinity
- Oracle Coherence: Querying Near Cache
- Oracle Coherence: Paging Over Query Results
- Oracle Coherence: Anatomy of an Index
- Oracle Coherence: Creating Indexes
- Oracle Coherence: Query Limitations
- Oracle Coherence: Aggregators
- Oracle Coherence: Built-in Aggregators
- Oracle Coherence: Implementing LookupValuesAggregator







