THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
ID | IEP-71 | ||||||
Author | |||||||
Sponsor | |||||||
Created | 06.04.2021 | ||||||
Status |
|
...
Rules to write criteria:
Rules to choose index:
Code Block | ||
---|---|---|
| ||
// Internal | ||
Code Block | ||
| ||
// Internal package.
public class IndexQueryProcessor extends GridProcessorAdapter {
// Provides access to indexes.
private final IndexProcessor processor;
// Entrypoint for local query.
public Iterator<Cache.Entry<?,?>> queryLocal(IndexQuery idxQuery, @Nullable IndexingQueryFilter filters) throws IgniteException {
// 1. If user specified index name, then check a query:
// - sort query fields in index key order;
// - check that it's a valid index query: fields covers index keys (from left to right)
// - fail otherwise.
// 2. If user doesn't specified index name:
// - get all indexes for specified cache and Value.class;
// - find index by filtering by a query fields (index keys must be in the same order as specified query fields, try sort fields to match any index).
// - validate index query (see validation steps from 1.)
Index idx = index(idxQuery.desc());
// 1. Parse index conditions.
// 2. Validate index condition, index type.
// 3. Maps index conditions to an index query methods.
// 4. Perform index operations, get Cursor.
GridCursor<IndexRow> cursor = query(idx, idxQry.conditions());
// 1. Map IndexRow to Cache entry.
// 2. Apply specified cache filters (primary partitions, MVCC versions, etc.)
// 3. Wrap cursor to iterator and return.
return map_and_filter(cursor, filters);
}
private GridCursor<IndexRow> query(Index idx, List<IndexCondition> conditions) {
// eq(key) -> idx.findOne(key)
// notEq(key) -> idx.find(null, null, current -> current != key)
// gt(key) -> idx.find(key, null, current -> current != key)
// gte(key) -> idx.find(key, null)
// lt(key) -> idx.find(null, key, current -> current != key)
// lte(key) -> idx.find(null, key)
// between(left, right) -> idx.find(left, right), inclusive only
// in(keys...) -> idx.findOne(keys[0]) && idx.findOne(keys[1]) ...
// notIn(keys...) -> idx.find(null, null, current -> !keys.contains(current))
// min() -> idx.findFirst()
// max() -> idx.findLast()
// predicate(p) -> idx.find(null, null, p)
}
} |
...
IndexName is optional. If it's not specified than take PK index of specified table.
Code Block | ||
---|---|---|
| ||
// The "predicate" operation can't find best index for a user query. So user must provide an index name for this operation. QueryCursor<Cache.Entry<Long, Good>> cursor = ignite.cache("GOOD").query( new IndexQuery<>("GOOD_TBL", "GOOD_TS_DESC_PRICE_ASC_IDX") .predicatesetFilter((good) -> good.ts > lastMidnightTs || price > 100) ); |
...