提交 1d3079b7 authored 作者: Sergi Vladykin's avatar Sergi Vladykin

Minor improvement: Index.isFirstColumn

上级 87562a00
......@@ -377,6 +377,11 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
return -1;
}
@Override
public boolean isFirstColumn(Column column) {
return column.equals(columns[0]);
}
/**
* Get the list of columns as a string.
*
......
......@@ -190,6 +190,14 @@ public interface Index extends SchemaObject {
*/
int getColumnIndex(Column col);
/**
* Check if the given column is the first for this index
*
* @param column the column
* @return true if the given columns is the first
*/
boolean isFirstColumn(Column column);
/**
* Get the indexed columns as index columns (with ordering information).
*
......
......@@ -82,6 +82,14 @@ public class MetaIndex extends BaseIndex {
return super.getColumnIndex(col);
}
@Override
public boolean isFirstColumn(Column column) {
if (scan) {
return false;
}
return super.isFirstColumn(column);
}
@Override
public void checkRename() {
throw DbException.getUnsupportedException("META");
......
......@@ -230,6 +230,11 @@ public class MultiVersionIndex implements Index {
return base.getColumnIndex(col);
}
@Override
public boolean isFirstColumn(Column column) {
return base.isFirstColumn(column);
}
@Override
public Column[] getColumns() {
return base.getColumns();
......
......@@ -464,6 +464,11 @@ public class PageDataIndex extends PageIndex {
return -1;
}
@Override
public boolean isFirstColumn(Column column) {
return false;
}
@Override
public void close(Session session) {
if (trace.isDebugEnabled()) {
......
......@@ -96,6 +96,11 @@ public class PageDelegateIndex extends PageIndex {
return -1;
}
@Override
public boolean isFirstColumn(Column column) {
return getColumnIndex(column) == 0;
}
@Override
public double getCost(Session session, int[] masks,
TableFilter[] filters, int filter, SortOrder sortOrder,
......
......@@ -222,6 +222,11 @@ public class ScanIndex extends BaseIndex {
return -1;
}
@Override
public boolean isFirstColumn(Column column) {
return false;
}
@Override
public void checkRename() {
throw DbException.getUnsupportedException("SCAN");
......
......@@ -88,6 +88,11 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
return -1;
}
@Override
public boolean isFirstColumn(Column column) {
return getColumnIndex(column) == 0;
}
@Override
public double getCost(Session session, int[] masks,
TableFilter[] filters, int filter, SortOrder sortOrder,
......
......@@ -242,6 +242,11 @@ public class MVPrimaryIndex extends BaseIndex {
return -1;
}
@Override
public boolean isFirstColumn(Column column) {
return false;
}
@Override
public void remove(Session session) {
TransactionMap<Value, Value> map = getMap(session);
......
......@@ -1069,10 +1069,9 @@ public abstract class Table extends SchemaObjectBase {
if (needFindNext && !index.canFindNext()) {
continue;
}
int idx = index.getColumnIndex(column);
// choose the minimal covering index with the needed first column
// to work consistently with execution plan from Optimizer
if (idx == 0 && (result == null ||
if (index.isFirstColumn(column) && (result == null ||
result.getColumns().length > index.getColumns().length)) {
result = index;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论