Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
52dec4ac
Unverified
提交
52dec4ac
authored
6 年前
作者:
Andrei Tokar
提交者:
GitHub
6 年前
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1176 from h2database/rowid-index
Magic value replacement with constant
上级
74b4db9a
1cccbd70
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
48 行增加
和
44 行删除
+48
-44
IndexCursor.java
h2/src/main/org/h2/index/IndexCursor.java
+5
-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
+33
-29
RowImpl.java
h2/src/main/org/h2/result/RowImpl.java
+2
-2
SearchRow.java
h2/src/main/org/h2/result/SearchRow.java
+4
-0
没有找到文件。
h2/src/main/org/h2/index/IndexCursor.java
浏览文件 @
52dec4ac
...
@@ -114,7 +114,7 @@ public class IndexCursor implements Cursor {
...
@@ -114,7 +114,7 @@ public class IndexCursor implements Cursor {
boolean
isEnd
=
condition
.
isEnd
();
boolean
isEnd
=
condition
.
isEnd
();
boolean
isIntersects
=
condition
.
isSpatialIntersects
();
boolean
isIntersects
=
condition
.
isSpatialIntersects
();
int
columnId
=
column
.
getColumnId
();
int
columnId
=
column
.
getColumnId
();
if
(
columnId
>=
0
)
{
if
(
columnId
!=
SearchRow
.
ROWID_INDEX
)
{
IndexColumn
idxCol
=
indexColumns
[
columnId
];
IndexColumn
idxCol
=
indexColumns
[
columnId
];
if
(
idxCol
!=
null
&&
(
idxCol
.
sortType
&
SortOrder
.
DESCENDING
)
!=
0
)
{
if
(
idxCol
!=
null
&&
(
idxCol
.
sortType
&
SortOrder
.
DESCENDING
)
!=
0
)
{
// if the index column is sorted the other way, we swap
// if the index column is sorted the other way, we swap
...
@@ -210,7 +210,7 @@ public class IndexCursor implements Cursor {
...
@@ -210,7 +210,7 @@ public class IndexCursor implements Cursor {
v
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
v
=
((
ValueGeometry
)
v
.
convertTo
(
Value
.
GEOMETRY
)).
getEnvelopeUnion
(
vg
);
getEnvelopeUnion
(
vg
);
}
}
if
(
columnId
<
0
)
{
if
(
columnId
==
SearchRow
.
ROWID_INDEX
)
{
row
.
setKey
(
v
.
getLong
());
row
.
setKey
(
v
.
getLong
());
}
else
{
}
else
{
row
.
setValue
(
columnId
,
v
);
row
.
setValue
(
columnId
,
v
);
...
@@ -218,14 +218,13 @@ public class IndexCursor implements Cursor {
...
@@ -218,14 +218,13 @@ public class IndexCursor implements Cursor {
return
row
;
return
row
;
}
}
private
SearchRow
getSearchRow
(
SearchRow
row
,
int
columnId
,
Value
v
,
private
SearchRow
getSearchRow
(
SearchRow
row
,
int
columnId
,
Value
v
,
boolean
max
)
{
boolean
max
)
{
if
(
row
==
null
)
{
if
(
row
==
null
)
{
row
=
table
.
getTemplateRow
();
row
=
table
.
getTemplateRow
();
}
else
{
}
else
{
v
=
getMax
(
row
.
getValue
(
columnId
),
v
,
max
);
v
=
getMax
(
row
.
getValue
(
columnId
),
v
,
max
);
}
}
if
(
columnId
<
0
)
{
if
(
columnId
==
SearchRow
.
ROWID_INDEX
)
{
row
.
setKey
(
v
.
getLong
());
row
.
setKey
(
v
.
getLong
());
}
else
{
}
else
{
row
.
setValue
(
columnId
,
v
);
row
.
setValue
(
columnId
,
v
);
...
@@ -257,10 +256,7 @@ public class IndexCursor implements Cursor {
...
@@ -257,10 +256,7 @@ public class IndexCursor implements Cursor {
return
null
;
return
null
;
}
}
}
}
if
(!
bigger
)
{
return
(
comp
>
0
)
==
bigger
?
a
:
b
;
comp
=
-
comp
;
}
return
comp
>
0
?
a
:
b
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/db/MVDelegateIndex.java
浏览文件 @
52dec4ac
...
@@ -111,7 +111,7 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
...
@@ -111,7 +111,7 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
@Override
@Override
public
void
remove
(
Session
session
)
{
public
void
remove
(
Session
session
)
{
mainIndex
.
setMainIndexColumn
(
-
1
);
mainIndex
.
setMainIndexColumn
(
SearchRow
.
ROWID_INDEX
);
}
}
@Override
@Override
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
52dec4ac
...
@@ -41,7 +41,7 @@ public class MVPrimaryIndex extends BaseIndex {
...
@@ -41,7 +41,7 @@ public class MVPrimaryIndex extends BaseIndex {
private
final
String
mapName
;
private
final
String
mapName
;
private
final
TransactionMap
<
Value
,
Value
>
dataMap
;
private
final
TransactionMap
<
Value
,
Value
>
dataMap
;
private
final
AtomicLong
lastKey
=
new
AtomicLong
(
0
);
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
,
public
MVPrimaryIndex
(
Database
db
,
MVTable
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
)
{
IndexColumn
[]
columns
,
IndexType
indexType
)
{
...
@@ -90,7 +90,7 @@ public class MVPrimaryIndex extends BaseIndex {
...
@@ -90,7 +90,7 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
@Override
public
void
add
(
Session
session
,
Row
row
)
{
public
void
add
(
Session
session
,
Row
row
)
{
if
(
mainIndexColumn
==
-
1
)
{
if
(
mainIndexColumn
==
SearchRow
.
ROWID_INDEX
)
{
if
(
row
.
getKey
()
==
0
)
{
if
(
row
.
getKey
()
==
0
)
{
row
.
setKey
(
lastKey
.
incrementAndGet
());
row
.
setKey
(
lastKey
.
incrementAndGet
());
}
}
...
@@ -239,7 +239,7 @@ public class MVPrimaryIndex extends BaseIndex {
...
@@ -239,7 +239,7 @@ public class MVPrimaryIndex extends BaseIndex {
@Override
@Override
public
int
getColumnIndex
(
Column
col
)
{
public
int
getColumnIndex
(
Column
col
)
{
// can not use this index - use the delegate index instead
// can not use this index - use the delegate index instead
return
-
1
;
return
SearchRow
.
ROWID_INDEX
;
}
}
@Override
@Override
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
52dec4ac
...
@@ -13,6 +13,7 @@ import java.util.HashSet;
...
@@ -13,6 +13,7 @@ import java.util.HashSet;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.DatabaseEventListener
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
...
@@ -33,6 +34,7 @@ import org.h2.mvstore.db.MVTableEngine.Store;
...
@@ -33,6 +34,7 @@ import org.h2.mvstore.db.MVTableEngine.Store;
import
org.h2.mvstore.tx.Transaction
;
import
org.h2.mvstore.tx.Transaction
;
import
org.h2.mvstore.tx.TransactionStore
;
import
org.h2.mvstore.tx.TransactionStore
;
import
org.h2.result.Row
;
import
org.h2.result.Row
;
import
org.h2.result.SearchRow
;
import
org.h2.result.SortOrder
;
import
org.h2.result.SortOrder
;
import
org.h2.schema.SchemaObject
;
import
org.h2.schema.SchemaObject
;
import
org.h2.table.Column
;
import
org.h2.table.Column
;
...
@@ -117,7 +119,7 @@ public class MVTable extends TableBase {
...
@@ -117,7 +119,7 @@ public class MVTable extends TableBase {
*/
*/
private
final
ArrayDeque
<
Session
>
waitingSessions
=
new
ArrayDeque
<>();
private
final
ArrayDeque
<
Session
>
waitingSessions
=
new
ArrayDeque
<>();
private
final
Trace
traceLock
;
private
final
Trace
traceLock
;
private
int
changesSince
Analyze
;
private
final
AtomicInteger
changesUnitl
Analyze
;
private
int
nextAnalyze
;
private
int
nextAnalyze
;
private
final
boolean
containsLargeObject
;
private
final
boolean
containsLargeObject
;
private
Column
rowIdColumn
;
private
Column
rowIdColumn
;
...
@@ -128,6 +130,7 @@ public class MVTable extends TableBase {
...
@@ -128,6 +130,7 @@ public class MVTable extends TableBase {
public
MVTable
(
CreateTableData
data
,
MVTableEngine
.
Store
store
)
{
public
MVTable
(
CreateTableData
data
,
MVTableEngine
.
Store
store
)
{
super
(
data
);
super
(
data
);
nextAnalyze
=
database
.
getSettings
().
analyzeAuto
;
nextAnalyze
=
database
.
getSettings
().
analyzeAuto
;
changesUnitlAnalyze
=
nextAnalyze
<=
0
?
null
:
new
AtomicInteger
(
nextAnalyze
);
this
.
store
=
store
;
this
.
store
=
store
;
this
.
transactionStore
=
store
.
getTransactionStore
();
this
.
transactionStore
=
store
.
getTransactionStore
();
this
.
isHidden
=
data
.
isHidden
;
this
.
isHidden
=
data
.
isHidden
;
...
@@ -317,15 +320,16 @@ public class MVTable extends TableBase {
...
@@ -317,15 +320,16 @@ public class MVTable extends TableBase {
return
true
;
return
true
;
}
}
}
}
if
(
!
lockSharedSessions
.
containsKey
(
session
)
)
{
if
(
lockSharedSessions
.
putIfAbsent
(
session
,
session
)
==
null
)
{
traceLock
(
session
,
exclusive
,
TraceLockEvent
.
TRACE_LOCK_OK
,
NO_EXTRA_INFO
);
traceLock
(
session
,
exclusive
,
TraceLockEvent
.
TRACE_LOCK_OK
,
NO_EXTRA_INFO
);
session
.
addLock
(
this
);
session
.
addLock
(
this
);
lockSharedSessions
.
put
(
session
,
session
);
if
(
SysProperties
.
THREAD_DEADLOCK_DETECTOR
)
{
if
(
SysProperties
.
THREAD_DEADLOCK_DETECTOR
)
{
if
(
SHARED_LOCKS
.
get
()
==
null
)
{
ArrayList
<
String
>
list
=
SHARED_LOCKS
.
get
();
SHARED_LOCKS
.
set
(
new
ArrayList
<
String
>());
if
(
list
==
null
)
{
list
=
new
ArrayList
<>();
SHARED_LOCKS
.
set
(
list
);
}
}
SHARED_LOCKS
.
get
()
.
add
(
getName
());
list
.
add
(
getName
());
}
}
}
}
return
true
;
return
true
;
...
@@ -353,7 +357,7 @@ public class MVTable extends TableBase {
...
@@ -353,7 +357,7 @@ public class MVTable extends TableBase {
}
}
buff
.
append
(
t
.
toString
());
buff
.
append
(
t
.
toString
());
if
(
t
instanceof
MVTable
)
{
if
(
t
instanceof
MVTable
)
{
if
(
((
MVTable
)
t
).
lockExclusiveSession
==
s
)
{
if
(
t
.
isLockedExclusivelyBy
(
s
)
)
{
buff
.
append
(
" (exclusive)"
);
buff
.
append
(
" (exclusive)"
);
}
else
{
}
else
{
buff
.
append
(
" (shared)"
);
buff
.
append
(
" (shared)"
);
...
@@ -517,12 +521,12 @@ public class MVTable extends TableBase {
...
@@ -517,12 +521,12 @@ public class MVTable extends TableBase {
mainIndexColumn
=
getMainIndexColumn
(
indexType
,
cols
);
mainIndexColumn
=
getMainIndexColumn
(
indexType
,
cols
);
if
(
database
.
isStarting
())
{
if
(
database
.
isStarting
())
{
if
(
transactionStore
.
hasMap
(
"index."
+
indexId
))
{
if
(
transactionStore
.
hasMap
(
"index."
+
indexId
))
{
mainIndexColumn
=
-
1
;
mainIndexColumn
=
SearchRow
.
ROWID_INDEX
;
}
}
}
else
if
(
primaryIndex
.
getRowCountMax
()
!=
0
)
{
}
else
if
(
primaryIndex
.
getRowCountMax
()
!=
0
)
{
mainIndexColumn
=
-
1
;
mainIndexColumn
=
SearchRow
.
ROWID_INDEX
;
}
}
if
(
mainIndexColumn
!=
-
1
)
{
if
(
mainIndexColumn
!=
SearchRow
.
ROWID_INDEX
)
{
primaryIndex
.
setMainIndexColumn
(
mainIndexColumn
);
primaryIndex
.
setMainIndexColumn
(
mainIndexColumn
);
index
=
new
MVDelegateIndex
(
this
,
indexId
,
indexName
,
primaryIndex
,
index
=
new
MVDelegateIndex
(
this
,
indexId
,
indexName
,
primaryIndex
,
indexType
);
indexType
);
...
@@ -656,15 +660,15 @@ public class MVTable extends TableBase {
...
@@ -656,15 +660,15 @@ public class MVTable extends TableBase {
}
}
private
int
getMainIndexColumn
(
IndexType
indexType
,
IndexColumn
[]
cols
)
{
private
int
getMainIndexColumn
(
IndexType
indexType
,
IndexColumn
[]
cols
)
{
if
(
primaryIndex
.
getMainIndexColumn
()
!=
-
1
)
{
if
(
primaryIndex
.
getMainIndexColumn
()
!=
SearchRow
.
ROWID_INDEX
)
{
return
-
1
;
return
SearchRow
.
ROWID_INDEX
;
}
}
if
(!
indexType
.
isPrimaryKey
()
||
cols
.
length
!=
1
)
{
if
(!
indexType
.
isPrimaryKey
()
||
cols
.
length
!=
1
)
{
return
-
1
;
return
SearchRow
.
ROWID_INDEX
;
}
}
IndexColumn
first
=
cols
[
0
];
IndexColumn
first
=
cols
[
0
];
if
(
first
.
sortType
!=
SortOrder
.
ASCENDING
)
{
if
(
first
.
sortType
!=
SortOrder
.
ASCENDING
)
{
return
-
1
;
return
SearchRow
.
ROWID_INDEX
;
}
}
switch
(
first
.
column
.
getType
())
{
switch
(
first
.
column
.
getType
())
{
case
Value
.
BYTE
:
case
Value
.
BYTE
:
...
@@ -673,7 +677,7 @@ public class MVTable extends TableBase {
...
@@ -673,7 +677,7 @@ public class MVTable extends TableBase {
case
Value
.
LONG
:
case
Value
.
LONG
:
break
;
break
;
default
:
default
:
return
-
1
;
return
SearchRow
.
ROWID_INDEX
;
}
}
return
first
.
column
.
getColumnId
();
return
first
.
column
.
getColumnId
();
}
}
...
@@ -687,10 +691,10 @@ public class MVTable extends TableBase {
...
@@ -687,10 +691,10 @@ public class MVTable extends TableBase {
list
.
clear
();
list
.
clear
();
}
}
private
static
void
sortRows
(
ArrayList
<
Row
>
list
,
final
Index
index
)
{
private
static
void
sortRows
(
ArrayList
<
?
extends
Search
Row
>
list
,
final
Index
index
)
{
Collections
.
sort
(
list
,
new
Comparator
<
Row
>()
{
Collections
.
sort
(
list
,
new
Comparator
<
Search
Row
>()
{
@Override
@Override
public
int
compare
(
Row
r1
,
Row
r2
)
{
public
int
compare
(
SearchRow
r1
,
Search
Row
r2
)
{
return
index
.
compareRows
(
r1
,
r2
);
return
index
.
compareRows
(
r1
,
r2
);
}
}
});
});
...
@@ -724,7 +728,9 @@ public class MVTable extends TableBase {
...
@@ -724,7 +728,9 @@ public class MVTable extends TableBase {
Index
index
=
indexes
.
get
(
i
);
Index
index
=
indexes
.
get
(
i
);
index
.
truncate
(
session
);
index
.
truncate
(
session
);
}
}
changesSinceAnalyze
=
0
;
if
(
changesUnitlAnalyze
!=
null
)
{
changesUnitlAnalyze
.
set
(
nextAnalyze
);
}
}
}
@Override
@Override
...
@@ -753,17 +759,15 @@ public class MVTable extends TableBase {
...
@@ -753,17 +759,15 @@ public class MVTable extends TableBase {
}
}
private
void
analyzeIfRequired
(
Session
session
)
{
private
void
analyzeIfRequired
(
Session
session
)
{
synchronized
(
this
)
{
if
(
changesUnitlAnalyze
!=
null
)
{
if
(
nextAnalyze
==
0
||
nextAnalyze
>
changesSinceAnalyze
++)
{
if
(
changesUnitlAnalyze
.
decrementAndGet
()
==
0
)
{
return
;
if
(
nextAnalyze
<=
Integer
.
MAX_VALUE
/
2
)
{
nextAnalyze
*=
2
;
}
}
changesSinceAnalyze
=
0
;
changesUnitlAnalyze
.
set
(
nextAnalyze
);
int
n
=
2
*
nextAnalyze
;
session
.
markTableForAnalyze
(
this
);
if
(
n
>
0
)
{
nextAnalyze
=
n
;
}
}
}
}
session
.
markTableForAnalyze
(
this
);
}
}
@Override
@Override
...
@@ -885,7 +889,7 @@ public class MVTable extends TableBase {
...
@@ -885,7 +889,7 @@ public class MVTable extends TableBase {
public
Column
getRowIdColumn
()
{
public
Column
getRowIdColumn
()
{
if
(
rowIdColumn
==
null
)
{
if
(
rowIdColumn
==
null
)
{
rowIdColumn
=
new
Column
(
Column
.
ROWID
,
Value
.
LONG
);
rowIdColumn
=
new
Column
(
Column
.
ROWID
,
Value
.
LONG
);
rowIdColumn
.
setTable
(
this
,
-
1
);
rowIdColumn
.
setTable
(
this
,
SearchRow
.
ROWID_INDEX
);
}
}
return
rowIdColumn
;
return
rowIdColumn
;
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/RowImpl.java
浏览文件 @
52dec4ac
...
@@ -73,7 +73,7 @@ public class RowImpl implements Row {
...
@@ -73,7 +73,7 @@ public class RowImpl implements Row {
@Override
@Override
public
Value
getValue
(
int
i
)
{
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 {
...
@@ -93,7 +93,7 @@ public class RowImpl implements Row {
@Override
@Override
public
void
setValue
(
int
i
,
Value
v
)
{
public
void
setValue
(
int
i
,
Value
v
)
{
if
(
i
==
-
1
)
{
if
(
i
==
SearchRow
.
ROWID_INDEX
)
{
this
.
key
=
v
.
getLong
();
this
.
key
=
v
.
getLong
();
}
else
{
}
else
{
data
[
i
]
=
v
;
data
[
i
]
=
v
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/result/SearchRow.java
浏览文件 @
52dec4ac
...
@@ -12,6 +12,10 @@ import org.h2.value.Value;
...
@@ -12,6 +12,10 @@ import org.h2.value.Value;
* index.
* index.
*/
*/
public
interface
SearchRow
{
public
interface
SearchRow
{
/**
* Index of a virtual "_ROWID_" column within a row or a table
*/
int
ROWID_INDEX
=
-
1
;
/**
/**
* An empty array of SearchRow objects.
* An empty array of SearchRow objects.
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论