Unverified 提交 4ce2a984 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1341 from katzyn/misc

Optimize MVSecondaryIndex.convertToKey()
......@@ -79,7 +79,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
public void addRowsToBuffer(List<Row> rows, String bufferName) {
MVMap<ValueArray, Value> map = openMap(bufferName);
for (Row row : rows) {
ValueArray key = convertToKey(row);
ValueArray key = convertToKey(row, null);
map.append(key, ValueNull.INSTANCE);
}
}
......@@ -185,7 +185,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
@Override
public void add(Session session, Row row) {
TransactionMap<Value, Value> map = getMap(session);
ValueArray array = convertToKey(row);
ValueArray array = convertToKey(row, null);
boolean checkRequired = indexType.isUnique() && !mayHaveNullDuplicates(row);
if (checkRequired) {
checkUnique(map, array, Long.MIN_VALUE);
......@@ -203,7 +203,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
}
private void checkUnique(TransactionMap<Value, Value> map, ValueArray row, long newKey) {
Iterator<Value> it = map.keyIterator(convertToKey(row, Boolean.FALSE), convertToKey(row, Boolean.TRUE), true);
Iterator<Value> it = map.keyIterator(convertToKey(row, ValueLong.MIN), convertToKey(row, ValueLong.MAX), true);
while (it.hasNext()) {
ValueArray rowData = (ValueArray)it.next();
Value[] array = rowData.getList();
......@@ -221,7 +221,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
@Override
public void remove(Session session, Row row) {
ValueArray array = convertToKey(row);
ValueArray array = convertToKey(row, null);
TransactionMap<Value, Value> map = getMap(session);
try {
Value old = map.remove(array);
......@@ -261,26 +261,19 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
}
private Cursor find(Session session, SearchRow first, boolean bigger, SearchRow last) {
ValueArray min = convertToKey(convertToKey(first), bigger);
ValueArray max = convertToKey(convertToKey(last), Boolean.TRUE);
ValueArray min = convertToKey(first, bigger ? ValueLong.MAX : ValueLong.MIN);
ValueArray max = convertToKey(last, ValueLong.MAX);
TransactionMap<Value,Value> map = getMap(session);
return new MVStoreCursor(session, map.keyIterator(min, max, false));
}
private static ValueArray convertToKey(ValueArray r, Boolean minmax) {
if (r == null) {
return null;
}
private static ValueArray convertToKey(ValueArray r, ValueLong key) {
Value[] values = r.getList().clone();
ValueArray row = ValueArray.get(values);
if (minmax != null) {
values[values.length - 1] = ValueLong.get(minmax ? Long.MAX_VALUE : Long.MIN_VALUE);
}
return row;
values[values.length - 1] = key;
return ValueArray.get(values);
}
private ValueArray convertToKey(SearchRow r) {
private ValueArray convertToKey(SearchRow r, ValueLong key) {
if (r == null) {
return null;
}
......@@ -293,7 +286,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
array[i] = v.convertTo(c.getType(), -1, database.getMode(), null, c.getEnumerators());
}
}
array[keyColumns - 1] = ValueLong.get(r.getKey());
array[keyColumns - 1] = key != null ? key : ValueLong.get(r.getKey());
return ValueArray.get(array);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论