提交 d8ba1455 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not fetch all rows in Select.queryFlat() for WITH TIES if quick offset is available

上级 be3153dd
......@@ -654,14 +654,29 @@ public class Select extends Query {
if (result == null) {
return lazyResult;
}
if (sort != null && !sortUsingIndex || limitRows < 0 || withTies) {
if (limitRows < 0 || sort != null && !sortUsingIndex || withTies && !quickOffset) {
limitRows = Long.MAX_VALUE;
}
Value[] row = null;
while (result.getRowCount() < limitRows && lazyResult.next()) {
if (forUpdateRows != null) {
topTableFilter.lockRowAdd(forUpdateRows);
}
result.addRow(lazyResult.currentRow());
row = lazyResult.currentRow();
result.addRow(row);
}
if (limitRows != Long.MAX_VALUE && withTies && sort != null && row != null) {
Value[] expected = row;
while (lazyResult.next()) {
row = lazyResult.currentRow();
if (sort.compare(expected, row) != 0) {
break;
}
if (forUpdateRows != null) {
topTableFilter.lockRowAdd(forUpdateRows);
}
result.addRow(row);
}
}
if (forUpdateRows != null) {
topTableFilter.lockRows(forUpdateRows);
......
......@@ -411,8 +411,10 @@ public class LocalResult implements ResultInterface, ResultTarget {
rowCount++;
}
}
// avoid copying the whole array for each row
rows = new ArrayList<>(rows.subList(offset, to));
if (offset != 0 || to != rows.size()) {
// avoid copying the whole array for each row
rows = new ArrayList<>(rows.subList(offset, to));
}
} else {
if (clearAll) {
external.close();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论