提交 77cc7372 authored 作者: Thomas Mueller's avatar Thomas Mueller

Queries using multiple IN(..) conditions on the same table could cause repeated…

Queries using multiple IN(..) conditions on the same table could cause repeated rows in the result set.
上级 dfeceb6e
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Translation: Lubomir Grajciar translated the H2 Console as well as all error message to Slovensky. Thanks a lot!
<ul><li>Queries using multiple IN(..) conditions on the same table could cause repeated rows in the result set.
</li><li>Translation: Lubomir Grajciar translated the H2 Console as well as all error message to Slovensky. Thanks a lot!
</li><li>There was a possible Java level deadlock when opening an uninitialized database and using
a file system that also opened a database.
</li><li>When killing the process while the database was writing a checkpoint or while it was closing,
......
......@@ -77,14 +77,18 @@ public class IndexCursor implements Cursor {
Column column = condition.getColumn();
if (condition.getCompareType() == Comparison.IN_LIST) {
if (start == null && end == null) {
this.inColumn = column;
inList = condition.getCurrentValueList(s);
inListIndex = 0;
if (canUseIndexForIn(column)) {
this.inColumn = column;
inList = condition.getCurrentValueList(s);
inListIndex = 0;
}
}
} else if (condition.getCompareType() == Comparison.IN_QUERY) {
if (start == null && end == null) {
this.inColumn = column;
inResult = condition.getCurrentResult(s);
if (canUseIndexForIn(column)) {
this.inColumn = column;
inResult = condition.getCurrentResult(s);
}
}
} else {
Value v = condition.getCurrentValue(s);
......@@ -128,6 +132,19 @@ public class IndexCursor implements Cursor {
}
}
private boolean canUseIndexForIn(Column column) {
if (inColumn != null) {
// only one IN(..) condition can be used at the same time
return false;
}
// The first column of the index must match this column,
// or it must be a VIEW indexe (where the column is null).
// Multiple IN conditions with views are not supported, see
// IndexCondition.getMask.
IndexColumn idxCol = indexColumns[0];
return idxCol == null || idxCol.column == column;
}
private SearchRow getSearchRow(SearchRow row, int id, Value v, boolean max) {
if (row == null) {
row = table.getTemplateRow();
......
create table test(a int, b int, unique(a, b));
insert into test values(1,1), (1,2);
select count(*) from test where a in(1,2) and b in(1,2);
> 2;
drop table test;
create memory temp table test(name varchar primary key);
select index_class from information_schema.indexes where table_name = 'TEST';
> org.h2.index.TreeIndex;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论