Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
36fc00c4
提交
36fc00c4
authored
1月 18, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename containsNullAndAllowMultipleNull() to mayHaveDuplicates()
Previous name was incorrect.
上级
9ba6f143
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
45 行增加
和
37 行删除
+45
-37
Mode.java
h2/src/main/org/h2/engine/Mode.java
+13
-14
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+28
-19
PageBtree.java
h2/src/main/org/h2/index/PageBtree.java
+1
-1
TreeIndex.java
h2/src/main/org/h2/index/TreeIndex.java
+1
-1
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+2
-2
没有找到文件。
h2/src/main/org/h2/engine/Mode.java
浏览文件 @
36fc00c4
...
@@ -87,17 +87,16 @@ public class Mode {
...
@@ -87,17 +87,16 @@ public class Mode {
public
boolean
systemColumns
;
public
boolean
systemColumns
;
/**
/**
* For unique indexes, NULL is distinct. That means only one row with NULL
* <ul>
* in one of the columns is allowed.
* <li>If {@code 0}, multiple identical indexed columns with at least one
* {@code NULL} value are allowed in unique index.</li>
* <li>If {@code 1}, multiple identical indexed columns with all {@code NULL}
* values are allowed in unique index.</li>
* <li>If {@code 2}, multiple identical indexed columns are not allowed in
* unique index.</li>
* </ul>
*/
*/
public
boolean
uniqueIndexSingleNull
;
public
byte
uniquieIndexNullsHandling
;
/**
* When using unique indexes, multiple rows with NULL in all columns
* are allowed, however it is not allowed to have multiple rows with the
* same values otherwise.
*/
public
boolean
uniqueIndexSingleNullExceptAllColumnsAreNull
;
/**
/**
* Empty strings are treated like NULL values. Useful for Oracle emulation.
* Empty strings are treated like NULL values. Useful for Oracle emulation.
...
@@ -208,7 +207,7 @@ public class Mode {
...
@@ -208,7 +207,7 @@ public class Mode {
mode
=
new
Mode
(
ModeEnum
.
Derby
.
name
());
mode
=
new
Mode
(
ModeEnum
.
Derby
.
name
());
mode
.
aliasColumnName
=
true
;
mode
.
aliasColumnName
=
true
;
mode
.
uniqu
eIndexSingleNull
=
true
;
mode
.
uniqu
ieIndexNullsHandling
=
2
;
mode
.
supportOffsetFetch
=
true
;
mode
.
supportOffsetFetch
=
true
;
mode
.
sysDummy1
=
true
;
mode
.
sysDummy1
=
true
;
mode
.
isolationLevelInSelectOrInsertStatement
=
true
;
mode
.
isolationLevelInSelectOrInsertStatement
=
true
;
...
@@ -220,7 +219,7 @@ public class Mode {
...
@@ -220,7 +219,7 @@ public class Mode {
mode
.
aliasColumnName
=
true
;
mode
.
aliasColumnName
=
true
;
mode
.
convertOnlyToSmallerScale
=
true
;
mode
.
convertOnlyToSmallerScale
=
true
;
mode
.
nullConcatIsNull
=
true
;
mode
.
nullConcatIsNull
=
true
;
mode
.
uniqu
eIndexSingleNull
=
true
;
mode
.
uniqu
ieIndexNullsHandling
=
2
;
mode
.
allowPlusForStringConcat
=
true
;
mode
.
allowPlusForStringConcat
=
true
;
// HSQLDB does not support client info properties. See
// HSQLDB does not support client info properties. See
// http://hsqldb.org/doc/apidocs/
// http://hsqldb.org/doc/apidocs/
...
@@ -232,7 +231,7 @@ public class Mode {
...
@@ -232,7 +231,7 @@ public class Mode {
mode
=
new
Mode
(
ModeEnum
.
MSSQLServer
.
name
());
mode
=
new
Mode
(
ModeEnum
.
MSSQLServer
.
name
());
mode
.
aliasColumnName
=
true
;
mode
.
aliasColumnName
=
true
;
mode
.
squareBracketQuotedNames
=
true
;
mode
.
squareBracketQuotedNames
=
true
;
mode
.
uniqu
eIndexSingleNull
=
true
;
mode
.
uniqu
ieIndexNullsHandling
=
2
;
mode
.
allowPlusForStringConcat
=
true
;
mode
.
allowPlusForStringConcat
=
true
;
mode
.
swapConvertFunctionParameters
=
true
;
mode
.
swapConvertFunctionParameters
=
true
;
mode
.
supportPoundSymbolForColumnNames
=
true
;
mode
.
supportPoundSymbolForColumnNames
=
true
;
...
@@ -260,7 +259,7 @@ public class Mode {
...
@@ -260,7 +259,7 @@ public class Mode {
mode
=
new
Mode
(
ModeEnum
.
Oracle
.
name
());
mode
=
new
Mode
(
ModeEnum
.
Oracle
.
name
());
mode
.
aliasColumnName
=
true
;
mode
.
aliasColumnName
=
true
;
mode
.
convertOnlyToSmallerScale
=
true
;
mode
.
convertOnlyToSmallerScale
=
true
;
mode
.
uniqu
eIndexSingleNullExceptAllColumnsAreNull
=
true
;
mode
.
uniqu
ieIndexNullsHandling
=
1
;
mode
.
treatEmptyStringsAsNull
=
true
;
mode
.
treatEmptyStringsAsNull
=
true
;
mode
.
regexpReplaceBackslashReferences
=
true
;
mode
.
regexpReplaceBackslashReferences
=
true
;
mode
.
supportPoundSymbolForColumnNames
=
true
;
mode
.
supportPoundSymbolForColumnNames
=
true
;
...
...
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
36fc00c4
...
@@ -9,7 +9,6 @@ import java.util.HashSet;
...
@@ -9,7 +9,6 @@ import java.util.HashSet;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Constants
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.DbObject
;
import
org.h2.engine.Mode
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.message.Trace
;
import
org.h2.message.Trace
;
...
@@ -302,33 +301,43 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -302,33 +301,43 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
}
}
/**
/**
* Check if one of the columns is NULL and multiple rows with NULL are
* Check if this row may have duplicates with the same indexed values in the
* allowed using the current compatibility mode for unique indexes. Note:
* current compatibility mode.
* NULL behavior is complicated in SQL.
*
*
* @param newRow the row to check
* @param searchRow
* @return true if one of the columns is null and multiple nulls in unique
* the row to check
* indexes are allowed
* @return {@code true} if specified row may have duplicates,
* {@code false otherwise}
*/
*/
protected
boolean
containsNullAndAllowMultipleNull
(
SearchRow
newRow
)
{
protected
boolean
mayHaveDuplicates
(
SearchRow
searchRow
)
{
Mode
mode
=
database
.
getMode
();
int
mode
=
database
.
getMode
().
uniquieIndexNullsHandling
;
if
(
mode
.
uniqueIndexSingleNull
)
{
/*
* Multiple identical indexed columns with at least one NULL value are allowed
* in unique index.
*/
if
(
mode
==
0
)
{
for
(
int
index
:
columnIds
)
{
if
(
searchRow
.
getValue
(
index
)
==
ValueNull
.
INSTANCE
)
{
return
true
;
}
}
return
false
;
return
false
;
}
else
if
(
mode
.
uniqueIndexSingleNullExceptAllColumnsAreNull
)
{
}
/*
* Multiple identical indexed columns with all {@code NULL} values are allowed
* in unique index.
*/
if
(
mode
==
1
)
{
for
(
int
index
:
columnIds
)
{
for
(
int
index
:
columnIds
)
{
Value
v
=
newRow
.
getValue
(
index
);
if
(
searchRow
.
getValue
(
index
)
!=
ValueNull
.
INSTANCE
)
{
if
(
v
!=
ValueNull
.
INSTANCE
)
{
return
false
;
return
false
;
}
}
}
}
return
true
;
return
true
;
}
}
for
(
int
index
:
columnIds
)
{
/*
Value
v
=
newRow
.
getValue
(
index
);
* Multiple identical indexed columns are not allowed in unique index.
if
(
v
==
ValueNull
.
INSTANCE
)
{
*/
return
true
;
}
}
return
false
;
return
false
;
}
}
...
...
h2/src/main/org/h2/index/PageBtree.java
浏览文件 @
36fc00c4
...
@@ -116,7 +116,7 @@ public abstract class PageBtree extends Page {
...
@@ -116,7 +116,7 @@ public abstract class PageBtree extends Page {
comp
=
index
.
compareRows
(
row
,
compare
);
comp
=
index
.
compareRows
(
row
,
compare
);
if
(
comp
==
0
)
{
if
(
comp
==
0
)
{
if
(
add
&&
index
.
indexType
.
isUnique
())
{
if
(
add
&&
index
.
indexType
.
isUnique
())
{
if
(!
index
.
containsNullAndAllowMultipleNull
(
compare
))
{
if
(!
index
.
mayHaveDuplicates
(
compare
))
{
throw
index
.
getDuplicateKeyException
(
compare
.
toString
());
throw
index
.
getDuplicateKeyException
(
compare
.
toString
());
}
}
}
}
...
...
h2/src/main/org/h2/index/TreeIndex.java
浏览文件 @
36fc00c4
...
@@ -66,7 +66,7 @@ public class TreeIndex extends BaseIndex {
...
@@ -66,7 +66,7 @@ public class TreeIndex extends BaseIndex {
int
compare
=
compareRows
(
row
,
r
);
int
compare
=
compareRows
(
row
,
r
);
if
(
compare
==
0
)
{
if
(
compare
==
0
)
{
if
(
indexType
.
isUnique
())
{
if
(
indexType
.
isUnique
())
{
if
(!
containsNullAndAllowMultipleNull
(
row
))
{
if
(!
mayHaveDuplicates
(
row
))
{
throw
getDuplicateKeyException
(
row
.
toString
());
throw
getDuplicateKeyException
(
row
.
toString
());
}
}
}
}
...
...
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
36fc00c4
...
@@ -208,7 +208,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
...
@@ -208,7 +208,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
if
(
compareRows
(
row
,
r2
)
!=
0
)
{
if
(
compareRows
(
row
,
r2
)
!=
0
)
{
break
;
break
;
}
}
if
(
containsNullAndAllowMultipleNull
(
r2
))
{
if
(
mayHaveDuplicates
(
r2
))
{
// this is allowed
// this is allowed
continue
;
continue
;
}
}
...
@@ -233,7 +233,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
...
@@ -233,7 +233,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
break
;
break
;
}
}
if
(
map
.
get
(
k
)
!=
null
)
{
if
(
map
.
get
(
k
)
!=
null
)
{
if
(!
containsNullAndAllowMultipleNull
(
r2
))
{
if
(!
mayHaveDuplicates
(
r2
))
{
throw
getDuplicateKeyException
(
k
.
toString
());
throw
getDuplicateKeyException
(
k
.
toString
());
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论