提交 88741eb5 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use TreeSet in IndexCondition and remove IndexCursor.inResultTested

上级 2cdafd3a
......@@ -319,6 +319,15 @@ public abstract class Query extends Prepared {
return distinct;
}
/**
* Returns whether results support random access.
*
* @return whether results support random access
*/
public boolean isRandomAccessResult() {
return randomAccessResult;
}
/**
* Whether results need to support random access.
*
......
......@@ -7,8 +7,8 @@ package org.h2.index;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.TreeSet;
import org.h2.command.dml.Query;
import org.h2.engine.Session;
import org.h2.expression.Expression;
......@@ -123,8 +123,8 @@ public class IndexCondition {
* @return the index condition
*/
public static IndexCondition getInQuery(ExpressionColumn column, Query query) {
IndexCondition cond = new IndexCondition(Comparison.IN_QUERY, column,
null);
assert query.isRandomAccessResult();
IndexCondition cond = new IndexCondition(Comparison.IN_QUERY, column, null);
cond.expressionQuery = query;
return cond;
}
......@@ -147,7 +147,7 @@ public class IndexCondition {
* @return the value list
*/
public Value[] getCurrentValueList(Session session) {
HashSet<Value> valueSet = new HashSet<>();
TreeSet<Value> valueSet = new TreeSet<>(session.getDatabase().getCompareMode());
for (Expression e : expressionList) {
Value v = e.getValue(session);
v = column.convert(v);
......
......@@ -6,7 +6,6 @@
package org.h2.index;
import java.util.ArrayList;
import java.util.HashSet;
import org.h2.engine.Session;
import org.h2.expression.condition.Comparison;
......@@ -45,7 +44,6 @@ public class IndexCursor implements Cursor {
private int inListIndex;
private Value[] inList;
private ResultInterface inResult;
private HashSet<Value> inResultTested;
public IndexCursor(TableFilter filter) {
this.tableFilter = filter;
......@@ -79,7 +77,6 @@ public class IndexCursor implements Cursor {
inList = null;
inColumn = null;
inResult = null;
inResultTested = null;
intersects = null;
for (IndexCondition condition : indexConditions) {
if (condition.isAlwaysFalse()) {
......@@ -311,13 +308,8 @@ public class IndexCursor implements Cursor {
while (inResult.next()) {
Value v = inResult.currentRow()[0];
if (v != ValueNull.INSTANCE) {
if (inResultTested == null) {
inResultTested = new HashSet<>();
}
if (inResultTested.add(v)) {
find(v);
break;
}
find(v);
break;
}
}
}
......
......@@ -29,3 +29,32 @@ SELECT DISTINCT * FROM TEST;
DROP TABLE TEST;
> ok
CREATE TABLE TEST (N NUMERIC) AS VALUES (0), (0.0), (2), (NULL);
> ok
CREATE INDEX TEST_IDX ON TEST(N);
> ok
SELECT N FROM TEST WHERE N IN (0.000, 0.00, 1.0);
> N
> ---
> 0
> 0.0
> rows: 2
SELECT N FROM TEST WHERE N IN (SELECT DISTINCT ON(B) A FROM VALUES (0.000, 1), (0.00, 2), (1.0, 3) T(A, B));
> N
> ---
> 0
> 0.0
> rows: 2
DROP INDEX TEST_IDX;
> ok
CREATE UNIQUE INDEX TEST_IDX ON TEST(N);
> exception DUPLICATE_KEY_1
DROP TABLE TEST;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论