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

Merge pull request #1159 from katzyn/ResultTempTable

Do not create additional indexes in copies of ResultTempTable
...@@ -71,7 +71,7 @@ public class ResultTempTable implements ResultExternal { ...@@ -71,7 +71,7 @@ public class ResultTempTable implements ResultExternal {
data.session = session; data.session = session;
table = schema.createTable(data); table = schema.createTable(data);
if (sort != null || distinct) { if (sort != null || distinct) {
createIndex(); getIndex();
} }
parent = null; parent = null;
} }
...@@ -82,14 +82,19 @@ public class ResultTempTable implements ResultExternal { ...@@ -82,14 +82,19 @@ public class ResultTempTable implements ResultExternal {
this.distinct = parent.distinct; this.distinct = parent.distinct;
this.session = parent.session; this.session = parent.session;
this.table = parent.table; this.table = parent.table;
this.index = parent.index;
this.rowCount = parent.rowCount; this.rowCount = parent.rowCount;
this.sort = parent.sort; this.sort = parent.sort;
this.containsLob = parent.containsLob; this.containsLob = parent.containsLob;
reset(); reset();
} }
private void createIndex() { private Index getIndex() {
if (parent != null) {
return parent.getIndex();
}
if (index != null) {
return index;
}
IndexColumn[] indexCols; IndexColumn[] indexCols;
if (sort != null) { if (sort != null) {
int[] colIndex = sort.getQueryColumnIndexes(); int[] colIndex = sort.getQueryColumnIndexes();
...@@ -128,7 +133,7 @@ public class ResultTempTable implements ResultExternal { ...@@ -128,7 +133,7 @@ public class ResultTempTable implements ResultExternal {
table, Constants.PREFIX_INDEX); table, Constants.PREFIX_INDEX);
int indexId = session.getDatabase().allocateObjectId(); int indexId = session.getDatabase().allocateObjectId();
IndexType indexType = IndexType.createNonUnique(true); IndexType indexType = IndexType.createNonUnique(true);
index = table.addIndex(session, indexName, indexId, indexCols, return index = table.addIndex(session, indexName, indexId, indexCols,
indexType, true, null); indexType, true, null);
} }
...@@ -274,7 +279,7 @@ public class ResultTempTable implements ResultExternal { ...@@ -274,7 +279,7 @@ public class ResultTempTable implements ResultExternal {
if (resultCursor == null) { if (resultCursor == null) {
Index idx; Index idx;
if (distinct || sort != null) { if (distinct || sort != null) {
idx = index; idx = getIndex();
} else { } else {
idx = table.getScanIndex(session); idx = table.getScanIndex(session);
} }
...@@ -304,12 +309,7 @@ public class ResultTempTable implements ResultExternal { ...@@ -304,12 +309,7 @@ public class ResultTempTable implements ResultExternal {
} }
private Cursor find(Row row) { private Cursor find(Row row) {
if (index == null) { Index index = getIndex();
// for the case "in(select ...)", the query might
// use an optimization and not create the index
// up front
createIndex();
}
Cursor cursor = index.find(session, row, row); Cursor cursor = index.find(session, row, row);
while (cursor.next()) { while (cursor.next()) {
SearchRow found = cursor.getSearchRow(); SearchRow found = cursor.getSearchRow();
......
...@@ -18,7 +18,6 @@ import java.util.Random; ...@@ -18,7 +18,6 @@ import java.util.Random;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.test.db.Db; import org.h2.test.db.Db;
import org.h2.test.db.Db.Prepared; import org.h2.test.db.Db.Prepared;
import org.h2.util.Utils;
/** /**
* This test executes random SQL statements to test if optimizations are working * This test executes random SQL statements to test if optimizations are working
...@@ -117,18 +116,6 @@ public class TestFuzzOptimizations extends TestBase { ...@@ -117,18 +116,6 @@ public class TestFuzzOptimizations extends TestBase {
} }
executeAndCompare(condition, params, message); executeAndCompare(condition, params, message);
} }
if (!config.mvStore && config.travis) {
/*
* Travis tests have problems with automatic garbage collection, so request a GC
* explicitly and print its results.
*/
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
println((Utils.getMemoryUsed() >> 10) + " MiB used");
}
} }
executeAndCompare("a >=0 and b in(?, 2) and a in(1, ?, null)", Arrays.asList("10", "2"), executeAndCompare("a >=0 and b in(?, 2) and a in(1, ?, null)", Arrays.asList("10", "2"),
"testIn() seed=-6191135606105920350L"); "testIn() seed=-6191135606105920350L");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论