提交 83d70464 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not create additional indexes in copies of ResultTempTable

上级 096f44e1
...@@ -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();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论