提交 21ffff1a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use ValueRow instead of ValueArray in local and external results

上级 a440ce8c
...@@ -13,7 +13,7 @@ import org.h2.mvstore.MVMap; ...@@ -13,7 +13,7 @@ import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVMap.Builder; import org.h2.mvstore.MVMap.Builder;
import org.h2.result.ResultExternal; import org.h2.result.ResultExternal;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueRow;
/** /**
* Plain temporary result. * Plain temporary result.
...@@ -23,7 +23,7 @@ class MVPlainTempResult extends MVTempResult { ...@@ -23,7 +23,7 @@ class MVPlainTempResult extends MVTempResult {
/** /**
* Map with identities of rows as keys rows as values. * Map with identities of rows as keys rows as values.
*/ */
private final MVMap<Long, ValueArray> map; private final MVMap<Long, ValueRow> map;
/** /**
* Counter for the identities of rows. A separate counter is used instead of * Counter for the identities of rows. A separate counter is used instead of
...@@ -35,7 +35,7 @@ class MVPlainTempResult extends MVTempResult { ...@@ -35,7 +35,7 @@ class MVPlainTempResult extends MVTempResult {
/** /**
* Cursor for the {@link #next()} method. * Cursor for the {@link #next()} method.
*/ */
private Cursor<Long, ValueArray> cursor; private Cursor<Long, ValueRow> cursor;
/** /**
* Creates a shallow copy of the result. * Creates a shallow copy of the result.
...@@ -61,7 +61,7 @@ class MVPlainTempResult extends MVTempResult { ...@@ -61,7 +61,7 @@ class MVPlainTempResult extends MVTempResult {
MVPlainTempResult(Database database, Expression[] expressions, int visibleColumnCount) { MVPlainTempResult(Database database, Expression[] expressions, int visibleColumnCount) {
super(database, expressions.length, visibleColumnCount); super(database, expressions.length, visibleColumnCount);
ValueDataType valueType = new ValueDataType(database, new int[columnCount]); ValueDataType valueType = new ValueDataType(database, new int[columnCount]);
Builder<Long, ValueArray> builder = new MVMap.Builder<Long, ValueArray>() Builder<Long, ValueRow> builder = new MVMap.Builder<Long, ValueRow>()
.valueType(valueType).singleWriter(); .valueType(valueType).singleWriter();
map = store.openMap("tmp", builder); map = store.openMap("tmp", builder);
} }
...@@ -69,7 +69,7 @@ class MVPlainTempResult extends MVTempResult { ...@@ -69,7 +69,7 @@ class MVPlainTempResult extends MVTempResult {
@Override @Override
public int addRow(Value[] values) { public int addRow(Value[] values) {
assert parent == null; assert parent == null;
map.append(counter++, ValueArray.get(values)); map.append(counter++, ValueRow.get(values));
return ++rowCount; return ++rowCount;
} }
......
...@@ -17,7 +17,7 @@ import org.h2.mvstore.MVMap.Builder; ...@@ -17,7 +17,7 @@ import org.h2.mvstore.MVMap.Builder;
import org.h2.result.ResultExternal; import org.h2.result.ResultExternal;
import org.h2.result.SortOrder; import org.h2.result.SortOrder;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueRow;
/** /**
* Sorted temporary result. * Sorted temporary result.
...@@ -48,7 +48,7 @@ class MVSortedTempResult extends MVTempResult { ...@@ -48,7 +48,7 @@ class MVSortedTempResult extends MVTempResult {
* Map with rows as keys and counts of duplicate rows as values. If this map is * Map with rows as keys and counts of duplicate rows as values. If this map is
* distinct all values are 1. * distinct all values are 1.
*/ */
private final MVMap<ValueArray, Long> map; private final MVMap<ValueRow, Long> map;
/** /**
* Optional index. This index is created only if result is distinct and * Optional index. This index is created only if result is distinct and
...@@ -56,12 +56,12 @@ class MVSortedTempResult extends MVTempResult { ...@@ -56,12 +56,12 @@ class MVSortedTempResult extends MVTempResult {
* {@link #contains(Value[])} method is invoked. Only the root result should * {@link #contains(Value[])} method is invoked. Only the root result should
* have an index if required. * have an index if required.
*/ */
private MVMap<ValueArray, Boolean> index; private MVMap<ValueRow, Boolean> index;
/** /**
* Cursor for the {@link #next()} method. * Cursor for the {@link #next()} method.
*/ */
private Cursor<ValueArray, Long> cursor; private Cursor<ValueRow, Long> cursor;
/** /**
* Current value for the {@link #next()} method. Used in non-distinct results * Current value for the {@link #next()} method. Used in non-distinct results
...@@ -167,12 +167,12 @@ class MVSortedTempResult extends MVTempResult { ...@@ -167,12 +167,12 @@ class MVSortedTempResult extends MVTempResult {
} }
this.indexes = indexes; this.indexes = indexes;
ValueDataType keyType = new ValueDataType(database, sortTypes); ValueDataType keyType = new ValueDataType(database, sortTypes);
Builder<ValueArray, Long> builder = new MVMap.Builder<ValueArray, Long>().keyType(keyType); Builder<ValueRow, Long> builder = new MVMap.Builder<ValueRow, Long>().keyType(keyType);
map = store.openMap("tmp", builder); map = store.openMap("tmp", builder);
if (distinct && length != visibleColumnCount || distinctIndexes != null) { if (distinct && length != visibleColumnCount || distinctIndexes != null) {
int count = distinctIndexes != null ? distinctIndexes.length : visibleColumnCount; int count = distinctIndexes != null ? distinctIndexes.length : visibleColumnCount;
ValueDataType distinctType = new ValueDataType(database, new int[count]); ValueDataType distinctType = new ValueDataType(database, new int[count]);
Builder<ValueArray, Boolean> indexBuilder = new MVMap.Builder<ValueArray, Boolean>().keyType(distinctType); Builder<ValueRow, Boolean> indexBuilder = new MVMap.Builder<ValueRow, Boolean>().keyType(distinctType);
index = store.openMap("idx", indexBuilder); index = store.openMap("idx", indexBuilder);
} }
} }
...@@ -180,7 +180,7 @@ class MVSortedTempResult extends MVTempResult { ...@@ -180,7 +180,7 @@ class MVSortedTempResult extends MVTempResult {
@Override @Override
public int addRow(Value[] values) { public int addRow(Value[] values) {
assert parent == null; assert parent == null;
ValueArray key = getKey(values); ValueRow key = getKey(values);
if (distinct || distinctIndexes != null) { if (distinct || distinctIndexes != null) {
if (distinctIndexes != null) { if (distinctIndexes != null) {
int cnt = distinctIndexes.length; int cnt = distinctIndexes.length;
...@@ -188,12 +188,12 @@ class MVSortedTempResult extends MVTempResult { ...@@ -188,12 +188,12 @@ class MVSortedTempResult extends MVTempResult {
for (int i = 0; i < cnt; i++) { for (int i = 0; i < cnt; i++) {
newValues[i] = values[distinctIndexes[i]]; newValues[i] = values[distinctIndexes[i]];
} }
ValueArray distinctRow = ValueArray.get(newValues); ValueRow distinctRow = ValueRow.get(newValues);
if (index.putIfAbsent(distinctRow, true) != null) { if (index.putIfAbsent(distinctRow, true) != null) {
return rowCount; return rowCount;
} }
} else if (columnCount != visibleColumnCount) { } else if (columnCount != visibleColumnCount) {
ValueArray distinctRow = ValueArray.get(Arrays.copyOf(values, visibleColumnCount)); ValueRow distinctRow = ValueRow.get(Arrays.copyOf(values, visibleColumnCount));
if (index.putIfAbsent(distinctRow, true) != null) { if (index.putIfAbsent(distinctRow, true) != null) {
return rowCount; return rowCount;
} }
...@@ -222,7 +222,7 @@ class MVSortedTempResult extends MVTempResult { ...@@ -222,7 +222,7 @@ class MVSortedTempResult extends MVTempResult {
} }
assert distinct; assert distinct;
if (columnCount != visibleColumnCount) { if (columnCount != visibleColumnCount) {
return index.containsKey(ValueArray.get(values)); return index.containsKey(ValueRow.get(values));
} }
return map.containsKey(getKey(values)); return map.containsKey(getKey(values));
} }
...@@ -240,13 +240,13 @@ class MVSortedTempResult extends MVTempResult { ...@@ -240,13 +240,13 @@ class MVSortedTempResult extends MVTempResult {
} }
/** /**
* Reorder values if required and convert them into {@link ValueArray}. * Reorder values if required and convert them into {@link ValueRow}.
* *
* @param values * @param values
* values * values
* @return ValueArray for maps * @return ValueRow for maps
*/ */
private ValueArray getKey(Value[] values) { private ValueRow getKey(Value[] values) {
if (indexes != null) { if (indexes != null) {
Value[] r = new Value[indexes.length]; Value[] r = new Value[indexes.length];
for (int i = 0; i < indexes.length; i++) { for (int i = 0; i < indexes.length; i++) {
...@@ -254,7 +254,7 @@ class MVSortedTempResult extends MVTempResult { ...@@ -254,7 +254,7 @@ class MVSortedTempResult extends MVTempResult {
} }
values = r; values = r;
} }
return ValueArray.get(values); return ValueRow.get(values);
} }
/** /**
......
...@@ -17,7 +17,7 @@ import org.h2.util.Utils; ...@@ -17,7 +17,7 @@ import org.h2.util.Utils;
import org.h2.util.ValueHashMap; import org.h2.util.ValueHashMap;
import org.h2.value.TypeInfo; import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueRow;
/** /**
* A local result set contains all row data of a result set. * A local result set contains all row data of a result set.
...@@ -179,7 +179,7 @@ public class LocalResultImpl implements LocalResult { ...@@ -179,7 +179,7 @@ public class LocalResultImpl implements LocalResult {
} }
assert values.length == visibleColumnCount; assert values.length == visibleColumnCount;
if (distinctRows != null) { if (distinctRows != null) {
ValueArray array = ValueArray.get(values); ValueRow array = ValueRow.get(values);
distinctRows.remove(array); distinctRows.remove(array);
rowCount = distinctRows.size(); rowCount = distinctRows.size();
} else { } else {
...@@ -202,11 +202,11 @@ public class LocalResultImpl implements LocalResult { ...@@ -202,11 +202,11 @@ public class LocalResultImpl implements LocalResult {
if (distinctRows == null) { if (distinctRows == null) {
distinctRows = new ValueHashMap<>(); distinctRows = new ValueHashMap<>();
for (Value[] row : rows) { for (Value[] row : rows) {
ValueArray array = getArrayOfDistinct(row); ValueRow array = getDistinctRow(row);
distinctRows.put(array, array.getList()); distinctRows.put(array, array.getList());
} }
} }
ValueArray array = ValueArray.get(values); ValueRow array = ValueRow.get(values);
return distinctRows.get(array) != null; return distinctRows.get(array) != null;
} }
...@@ -284,7 +284,7 @@ public class LocalResultImpl implements LocalResult { ...@@ -284,7 +284,7 @@ public class LocalResultImpl implements LocalResult {
} }
} }
private ValueArray getArrayOfDistinct(Value[] values) { private ValueRow getDistinctRow(Value[] values) {
if (distinctIndexes != null) { if (distinctIndexes != null) {
int cnt = distinctIndexes.length; int cnt = distinctIndexes.length;
Value[] newValues = new Value[cnt]; Value[] newValues = new Value[cnt];
...@@ -295,7 +295,7 @@ public class LocalResultImpl implements LocalResult { ...@@ -295,7 +295,7 @@ public class LocalResultImpl implements LocalResult {
} else if (values.length > visibleColumnCount) { } else if (values.length > visibleColumnCount) {
values = Arrays.copyOf(values, visibleColumnCount); values = Arrays.copyOf(values, visibleColumnCount);
} }
return ValueArray.get(values); return ValueRow.get(values);
} }
private void createExternalResult() { private void createExternalResult() {
...@@ -317,7 +317,7 @@ public class LocalResultImpl implements LocalResult { ...@@ -317,7 +317,7 @@ public class LocalResultImpl implements LocalResult {
cloneLobs(values); cloneLobs(values);
if (isAnyDistinct()) { if (isAnyDistinct()) {
if (distinctRows != null) { if (distinctRows != null) {
ValueArray array = getArrayOfDistinct(values); ValueRow array = getDistinctRow(values);
distinctRows.putIfAbsent(array, values); distinctRows.putIfAbsent(array, values);
rowCount = distinctRows.size(); rowCount = distinctRows.size();
if (rowCount > maxMemoryRows) { if (rowCount > maxMemoryRows) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论