提交 5d14674d authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Avoid copying of external result if WITH TIES limit was already applied

上级 d8ba1455
......@@ -267,6 +267,11 @@ public class Insert extends Prepared implements ResultTarget {
return rowNumber;
}
@Override
public void limitsWereApplied() {
// Nothing to do
}
@Override
public String getPlanSQL() {
StatementBuilder buff = new StatementBuilder("INSERT INTO ");
......
......@@ -677,6 +677,7 @@ public class Select extends Query {
}
result.addRow(row);
}
result.limitsWereApplied();
}
if (forUpdateRows != null) {
topTableFilter.lockRows(forUpdateRows);
......
......@@ -42,6 +42,7 @@ public class LocalResult implements ResultInterface, ResultTarget {
private int offset;
private int limit = -1;
private boolean withTies;
private boolean limitsWereApplied;
private ResultExternal external;
private boolean distinct;
private int[] distinctIndexes;
......@@ -381,6 +382,9 @@ public class LocalResult implements ResultInterface, ResultTarget {
}
private void applyOffsetAndLimit() {
if (limitsWereApplied) {
return;
}
int offset = Math.max(this.offset, 0);
int limit = this.limit;
if (offset == 0 && limit < 0 || rowCount == 0) {
......@@ -461,6 +465,11 @@ public class LocalResult implements ResultInterface, ResultTarget {
return rowCount;
}
@Override
public void limitsWereApplied() {
this.limitsWereApplied = true;
}
@Override
public boolean hasNext() {
return !closed && rowId < rowCount - 1;
......
......@@ -26,4 +26,11 @@ public interface ResultTarget {
*/
int getRowCount();
/**
* A hint that offset and limit may be ignored by this result because they
* were applied during the query. This is useful for WITH TIES clause
* because result may contain tied rows above limit.
*/
void limitsWereApplied();
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论