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

Optimize EXCLUDE GROUP part 2

上级 de4aaa48
......@@ -6,7 +6,6 @@
package org.h2.expression.aggregate;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.Iterator;
import java.util.NoSuchElementException;
......@@ -28,6 +27,8 @@ public final class WindowFrame {
final ArrayList<Value[]> orderedRows;
int cursor;
Itr(ArrayList<Value[]> orderedRows) {
this.orderedRows = orderedRows;
}
......@@ -43,8 +44,6 @@ public final class WindowFrame {
final int endIndex;
int cursor;
PlainItr(ArrayList<Value[]> orderedRows, int startIndex, int endIndex) {
super(orderedRows);
this.endIndex = endIndex;
......@@ -70,8 +69,6 @@ public final class WindowFrame {
final int startIndex;
int cursor;
PlainReverseItr(ArrayList<Value[]> orderedRows, int startIndex, int endIndex) {
super(orderedRows);
this.startIndex = startIndex;
......@@ -183,62 +180,6 @@ public final class WindowFrame {
}
private static abstract class AbstractBitSetItr extends Itr {
final BitSet set;
int cursor;
AbstractBitSetItr(ArrayList<Value[]> orderedRows, BitSet set) {
super(orderedRows);
this.set = set;
}
@Override
public final boolean hasNext() {
return cursor >= 0;
}
}
private static final class BitSetItr extends AbstractBitSetItr {
BitSetItr(ArrayList<Value[]> orderedRows, BitSet set) {
super(orderedRows, set);
cursor = set.nextSetBit(0);
}
@Override
public Value[] next() {
if (cursor < 0) {
throw new NoSuchElementException();
}
Value[] result = orderedRows.get(cursor);
cursor = set.nextSetBit(cursor + 1);
return result;
}
}
private static final class BitSetReverseItr extends AbstractBitSetItr {
BitSetReverseItr(ArrayList<Value[]> orderedRows, BitSet set) {
super(orderedRows, set);
cursor = set.length() - 1;
}
@Override
public Value[] next() {
if (cursor < 0) {
throw new NoSuchElementException();
}
Value[] result = orderedRows.get(cursor);
cursor = set.previousSetBit(cursor - 1);
return result;
}
}
private final WindowFrameUnits units;
private final WindowFrameBound starting;
......@@ -619,13 +560,13 @@ public final class WindowFrame {
}
}
} else {
BitSet set = new BitSet(endIndex + 1);
set.set(startIndex, endIndex + 1);
set.clear(exStart, exEnd + 1);
if (set.isEmpty()) {
return Collections.emptyIterator();
if (startIndex >= exStart) {
startIndex = exEnd + 1;
} else if (endIndex <= exEnd) {
endIndex = exStart - 1;
} else {
return biIterator(orderedRows, startIndex, exStart - 1, exEnd + 1, endIndex, reverse);
}
return reverse ? new BitSetReverseItr(orderedRows, set) : new BitSetItr(orderedRows, set);
}
}
return plainIterator(orderedRows, startIndex, endIndex, reverse);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论