提交 77bd2516 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add Index.isFindSlow() and use it in IndexCursor to prevent multiple table scans in FunctionIndex

上级 8fcd494b
...@@ -120,6 +120,10 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -120,6 +120,10 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
return false; return false;
} }
@Override
public boolean isFindSlow() {
return false;
}
@Override @Override
public Cursor find(TableFilter filter, SearchRow first, SearchRow last) { public Cursor find(TableFilter filter, SearchRow first, SearchRow last) {
......
...@@ -44,6 +44,11 @@ public class FunctionIndex extends BaseIndex { ...@@ -44,6 +44,11 @@ public class FunctionIndex extends BaseIndex {
throw DbException.getUnsupportedException("ALIAS"); throw DbException.getUnsupportedException("ALIAS");
} }
@Override
public boolean isFindSlow() {
return true;
}
@Override @Override
public Cursor find(Session session, SearchRow first, SearchRow last) { public Cursor find(Session session, SearchRow first, SearchRow last) {
if (functionTable.isBufferResultSetToLocalTemp()) { if (functionTable.isBufferResultSetToLocalTemp()) {
......
...@@ -51,6 +51,15 @@ public interface Index extends SchemaObject { ...@@ -51,6 +51,15 @@ public interface Index extends SchemaObject {
*/ */
void remove(Session session, Row row); void remove(Session session, Row row);
/**
* Returns {@code true} if {@code find()} implementation performs scan over all
* index, {@code false} if {@code find()} performs the fast lookup.
*
* @return {@code true} if {@code find()} implementation performs scan over all
* index, {@code false} if {@code find()} performs the fast lookup
*/
boolean isFindSlow();
/** /**
* Find a row or a list of rows and create a cursor to iterate over the * Find a row or a list of rows and create a cursor to iterate over the
* result. * result.
......
...@@ -89,6 +89,9 @@ public class IndexCursor implements Cursor { ...@@ -89,6 +89,9 @@ public class IndexCursor implements Cursor {
alwaysFalse = true; alwaysFalse = true;
break; break;
} }
if (index.isFindSlow()) {
continue;
}
Column column = condition.getColumn(); Column column = condition.getColumn();
if (condition.getCompareType() == Comparison.IN_LIST) { if (condition.getCompareType() == Comparison.IN_LIST) {
if (start == null && end == null) { if (start == null && end == null) {
......
...@@ -72,6 +72,11 @@ public class MultiVersionIndex implements Index { ...@@ -72,6 +72,11 @@ public class MultiVersionIndex implements Index {
} }
} }
@Override
public boolean isFindSlow() {
return base.isFindSlow();
}
@Override @Override
public Cursor find(TableFilter filter, SearchRow first, SearchRow last) { public Cursor find(TableFilter filter, SearchRow first, SearchRow last) {
synchronized (sync) { synchronized (sync) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论