提交 b3a1e2d3 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix regression detected by TestTableEngines

上级 d9e6e1e4
......@@ -169,6 +169,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
long rowsCost = rowCount;
if (masks != null) {
int i = 0, len = columns.length;
boolean tryAdditional = false;
while (i < len) {
Column column = columns[i++];
int index = column.getColumnId();
......@@ -187,12 +188,15 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
rowsCost = 2 + Math.max(rowCount / distinctRows, 1);
} else if ((mask & IndexCondition.RANGE) == IndexCondition.RANGE) {
rowsCost = 2 + rowsCost / 4;
tryAdditional = true;
break;
} else if ((mask & IndexCondition.START) == IndexCondition.START) {
rowsCost = 2 + rowsCost / 3;
tryAdditional = true;
break;
} else if ((mask & IndexCondition.END) == IndexCondition.END) {
rowsCost = rowsCost / 3;
tryAdditional = true;
break;
} else {
if (mask == 0) {
......@@ -202,6 +206,12 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
break;
}
}
// Some additional columns can still be used
if (tryAdditional) {
while (i < len && masks[columns[i].getColumnId()] != 0) {
i++;
}
}
// Increase cost of indexes with additional unused columns
rowsCost += len - i;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论