Unverified 提交 7a60c09e authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1692 from katzyn/external

Use MVTempResult unconditionally
......@@ -62,14 +62,14 @@ class MVPlainTempResult extends MVTempResult {
super(database, expressions.length, visibleColumnCount);
ValueDataType valueType = new ValueDataType(database, new int[columnCount]);
Builder<Long, ValueRow> builder = new MVMap.Builder<Long, ValueRow>()
.valueType(valueType).singleWriter();
.valueType(valueType);
map = store.openMap("tmp", builder);
}
@Override
public int addRow(Value[] values) {
assert parent == null;
map.append(counter++, ValueRow.get(values));
map.put(counter++, ValueRow.get(values));
return ++rowCount;
}
......
......@@ -301,12 +301,8 @@ public class LocalResultImpl implements LocalResult {
}
private void createExternalResult() {
Database database = session.getDatabase();
external = database.isMVStore()
|| /* not supported by ResultTempTable */ distinct && expressions.length != visibleColumnCount
|| distinctIndexes != null
? MVTempResult.of(database, expressions, distinct, distinctIndexes, visibleColumnCount, sort)
: new ResultTempTable(session, expressions, distinct, sort);
external = MVTempResult.of(session.getDatabase(), expressions, distinct, distinctIndexes, visibleColumnCount,
sort);
}
/**
......
......@@ -200,6 +200,7 @@ import org.h2.test.unit.TestJmx;
import org.h2.test.unit.TestKeywords;
import org.h2.test.unit.TestLocalResultFactory;
import org.h2.test.unit.TestLocale;
import org.h2.test.unit.TestMVTempResult;
import org.h2.test.unit.TestMathUtils;
import org.h2.test.unit.TestMemoryUnmapper;
import org.h2.test.unit.TestMode;
......@@ -960,6 +961,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestSpinLock());
addTest(new TestStreamStore());
addTest(new TestTransactionStore());
addTest(new TestMVTempResult());
// unit
addTest(new TestAnsCompression());
......
/*
* Copyright 2004-2019 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.test.unit;
import java.lang.ProcessBuilder.Redirect;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.test.TestBase;
import org.h2.tools.DeleteDbFiles;
/**
* Tests that MVTempResult implementations do not produce OOME.
*/
public class TestMVTempResult extends TestBase {
private static final int MEMORY = 128;
private static final int ROWS = 1_000_000;
/**
* May be used to run only this test and may be launched by this test in a
* subprocess.
*
* @param a
* if empty run this test, if not empty run the subprocess
*/
public static void main(String... a) throws Exception {
TestMVTempResult test = (TestMVTempResult) TestBase.createCaller().init();
if (a.length == 0) {
test.test();
} else {
test.runTest();
}
}
@Override
public void test() throws Exception {
ProcessBuilder pb = new ProcessBuilder().redirectError(Redirect.INHERIT);
pb.command(getJVM(), "-Xmx" + MEMORY + "M", "-cp", getClassPath(), "-ea", getClass().getName(), "dummy");
assertEquals(0, pb.start().waitFor());
}
private void runTest() throws SQLException {
String dir = getBaseDir();
String name = "testResultExternal";
DeleteDbFiles.execute(dir, name, true);
try (Connection c = DriverManager.getConnection("jdbc:h2:" + dir + '/' + name)) {
Statement s = c.createStatement();
try (ResultSet rs = s.executeQuery("SELECT X, RAND() R FROM SYSTEM_RANGE(1, " + ROWS + ") ORDER BY R")) {
for (int i = 1; i <= ROWS; i++) {
assertTrue(rs.next());
}
}
try (ResultSet rs = s.executeQuery("SELECT X, RAND() FROM SYSTEM_RANGE(1, " + ROWS + ')')) {
for (int i = 1; i <= ROWS; i++) {
assertTrue(rs.next());
assertEquals(i, rs.getLong(1));
}
}
}
DeleteDbFiles.execute(dir, name, true);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论