Fix index usage (skip) in SQL statements when it cannot be used for equality
@@ -11,6 +11,7 @@ import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexDefinition;
+import com.orientechnologies.orient.core.index.OIndexInternal;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.sql.OCommandExecutorSQLAbstract;
import com.orientechnologies.orient.core.sql.parser.*;
@@ -1186,8 +1187,8 @@ public class OSelectExecutionPlanner {
* @return
*/
private IndexSearchDescriptor findBestIndexFor(OCommandContext ctx, Set<OIndex<?>> indexes, OAndBlock block) {
- return indexes.stream().map(index -> buildIndexSearchDescriptor(ctx, index, block)).filter(Objects::nonNull)
- .filter(x -> x.keyCondition != null).filter(x -> x.keyCondition.getSubBlocks().size() > 0)
+ return indexes.stream().filter(x -> ((OIndexInternal)x).canBeUsedInEqualityOperators()).map(index -> buildIndexSearchDescriptor(ctx, index, block))
+ .filter(Objects::nonNull).filter(x -> x.keyCondition != null).filter(x -> x.keyCondition.getSubBlocks().size() > 0)
.min(Comparator.comparing(x -> x.cost(ctx))).orElse(null);
}
