Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a4ed2d4c
提交
a4ed2d4c
authored
6月 03, 2018
作者:
Andrei Tokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Magic value replacement with constant
assorted minor refactorings
上级
8b4bfee5
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
47 行增加
和
37 行删除
+47
-37
IndexCursor.java
h2/src/main/org/h2/index/IndexCursor.java
+13
-9
MVDelegateIndex.java
h2/src/main/org/h2/mvstore/db/MVDelegateIndex.java
+1
-1
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+3
-3
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+26
-22
RowImpl.java
h2/src/main/org/h2/result/RowImpl.java
+2
-2
SearchRow.java
h2/src/main/org/h2/result/SearchRow.java
+2
-0
没有找到文件。
h2/src/main/org/h2/index/IndexCursor.java
浏览文件 @
a4ed2d4c
...
...
@@ -114,7 +114,7 @@ public class IndexCursor implements Cursor {
boolean
isEnd
=
condition
.
isEnd
();
boolean
isIntersects
=
condition
.
isSpatialIntersects
();
int
columnId
=
column
.
getColumnId
();
if
(
columnId
>=
0
)
{
if
(
columnId
!=
SearchRow
.
ROWID_INDEX
)
{
IndexColumn
idxCol
=
indexColumns
[
columnId
];
if
(
idxCol
!=
null
&&
(
idxCol
.
sortType
&
SortOrder
.
DESCENDING
)
!=
0
)
{
// if the index column is sorted the other way, we swap
...
...
@@ -210,7 +210,7 @@ public class IndexCursor implements Cursor {
v
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeUnion
(
vg
);
}
if
(
columnId
<
0
)
{
if
(
columnId
==
SearchRow
.
ROWID_INDEX
)
{
row
.
setKey
(
v
.
getLong
());
}
else
{
row
.
setValue
(
columnId
,
v
);
...
...
@@ -218,14 +218,21 @@ public class IndexCursor implements Cursor {
return
row
;
}
private
SearchRow
getSearchRow
(
SearchRow
row
,
int
columnId
,
Value
v
,
boolean
max
)
{
private
SearchRow
getSearchRow
(
SearchRow
row
,
int
columnId
,
Value
v
,
boolean
max
)
{
Column
column
=
columnId
==
SearchRow
.
ROWID_INDEX
?
table
.
getRowIdColumn
()
:
table
.
getColumn
(
columnId
);
int
vType
=
v
.
getType
();
int
resType
=
Value
.
getHigherOrder
(
column
.
getType
(),
vType
);
if
(
vType
!=
resType
)
{
v
=
column
.
convert
(
v
,
session
.
getDatabase
().
getMode
());
}
if
(
row
==
null
)
{
row
=
table
.
getTemplateRow
();
}
else
{
v
=
getMax
(
row
.
getValue
(
columnId
),
v
,
max
);
}
if
(
columnId
<
0
)
{
if
(
columnId
==
SearchRow
.
ROWID_INDEX
)
{
row
.
setKey
(
v
.
getLong
());
}
else
{
row
.
setValue
(
columnId
,
v
);
...
...
@@ -257,10 +264,7 @@ public class IndexCursor implements Cursor {
return
null
;
}
}
if
(!
bigger
)
{
comp
=
-
comp
;
}
return
comp
>
0
?
a
:
b
;
return
(
comp
>
0
)
==
bigger
?
a
:
b
;
}
/**
...
...
h2/src/main/org/h2/mvstore/db/MVDelegateIndex.java
浏览文件 @
a4ed2d4c
...
...
@@ -111,7 +111,7 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
@Override
public
void
remove
(
Session
session
)
{
mainIndex
.
setMainIndexColumn
(
-
1
);
mainIndex
.
setMainIndexColumn
(
SearchRow
.
ROWID_INDEX
);
}
@Override
...
...
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
a4ed2d4c
...
...
@@ -41,7 +41,7 @@ public class MVPrimaryIndex extends BaseIndex {
private
final
String
mapName
;
private
final
TransactionMap
<
Value
,
Value
>
dataMap
;
private
final
AtomicLong
lastKey
=
new
AtomicLong
(
0
);
private
int
mainIndexColumn
=
-
1
;
private
int
mainIndexColumn
=
SearchRow
.
ROWID_INDEX
;
public
MVPrimaryIndex
(
Database
db
,
MVTable
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
)
{
...
...
@@ -90,7 +90,7 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
public
void
add
(
Session
session
,
Row
row
)
{
if
(
mainIndexColumn
==
-
1
)
{
if
(
mainIndexColumn
==
SearchRow
.
ROWID_INDEX
)
{
if
(
row
.
getKey
()
==
0
)
{
row
.
setKey
(
lastKey
.
incrementAndGet
());
}
...
...
@@ -239,7 +239,7 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
public
int
getColumnIndex
(
Column
col
)
{
// can not use this index - use the delegate index instead
return
-
1
;
return
SearchRow
.
ROWID_INDEX
;
}
@Override
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
a4ed2d4c
...
...
@@ -33,6 +33,7 @@ import org.h2.mvstore.db.MVTableEngine.Store;
import
org.h2.mvstore.tx.Transaction
;
import
org.h2.mvstore.tx.TransactionStore
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.schema.SchemaObject
;
import
org.h2.table.Column
;
...
...
@@ -128,6 +129,9 @@ public class MVTable extends TableBase {
public
MVTable
(
CreateTableData
data
,
MVTableEngine
.
Store
store
)
{
super
(
data
);
nextAnalyze
=
database
.
getSettings
().
analyzeAuto
;
if
(
nextAnalyze
<=
0
)
{
nextAnalyze
=
Integer
.
MAX_VALUE
;
}
this
.
store
=
store
;
this
.
transactionStore
=
store
.
getTransactionStore
();
this
.
isHidden
=
data
.
isHidden
;
...
...
@@ -317,15 +321,16 @@ public class MVTable extends TableBase {
return
true
;
}
}
if
(
!
lockSharedSessions
.
containsKey
(
session
)
)
{
if
(
lockSharedSessions
.
putIfAbsent
(
session
,
session
)
==
null
)
{
traceLock
(
session
,
exclusive
,
TraceLockEvent
.
TRACE_LOCK_OK
,
NO_EXTRA_INFO
);
session
.
addLock
(
this
);
lockSharedSessions
.
put
(
session
,
session
);
if
(
SysProperties
.
THREAD_DEADLOCK_DETECTOR
)
{
if
(
SHARED_LOCKS
.
get
()
==
null
)
{
SHARED_LOCKS
.
set
(
new
ArrayList
<
String
>());
ArrayList
<
String
>
list
=
SHARED_LOCKS
.
get
();
if
(
list
==
null
)
{
list
=
new
ArrayList
<>();
SHARED_LOCKS
.
set
(
list
);
}
SHARED_LOCKS
.
get
()
.
add
(
getName
());
list
.
add
(
getName
());
}
}
return
true
;
...
...
@@ -353,7 +358,7 @@ public class MVTable extends TableBase {
}
buff
.
append
(
t
.
toString
());
if
(
t
instanceof
MVTable
)
{
if
(
((
MVTable
)
t
).
lockExclusiveSession
==
s
)
{
if
(
t
.
isLockedExclusivelyBy
(
s
)
)
{
buff
.
append
(
" (exclusive)"
);
}
else
{
buff
.
append
(
" (shared)"
);
...
...
@@ -517,12 +522,12 @@ public class MVTable extends TableBase {
mainIndexColumn
=
getMainIndexColumn
(
indexType
,
cols
);
if
(
database
.
isStarting
())
{
if
(
transactionStore
.
hasMap
(
"index."
+
indexId
))
{
mainIndexColumn
=
-
1
;
mainIndexColumn
=
SearchRow
.
ROWID_INDEX
;
}
}
else
if
(
primaryIndex
.
getRowCountMax
()
!=
0
)
{
mainIndexColumn
=
-
1
;
mainIndexColumn
=
SearchRow
.
ROWID_INDEX
;
}
if
(
mainIndexColumn
!=
-
1
)
{
if
(
mainIndexColumn
!=
SearchRow
.
ROWID_INDEX
)
{
primaryIndex
.
setMainIndexColumn
(
mainIndexColumn
);
index
=
new
MVDelegateIndex
(
this
,
indexId
,
indexName
,
primaryIndex
,
indexType
);
...
...
@@ -656,15 +661,15 @@ public class MVTable extends TableBase {
}
private
int
getMainIndexColumn
(
IndexType
indexType
,
IndexColumn
[]
cols
)
{
if
(
primaryIndex
.
getMainIndexColumn
()
!=
-
1
)
{
return
-
1
;
if
(
primaryIndex
.
getMainIndexColumn
()
!=
SearchRow
.
ROWID_INDEX
)
{
return
SearchRow
.
ROWID_INDEX
;
}
if
(!
indexType
.
isPrimaryKey
()
||
cols
.
length
!=
1
)
{
return
-
1
;
return
SearchRow
.
ROWID_INDEX
;
}
IndexColumn
first
=
cols
[
0
];
if
(
first
.
sortType
!=
SortOrder
.
ASCENDING
)
{
return
-
1
;
return
SearchRow
.
ROWID_INDEX
;
}
switch
(
first
.
column
.
getType
())
{
case
Value
.
BYTE
:
...
...
@@ -673,7 +678,7 @@ public class MVTable extends TableBase {
case
Value
.
LONG
:
break
;
default
:
return
-
1
;
return
SearchRow
.
ROWID_INDEX
;
}
return
first
.
column
.
getColumnId
();
}
...
...
@@ -687,10 +692,10 @@ public class MVTable extends TableBase {
list
.
clear
();
}
private
static
void
sortRows
(
ArrayList
<
Row
>
list
,
final
Index
index
)
{
Collections
.
sort
(
list
,
new
Comparator
<
Row
>()
{
private
static
void
sortRows
(
ArrayList
<
?
extends
Search
Row
>
list
,
final
Index
index
)
{
Collections
.
sort
(
list
,
new
Comparator
<
Search
Row
>()
{
@Override
public
int
compare
(
Row
r1
,
Row
r2
)
{
public
int
compare
(
SearchRow
r1
,
Search
Row
r2
)
{
return
index
.
compareRows
(
r1
,
r2
);
}
});
...
...
@@ -754,13 +759,12 @@ public class MVTable extends TableBase {
private
void
analyzeIfRequired
(
Session
session
)
{
synchronized
(
this
)
{
if
(
nextAnalyze
==
0
||
nextAnalyze
>
changesSinceAnalyze
++
)
{
if
(
++
changesSinceAnalyze
<=
nextAnalyze
)
{
return
;
}
changesSinceAnalyze
=
0
;
int
n
=
2
*
nextAnalyze
;
if
(
n
>
0
)
{
nextAnalyze
=
n
;
if
(
nextAnalyze
<=
Integer
.
MAX_VALUE
/
2
)
{
nextAnalyze
*=
2
;
}
}
session
.
markTableForAnalyze
(
this
);
...
...
@@ -885,7 +889,7 @@ public class MVTable extends TableBase {
public
Column
getRowIdColumn
()
{
if
(
rowIdColumn
==
null
)
{
rowIdColumn
=
new
Column
(
Column
.
ROWID
,
Value
.
LONG
);
rowIdColumn
.
setTable
(
this
,
-
1
);
rowIdColumn
.
setTable
(
this
,
SearchRow
.
ROWID_INDEX
);
}
return
rowIdColumn
;
}
...
...
h2/src/main/org/h2/result/RowImpl.java
浏览文件 @
a4ed2d4c
...
...
@@ -73,7 +73,7 @@ public class RowImpl implements Row {
@Override
public
Value
getValue
(
int
i
)
{
return
i
==
-
1
?
ValueLong
.
get
(
key
)
:
data
[
i
];
return
i
==
SearchRow
.
ROWID_INDEX
?
ValueLong
.
get
(
key
)
:
data
[
i
];
}
/**
...
...
@@ -93,7 +93,7 @@ public class RowImpl implements Row {
@Override
public
void
setValue
(
int
i
,
Value
v
)
{
if
(
i
==
-
1
)
{
if
(
i
==
SearchRow
.
ROWID_INDEX
)
{
this
.
key
=
v
.
getLong
();
}
else
{
data
[
i
]
=
v
;
...
...
h2/src/main/org/h2/result/SearchRow.java
浏览文件 @
a4ed2d4c
...
...
@@ -13,6 +13,8 @@ import org.h2.value.Value;
*/
public
interface
SearchRow
{
int
ROWID_INDEX
=
-
1
;
/**
* An empty array of SearchRow objects.
*/
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论