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

Check UniqueIndexNullsHandling in HashIndex

上级 99bb9cda
...@@ -10,6 +10,7 @@ import java.util.HashMap; ...@@ -10,6 +10,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.h2.command.dml.AllColumnsForPlan; import org.h2.command.dml.AllColumnsForPlan;
import org.h2.engine.Mode.UniqueIndexNullsHandling;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.result.Row; import org.h2.result.Row;
...@@ -58,7 +59,8 @@ public class HashIndex extends BaseIndex { ...@@ -58,7 +59,8 @@ public class HashIndex extends BaseIndex {
@Override @Override
public void add(Session session, Row row) { public void add(Session session, Row row) {
Value key = row.getValue(indexColumn); Value key = row.getValue(indexColumn);
if (key != ValueNull.INSTANCE) { if (key != ValueNull.INSTANCE
|| database.getMode().uniqueIndexNullsHandling == UniqueIndexNullsHandling.FORBID_ANY_DUPLICATES) {
Object old = rows.get(key); Object old = rows.get(key);
if (old != null) { if (old != null) {
// TODO index duplicate key for hash indexes: is this allowed? // TODO index duplicate key for hash indexes: is this allowed?
...@@ -73,7 +75,8 @@ public class HashIndex extends BaseIndex { ...@@ -73,7 +75,8 @@ public class HashIndex extends BaseIndex {
@Override @Override
public void remove(Session session, Row row) { public void remove(Session session, Row row) {
Value key = row.getValue(indexColumn); Value key = row.getValue(indexColumn);
if (key != ValueNull.INSTANCE) { if (key != ValueNull.INSTANCE
|| database.getMode().uniqueIndexNullsHandling == UniqueIndexNullsHandling.FORBID_ANY_DUPLICATES) {
rows.remove(key); rows.remove(key);
} else { } else {
nullRows.remove(row.getKey()); nullRows.remove(row.getKey());
...@@ -87,7 +90,8 @@ public class HashIndex extends BaseIndex { ...@@ -87,7 +90,8 @@ public class HashIndex extends BaseIndex {
throw DbException.throwInternalError(first + " " + last); throw DbException.throwInternalError(first + " " + last);
} }
Value v = first.getValue(indexColumn); Value v = first.getValue(indexColumn);
if (v == ValueNull.INSTANCE) { if (v == ValueNull.INSTANCE
&& database.getMode().uniqueIndexNullsHandling != UniqueIndexNullsHandling.FORBID_ANY_DUPLICATES) {
return new NonUniqueHashCursor(session, tableData, nullRows); return new NonUniqueHashCursor(session, tableData, nullRows);
} }
/* /*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论