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