提交 d5006d2b authored 作者: Thomas Mueller's avatar Thomas Mueller

Conditions on the "_rowid_" pseudo-column didn't use an index when using the MVStore.

上级 6a639782
...@@ -17,7 +17,10 @@ Change Log ...@@ -17,7 +17,10 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>The Long.MIN_VALUE could not be parsed for auto-increment (identity) columns. <ul><li>Conditions on the "_rowid_" pseudo-column didn't use an index
when using the MVStore.
</li><li>Fixed documentation that "offset" and "fetch" are also keywords since version 1.4.x.
</li><li>The Long.MIN_VALUE could not be parsed for auto-increment (identity) columns.
</li><li>Issue 573: Add implementation for Methods "isWrapperFor()" and "unwrap()" in </li><li>Issue 573: Add implementation for Methods "isWrapperFor()" and "unwrap()" in
other JDBC classes. other JDBC classes.
</li><li>Issue 572: MySQL compatibility for "order by" in update statements. </li><li>Issue 572: MySQL compatibility for "order by" in update statements.
...@@ -159,7 +162,7 @@ Change Log ...@@ -159,7 +162,7 @@ Change Log
</li><li>Implicit relative paths are disabled (system property "h2.implicitRelativePath"), </li><li>Implicit relative paths are disabled (system property "h2.implicitRelativePath"),
so that the database URL jdbc:h2:test now needs to be written as jdbc:h2:./test. so that the database URL jdbc:h2:test now needs to be written as jdbc:h2:./test.
</li><li>"select ... fetch first 1 row only" is supported with the regular mode. </li><li>"select ... fetch first 1 row only" is supported with the regular mode.
This was disabled so far because "fetch" is now a keyword. This was disabled so far because "fetch" and "offset" are now keywords.
See also Mode.supportOffsetFetch. See also Mode.supportOffsetFetch.
</li><li>Byte arrays are now sorted in unsigned mode </li><li>Byte arrays are now sorted in unsigned mode
(x'99' is larger than x'09'). (x'99' is larger than x'09').
......
...@@ -174,22 +174,26 @@ public class MVPrimaryIndex extends BaseIndex { ...@@ -174,22 +174,26 @@ public class MVPrimaryIndex extends BaseIndex {
@Override @Override
public Cursor find(Session session, SearchRow first, SearchRow last) { public Cursor find(Session session, SearchRow first, SearchRow last) {
ValueLong min, max; ValueLong min, max;
if (first == null || mainIndexColumn < 0) { if (first == null) {
min = MIN; min = MIN;
} else if (mainIndexColumn < 0) {
min = ValueLong.get(first.getKey());
} else { } else {
ValueLong v = (ValueLong) first.getValue(mainIndexColumn); ValueLong v = (ValueLong) first.getValue(mainIndexColumn);
if (v == null) { if (v == null) {
min = ZERO; min = ValueLong.get(first.getKey());
} else { } else {
min = v; min = v;
} }
} }
if (last == null || mainIndexColumn < 0) { if (last == null) {
max = MAX; max = MAX;
} else if (mainIndexColumn < 0) {
max = ValueLong.get(last.getKey());
} else { } else {
ValueLong v = (ValueLong) last.getValue(mainIndexColumn); ValueLong v = (ValueLong) last.getValue(mainIndexColumn);
if (v == null) { if (v == null) {
max = MAX; max = ValueLong.get(last.getKey());
} else { } else {
max = v; max = v;
} }
......
...@@ -41,6 +41,7 @@ public class TestOptimizations extends TestBase { ...@@ -41,6 +41,7 @@ public class TestOptimizations extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
deleteDb("optimizations"); deleteDb("optimizations");
testFastRowIdCondition();
testExplainRoundTrip(); testExplainRoundTrip();
testOrderByExpression(); testOrderByExpression();
testGroupSubquery(); testGroupSubquery();
...@@ -78,6 +79,18 @@ public class TestOptimizations extends TestBase { ...@@ -78,6 +79,18 @@ public class TestOptimizations extends TestBase {
testConvertOrToIn(); testConvertOrToIn();
deleteDb("optimizations"); deleteDb("optimizations");
} }
private void testFastRowIdCondition() throws Exception {
Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement();
stat.executeUpdate("create table many(id int) " +
"as select x from system_range(1, 10000)");
ResultSet rs = stat.executeQuery("explain analyze select * from many " +
"where _rowid_ = 400");
rs.next();
assertContains(rs.getString(1), "/* scanCount: 2 */");
conn.close();
}
private void testExplainRoundTrip() throws Exception { private void testExplainRoundTrip() throws Exception {
Connection conn = getConnection("optimizations"); Connection conn = getConnection("optimizations");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论