Search in sources :

Example 6 with SecondaryIndexPrefixScan

use of herddb.index.SecondaryIndexPrefixScan in project herddb by diennea.

the class SQLPlanner method findSecondaryIndexOperation.

private static IndexOperation findSecondaryIndexOperation(AbstractIndexManager index, Expression where, Table table) throws StatementExecutionException {
    IndexOperation secondaryIndexOperation = null;
    String[] columnsToMatch = index.getColumnNames();
    SQLRecordKeyFunction indexSeekFunction = findIndexAccess(where, columnsToMatch, index.getIndex(), table.name, EqualsTo.class);
    if (indexSeekFunction != null) {
        if (indexSeekFunction.isFullPrimaryKey()) {
            secondaryIndexOperation = new SecondaryIndexSeek(index.getIndexName(), columnsToMatch, indexSeekFunction);
        } else {
            secondaryIndexOperation = new SecondaryIndexPrefixScan(index.getIndexName(), columnsToMatch, indexSeekFunction);
        }
    } else {
        SQLRecordKeyFunction rangeMin = findIndexAccess(where, columnsToMatch, index.getIndex(), table.name, GreaterThanEquals.class);
        if (rangeMin != null && !rangeMin.isFullPrimaryKey()) {
            rangeMin = null;
        }
        if (rangeMin == null) {
            rangeMin = findIndexAccess(where, columnsToMatch, index.getIndex(), table.name, GreaterThan.class);
            if (rangeMin != null && !rangeMin.isFullPrimaryKey()) {
                rangeMin = null;
            }
        }
        SQLRecordKeyFunction rangeMax = findIndexAccess(where, columnsToMatch, index.getIndex(), table.name, MinorThanEquals.class);
        if (rangeMax != null && !rangeMax.isFullPrimaryKey()) {
            rangeMax = null;
        }
        if (rangeMax == null) {
            rangeMax = findIndexAccess(where, columnsToMatch, index.getIndex(), table.name, MinorThan.class);
            if (rangeMax != null && !rangeMax.isFullPrimaryKey()) {
                rangeMax = null;
            }
        }
        if (rangeMin != null || rangeMax != null) {
            secondaryIndexOperation = new SecondaryIndexRangeScan(index.getIndexName(), columnsToMatch, rangeMin, rangeMax);
        }
    }
    return secondaryIndexOperation;
}
Also used : MinorThan(net.sf.jsqlparser.expression.operators.relational.MinorThan) IndexOperation(herddb.index.IndexOperation) SecondaryIndexSeek(herddb.index.SecondaryIndexSeek) SecondaryIndexRangeScan(herddb.index.SecondaryIndexRangeScan) GreaterThan(net.sf.jsqlparser.expression.operators.relational.GreaterThan) SecondaryIndexPrefixScan(herddb.index.SecondaryIndexPrefixScan)

Aggregations

SecondaryIndexPrefixScan (herddb.index.SecondaryIndexPrefixScan)6 SecondaryIndexSeek (herddb.index.SecondaryIndexSeek)5 SecondaryIndexRangeScan (herddb.index.SecondaryIndexRangeScan)3 MemoryCommitLogManager (herddb.mem.MemoryCommitLogManager)3 MemoryDataStorageManager (herddb.mem.MemoryDataStorageManager)3 MemoryMetadataStorageManager (herddb.mem.MemoryMetadataStorageManager)3 DataScanner (herddb.model.DataScanner)3 Index (herddb.model.Index)3 Table (herddb.model.Table)3 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)3 CreateTableSpaceStatement (herddb.model.commands.CreateTableSpaceStatement)3 CreateTableStatement (herddb.model.commands.CreateTableStatement)3 ScanStatement (herddb.model.commands.ScanStatement)3 TranslatedQuery (herddb.sql.TranslatedQuery)3 IndexOperation (herddb.index.IndexOperation)2 Test (org.junit.Test)2 SQLRecordKeyFunction (herddb.sql.SQLRecordKeyFunction)1 Bytes (herddb.utils.Bytes)1 List (java.util.List)1 GreaterThan (net.sf.jsqlparser.expression.operators.relational.GreaterThan)1