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

Conditions of the form columnName IS NULL now use an index.

上级 4100f056
......@@ -18,14 +18,16 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>H2 Console: when the settings were not stored yet (for example when running for the first time),
the last recently used settings were not stored. A workaround was to create the file
".h2.server.properties" manually in the current user home directory, with the contents:
webAllowOthers=false, webPort=8082, webSSL=false,
0=Generic H2 (Embedded)|org.h2.Driver|jdbc\:h2\:~/test|sa
(where a comma is a newline).
<ul><li>Conditions of the form columnName IS NULL now use an index. To disable this feature,
set the system property h2.optimizeIsNull to false.
</li><li>H2 Console: when the settings were not stored yet (for example when running for the first time),
the last recently used settings were not stored. A workaround was to create the file
".h2.server.properties" manually in the current user home directory, with the contents:
webAllowOthers=false, webPort=8082, webSSL=false,
0=Generic H2 (Embedded)|org.h2.Driver|jdbc\:h2\:~/test|sa
(where a comma is a newline).
</li><li>The source code is now switched to Java 6 (JDK 1.6) by default.
Java 5 (JDK 1.5) is still supported, and the jar file is still compiled for Java 5.
Java 5 (JDK 1.5) is still supported, and the jar file is still compiled for Java 5.
</li><li>The BOM (the byte-order-mark) character 0xfeff at the beginning of the file is ignored.
This is for compatibility with Microsoft Excel.
</li><li>When opening an existing database, the cache size is set to at most
......
......@@ -433,6 +433,12 @@ public class SysProperties {
*/
public static final boolean OPTIMIZE_IN_LIST = getBooleanSetting("h2.optimizeInList", true);
/**
* System property <code>h2.optimizeIsNull</code> (default: false).<br />
* Use an index for condition of the form columnName IS NULL.
*/
public static final boolean OPTIMIZE_IS_NULL = getBooleanSetting("h2.optimizeIsNull", true);
/**
* System property <code>h2.optimizeOr</code> (default: false).<br />
* Convert (C=? OR C=?) to (C IN(?, ?)).
......
......@@ -283,9 +283,6 @@ public class Comparison extends Condition {
}
public void createIndexConditions(Session session, TableFilter filter) {
if (right == null) {
return;
}
ExpressionColumn l = null;
if (left instanceof ExpressionColumn) {
l = (ExpressionColumn) left;
......@@ -293,6 +290,17 @@ public class Comparison extends Condition {
l = null;
}
}
if (right == null) {
if (l != null) {
switch (compareType) {
case IS_NULL:
if (SysProperties.OPTIMIZE_IS_NULL) {
filter.addIndexCondition(IndexCondition.get(Comparison.EQUAL, l, ValueExpression.getNull()));
}
}
}
return;
}
ExpressionColumn r = null;
if (right instanceof ExpressionColumn) {
r = (ExpressionColumn) right;
......
......@@ -8,6 +8,8 @@ package org.h2.index;
import java.util.ArrayList;
import java.util.HashSet;
import org.h2.constant.SysProperties;
import org.h2.engine.Session;
import org.h2.expression.Comparison;
import org.h2.message.DbException;
......@@ -117,10 +119,12 @@ public class IndexCursor implements Cursor {
inList = null;
inResult = null;
}
if (isStart && isEnd) {
if (v == ValueNull.INSTANCE) {
// join on a column=NULL is always false
alwaysFalse = true;
if (!SysProperties.OPTIMIZE_IS_NULL) {
if (isStart && isEnd) {
if (v == ValueNull.INSTANCE) {
// join on a column=NULL is always false
alwaysFalse = true;
}
}
}
}
......@@ -166,7 +170,24 @@ public class IndexCursor implements Cursor {
} else if (b == null) {
return a;
}
if (SysProperties.OPTIMIZE_IS_NULL) {
// IS NULL must be checked later
if (a == ValueNull.INSTANCE) {
return b;
} else if (b == ValueNull.INSTANCE) {
return a;
}
}
int comp = a.compareTo(b, table.getDatabase().getCompareMode());
if (comp == 0) {
return a;
}
if (SysProperties.OPTIMIZE_IS_NULL) {
if (a == ValueNull.INSTANCE || b == ValueNull.INSTANCE) {
// column IS NULL AND column <op> <not null> is always false
return null;
}
}
if (!bigger) {
comp = -comp;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论