use of herddb.index.IndexOperation in project herddb by diennea.
the class CalcitePlanner method findSecondaryIndexOperation.
private static IndexOperation findSecondaryIndexOperation(AbstractIndexManager index, CompiledSQLExpression where, Table table) throws StatementExecutionException {
IndexOperation secondaryIndexOperation = null;
String[] columnsToMatch = index.getColumnNames();
SQLRecordKeyFunction indexSeekFunction = findIndexAccess(where, columnsToMatch, index.getIndex(), "=", table);
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);
if (rangeMin != null && !rangeMin.isFullPrimaryKey()) {
rangeMin = null;
}
if (rangeMin == null) {
rangeMin = findIndexAccess(where, columnsToMatch, index.getIndex(), ">", table);
if (rangeMin != null && !rangeMin.isFullPrimaryKey()) {
rangeMin = null;
}
}
SQLRecordKeyFunction rangeMax = findIndexAccess(where, columnsToMatch, index.getIndex(), "<=", table);
if (rangeMax != null && !rangeMax.isFullPrimaryKey()) {
rangeMax = null;
}
if (rangeMax == null) {
rangeMax = findIndexAccess(where, columnsToMatch, index.getIndex(), "<", table);
if (rangeMax != null && !rangeMax.isFullPrimaryKey()) {
rangeMax = null;
}
}
if (rangeMin != null || rangeMax != null) {
secondaryIndexOperation = new SecondaryIndexRangeScan(index.getIndexName(), columnsToMatch, rangeMin, rangeMax);
}
}
return secondaryIndexOperation;
}
use of herddb.index.IndexOperation 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;
}
use of herddb.index.IndexOperation in project herddb by diennea.
the class IndexUtils method scanForIndexAccess.
private static IndexOperation scanForIndexAccess(CompiledSQLExpression expressionWhere, Table table, TableSpaceManager tableSpaceManager) {
SQLRecordKeyFunction keyFunction = findIndexAccess(expressionWhere, table.primaryKey, table, "=", table);
IndexOperation result = null;
if (keyFunction != null) {
if (keyFunction.isFullPrimaryKey()) {
result = new PrimaryIndexSeek(keyFunction);
} else {
result = new PrimaryIndexPrefixScan(keyFunction);
}
} else {
SQLRecordKeyFunction rangeMin = findIndexAccess(expressionWhere, table.primaryKey, table, ">=", table);
if (rangeMin != null && !rangeMin.isFullPrimaryKey()) {
rangeMin = null;
}
if (rangeMin == null) {
rangeMin = findIndexAccess(expressionWhere, table.primaryKey, table, ">", table);
if (rangeMin != null && !rangeMin.isFullPrimaryKey()) {
rangeMin = null;
}
}
SQLRecordKeyFunction rangeMax = findIndexAccess(expressionWhere, table.primaryKey, table, "<=", table);
if (rangeMax != null && !rangeMax.isFullPrimaryKey()) {
rangeMax = null;
}
if (rangeMax == null) {
rangeMax = findIndexAccess(expressionWhere, table.primaryKey, table, "<", table);
if (rangeMax != null && !rangeMax.isFullPrimaryKey()) {
rangeMax = null;
}
}
if (rangeMin != null || rangeMax != null) {
result = new PrimaryIndexRangeScan(table.primaryKey, rangeMin, rangeMax);
}
}
if (result == null && tableSpaceManager != null) {
Map<String, AbstractIndexManager> indexes = tableSpaceManager.getIndexesOnTable(table.name);
if (indexes != null) {
// TODO: use some kind of statistics, maybe using an index is more expensive than a full table scan
for (AbstractIndexManager index : indexes.values()) {
if (!index.isAvailable()) {
continue;
}
IndexOperation secondaryIndexOperation = findSecondaryIndexOperation(index, expressionWhere, table);
if (secondaryIndexOperation != null) {
result = secondaryIndexOperation;
break;
}
}
}
}
return result;
}
use of herddb.index.IndexOperation in project herddb by diennea.
the class IndexUtils method discoverIndexOperations.
static void discoverIndexOperations(final String tableSpace, CompiledSQLExpression where, Table table, SQLRecordPredicate predicate, Object debug, TableSpaceManager tableSpaceManager) throws StatementExecutionException {
IndexOperation op = scanForIndexAccess(where, table, tableSpaceManager);
predicate.setIndexOperation(op);
CompiledSQLExpression filterPk = findFiltersOnPrimaryKey(table, where);
if (filterPk != null) {
filterPk = remapPositionalAccessToToPrimaryKeyAccessor(filterPk, table, debug);
}
predicate.setPrimaryKeyFilter(filterPk);
}
use of herddb.index.IndexOperation in project herddb by diennea.
the class IndexUtils method findSecondaryIndexOperation.
private static IndexOperation findSecondaryIndexOperation(AbstractIndexManager index, CompiledSQLExpression where, Table table) throws StatementExecutionException {
IndexOperation secondaryIndexOperation = null;
String[] columnsToMatch = index.getColumnNames();
SQLRecordKeyFunction indexSeekFunction = findIndexAccess(where, columnsToMatch, index.getIndex(), "=", table);
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);
if (rangeMin != null && !rangeMin.isFullPrimaryKey()) {
rangeMin = null;
}
if (rangeMin == null) {
rangeMin = findIndexAccess(where, columnsToMatch, index.getIndex(), ">", table);
if (rangeMin != null && !rangeMin.isFullPrimaryKey()) {
rangeMin = null;
}
}
SQLRecordKeyFunction rangeMax = findIndexAccess(where, columnsToMatch, index.getIndex(), "<=", table);
if (rangeMax != null && !rangeMax.isFullPrimaryKey()) {
rangeMax = null;
}
if (rangeMax == null) {
rangeMax = findIndexAccess(where, columnsToMatch, index.getIndex(), "<", table);
if (rangeMax != null && !rangeMax.isFullPrimaryKey()) {
rangeMax = null;
}
}
if (rangeMin != null || rangeMax != null) {
secondaryIndexOperation = new SecondaryIndexRangeScan(index.getIndexName(), columnsToMatch, rangeMin, rangeMax);
}
}
return secondaryIndexOperation;
}
Aggregations