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