提交 9db9bca8 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not evaluate unneeded rows when quick offset is used

上级 32cd27c7
...@@ -706,8 +706,7 @@ public class Select extends Query { ...@@ -706,8 +706,7 @@ public class Select extends Query {
} }
ArrayList<Row>[] forUpdateRows = initForUpdateRows(); ArrayList<Row>[] forUpdateRows = initForUpdateRows();
int sampleSize = getSampleSizeValue(session); int sampleSize = getSampleSizeValue(session);
LazyResultQueryFlat lazyResult = new LazyResultQueryFlat(expressionArray, LazyResultQueryFlat lazyResult = new LazyResultQueryFlat(expressionArray, sampleSize, columnCount);
sampleSize, columnCount);
skipOffset(lazyResult, offset, quickOffset); skipOffset(lazyResult, offset, quickOffset);
if (result == null) { if (result == null) {
return lazyResult; return lazyResult;
...@@ -770,7 +769,7 @@ public class Select extends Query { ...@@ -770,7 +769,7 @@ public class Select extends Query {
private static void skipOffset(LazyResultSelect lazyResult, long offset, boolean quickOffset) { private static void skipOffset(LazyResultSelect lazyResult, long offset, boolean quickOffset) {
if (quickOffset) { if (quickOffset) {
while (offset > 0 && lazyResult.next()) { while (offset > 0 && lazyResult.skip()) {
offset--; offset--;
} }
} }
...@@ -1883,8 +1882,7 @@ public class Select extends Query { ...@@ -1883,8 +1882,7 @@ public class Select extends Query {
@Override @Override
protected Value[] fetchNextRow() { protected Value[] fetchNextRow() {
while ((sampleSize <= 0 || rowNumber < sampleSize) && while ((sampleSize <= 0 || rowNumber < sampleSize) && topTableFilter.next()) {
topTableFilter.next()) {
setCurrentRowNumber(rowNumber + 1); setCurrentRowNumber(rowNumber + 1);
if (isConditionMet()) { if (isConditionMet()) {
++rowNumber; ++rowNumber;
...@@ -1898,6 +1896,18 @@ public class Select extends Query { ...@@ -1898,6 +1896,18 @@ public class Select extends Query {
} }
return null; return null;
} }
@Override
protected boolean skipNextRow() {
while ((sampleSize <= 0 || rowNumber < sampleSize) && topTableFilter.next()) {
setCurrentRowNumber(rowNumber + 1);
if (isConditionMet()) {
++rowNumber;
return true;
}
}
return false;
}
} }
/** /**
......
...@@ -71,6 +71,27 @@ public abstract class LazyResult implements ResultInterface { ...@@ -71,6 +71,27 @@ public abstract class LazyResult implements ResultInterface {
return false; return false;
} }
/**
* Go to the next row and skip it.
*
* @return true if a row exists
*/
public boolean skip() {
if (closed || afterLast) {
return false;
}
currentRow = null;
if (nextRow != null) {
nextRow = null;
return true;
}
if (skipNextRow()) {
return true;
}
afterLast = true;
return false;
}
@Override @Override
public boolean hasNext() { public boolean hasNext() {
if (closed || afterLast) { if (closed || afterLast) {
...@@ -89,6 +110,15 @@ public abstract class LazyResult implements ResultInterface { ...@@ -89,6 +110,15 @@ public abstract class LazyResult implements ResultInterface {
*/ */
protected abstract Value[] fetchNextRow(); protected abstract Value[] fetchNextRow();
/**
* Skip next row.
*
* @return true if next row was available
*/
protected boolean skipNextRow() {
return fetchNextRow() != null;
}
@Override @Override
public boolean isAfterLast() { public boolean isAfterLast() {
return afterLast; return afterLast;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论