提交 73cd2b87 authored 作者: Thomas Mueller's avatar Thomas Mueller

Small improvements.

上级 c940fbb4
...@@ -55,8 +55,9 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -55,8 +55,9 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
if (newIndexColumns != null) { if (newIndexColumns != null) {
this.indexColumns = newIndexColumns; this.indexColumns = newIndexColumns;
columns = new Column[newIndexColumns.length]; columns = new Column[newIndexColumns.length];
columnIds = new int[columns.length]; int len = columns.length;
for (int i = 0; i < columns.length; i++) { columnIds = new int[len];
for (int i = 0; i < len; i++) {
Column col = newIndexColumns[i].column; Column col = newIndexColumns[i].column;
columns[i] = col; columns[i] = col;
columnIds[i] = col.getColumnId(); columnIds[i] = col.getColumnId();
...@@ -202,7 +203,10 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -202,7 +203,10 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
long cost = rowCount; long cost = rowCount;
long rows = rowCount; long rows = rowCount;
int totalSelectivity = 0; int totalSelectivity = 0;
for (int i = 0; masks != null && i < columns.length; i++) { if (masks == null) {
return cost;
}
for (int i = 0, len = columns.length; i < len; i++) {
Column column = columns[i]; Column column = columns[i];
int index = column.getColumnId(); int index = column.getColumnId();
int mask = masks[index]; int mask = masks[index];
...@@ -235,7 +239,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -235,7 +239,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
} }
public int compareRows(SearchRow rowData, SearchRow compare) { public int compareRows(SearchRow rowData, SearchRow compare) {
for (int i = 0; i < indexColumns.length; i++) { for (int i = 0, len = indexColumns.length; i < len; i++) {
int index = columnIds[i]; int index = columnIds[i];
Value v = compare.getValue(index); Value v = compare.getValue(index);
if (v == null) { if (v == null) {
...@@ -287,11 +291,11 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -287,11 +291,11 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
} }
private int compareValues(Value a, Value b, int sortType) { private int compareValues(Value a, Value b, int sortType) {
boolean aNull = a == null, bNull = b == null; if (a == b) {
if (aNull || bNull) {
if (aNull == bNull) {
return 0; return 0;
} }
boolean aNull = a == null, bNull = b == null;
if (aNull || bNull) {
return SortOrder.compareNull(aNull, bNull, sortType); return SortOrder.compareNull(aNull, bNull, sortType);
} }
int comp = table.compareTypeSave(a, b); int comp = table.compareTypeSave(a, b);
...@@ -302,7 +306,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -302,7 +306,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
} }
public int getColumnIndex(Column col) { public int getColumnIndex(Column col) {
for (int i = 0; i < columns.length; i++) { for (int i = 0, len = columns.length; i < len; i++) {
if (columns[i] == col) { if (columns[i] == col) {
return i; return i;
} }
......
...@@ -49,7 +49,7 @@ public class IndexCursor implements Cursor { ...@@ -49,7 +49,7 @@ public class IndexCursor implements Cursor {
indexColumns = new IndexColumn[columns.length]; indexColumns = new IndexColumn[columns.length];
IndexColumn[] idxCols = index.getIndexColumns(); IndexColumn[] idxCols = index.getIndexColumns();
if (idxCols != null) { if (idxCols != null) {
for (int i = 0; i < columns.length; i++) { for (int i = 0, len = columns.length; i < len; i++) {
int idx = index.getColumnIndex(columns[i]); int idx = index.getColumnIndex(columns[i]);
if (idx >= 0) { if (idx >= 0) {
indexColumns[i] = idxCols[idx]; indexColumns[i] = idxCols[idx];
......
...@@ -124,8 +124,8 @@ public class PageBtreeIndex extends PageIndex { ...@@ -124,8 +124,8 @@ public class PageBtreeIndex extends PageIndex {
private SearchRow getSearchRow(Row row) { private SearchRow getSearchRow(Row row) {
SearchRow r = table.getTemplateSimpleRow(columns.length == 1); SearchRow r = table.getTemplateSimpleRow(columns.length == 1);
r.setKeyAndVersion(row); r.setKeyAndVersion(row);
for (int j = 0; j < columns.length; j++) { for (Column c : columns) {
int idx = columns[j].getColumnId(); int idx = c.getColumnId();
r.setValue(idx, row.getValue(idx)); r.setValue(idx, row.getValue(idx));
} }
return r; return r;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论