提交 728d18f2 authored 作者: S.Vladykin's avatar S.Vladykin

JoinBatch.reset called after query as well as before to cleanup resources immediately

上级 6b374192
...@@ -639,18 +639,25 @@ public class Select extends Query { ...@@ -639,18 +639,25 @@ public class Select extends Query {
topTableFilter.lock(session, exclusive, exclusive); topTableFilter.lock(session, exclusive, exclusive);
ResultTarget to = result != null ? result : target; ResultTarget to = result != null ? result : target;
if (limitRows != 0) { if (limitRows != 0) {
if (isQuickAggregateQuery) { try {
queryQuick(columnCount, to); if (isQuickAggregateQuery) {
} else if (isGroupQuery) { queryQuick(columnCount, to);
if (isGroupSortedQuery) { } else if (isGroupQuery) {
queryGroupSorted(columnCount, to); if (isGroupSortedQuery) {
queryGroupSorted(columnCount, to);
} else {
queryGroup(columnCount, result);
}
} else if (isDistinctQuery) {
queryDistinct(to, limitRows);
} else { } else {
queryGroup(columnCount, result); queryFlat(columnCount, to, limitRows);
}
} finally {
JoinBatch jb = getJoinBatch();
if (jb != null) {
jb.reset(false);
} }
} else if (isDistinctQuery) {
queryDistinct(to, limitRows);
} else {
queryFlat(columnCount, to, limitRows);
} }
} }
if (offsetExpr != null) { if (offsetExpr != null) {
......
...@@ -59,7 +59,9 @@ public interface IndexLookupBatch { ...@@ -59,7 +59,9 @@ public interface IndexLookupBatch {
String getPlanSQL(); String getPlanSQL();
/** /**
* Reset this batch to clear state. This method will be called before each query execution. * Reset this batch to clear state. This method will be called before and after each query execution.
*
* @param beforeQuery if it is being called before query execution
*/ */
void reset(); void reset(boolean beforeQuery);
} }
...@@ -107,15 +107,17 @@ public final class JoinBatch { ...@@ -107,15 +107,17 @@ public final class JoinBatch {
/** /**
* Reset state of this batch. * Reset state of this batch.
*
* @param beforeQuery {@code true} if reset was called before the query run, {@code false} if after
*/ */
public void reset() { public void reset(boolean beforeQuery) {
current = null; current = null;
started = false; started = false;
found = false; found = false;
for (JoinFilter jf : filters) { for (JoinFilter jf : filters) {
jf.reset(); jf.reset(beforeQuery);
} }
if (additionalFilter != null) { if (beforeQuery && additionalFilter != null) {
additionalFilter.reset(); additionalFilter.reset();
} }
} }
...@@ -423,9 +425,9 @@ public final class JoinBatch { ...@@ -423,9 +425,9 @@ public final class JoinBatch {
assert lookupBatch != null || id == 0; assert lookupBatch != null || id == 0;
} }
private void reset() { private void reset(boolean beforeQuery) {
if (lookupBatch != null) { if (lookupBatch != null) {
lookupBatch.reset(); lookupBatch.reset(beforeQuery);
} }
} }
...@@ -659,7 +661,7 @@ public final class JoinBatch { ...@@ -659,7 +661,7 @@ public final class JoinBatch {
} }
@Override @Override
public void reset() { public void reset(boolean beforeQuery) {
full = false; full = false;
first = last = null; first = last = null;
result.set(0, null); result.set(0, null);
...@@ -783,11 +785,11 @@ public final class JoinBatch { ...@@ -783,11 +785,11 @@ public final class JoinBatch {
} }
@Override @Override
public void reset() { public void reset(boolean beforeQuery) {
if (resultSize != 0 && !resetAfterFind()) { if (resultSize != 0 && !resetAfterFind()) {
// find was not called, need to just clear runners // find was not called, need to just clear runners
for (int i = 0; i < resultSize; i++) { for (int i = 0; i < resultSize; i++) {
((QueryRunnerBase) result.get(i)).clear(); queryRunner(i).clear();
} }
resultSize = 0; resultSize = 0;
} }
......
...@@ -328,7 +328,7 @@ public class TableFilter implements ColumnResolver { ...@@ -328,7 +328,7 @@ public class TableFilter implements ColumnResolver {
public void reset() { public void reset() {
if (joinBatch != null && joinFilterId == 0) { if (joinBatch != null && joinFilterId == 0) {
// reset join batch only on top table filter // reset join batch only on top table filter
joinBatch.reset(); joinBatch.reset(true);
return; return;
} }
if (nestedJoin != null) { if (nestedJoin != null) {
......
...@@ -1344,7 +1344,7 @@ public class TestTableEngines extends TestBase { ...@@ -1344,7 +1344,7 @@ public class TestTableEngines extends TestBase {
} }
@Override @Override
public void reset() { public void reset(boolean beforeQuery) {
searchRows.clear(); searchRows.clear();
} }
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论