Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c7b592e3
提交
c7b592e3
authored
5月 03, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add external storage of temporary results for MVStore mode
上级
760c36b8
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
417 行增加
和
7 行删除
+417
-7
MVPlainTempResult.java
h2/src/main/org/h2/mvstore/db/MVPlainTempResult.java
+90
-0
MVSortedTempResult.java
h2/src/main/org/h2/mvstore/db/MVSortedTempResult.java
+188
-0
MVTableEngine.java
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
+10
-6
MVTempResult.java
h2/src/main/org/h2/mvstore/db/MVTempResult.java
+125
-0
LocalResult.java
h2/src/main/org/h2/result/LocalResult.java
+4
-1
没有找到文件。
h2/src/main/org/h2/mvstore/db/MVPlainTempResult.java
0 → 100644
浏览文件 @
c7b592e3
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
mvstore
.
db
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.Cursor
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVMap.Builder
;
import
org.h2.result.ResultExternal
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
import
org.h2.value.ValueLong
;
/**
* Plain temporary result.
*/
class
MVPlainTempResult
extends
MVTempResult
{
private
final
MVMap
<
ValueLong
,
ValueArray
>
map
;
private
long
counter
;
private
Cursor
<
ValueLong
,
ValueArray
>
cursor
;
private
MVPlainTempResult
(
MVPlainTempResult
parent
)
{
super
(
parent
);
this
.
map
=
parent
.
map
;
}
MVPlainTempResult
(
Session
session
,
Expression
[]
expressions
)
{
super
(
session
);
Database
db
=
session
.
getDatabase
();
ValueDataType
keyType
=
new
ValueDataType
(
null
,
null
,
null
);
ValueDataType
valueType
=
new
ValueDataType
(
db
.
getCompareMode
(),
db
,
new
int
[
expressions
.
length
]);
Builder
<
ValueLong
,
ValueArray
>
builder
=
new
MVMap
.
Builder
<
ValueLong
,
ValueArray
>().
keyType
(
keyType
)
.
valueType
(
valueType
);
map
=
store
.
openMap
(
"tmp"
,
builder
);
}
@Override
public
int
addRow
(
Value
[]
values
)
{
map
.
put
(
ValueLong
.
get
(
counter
++),
ValueArray
.
get
(
values
));
return
++
rowCount
;
}
@Override
public
boolean
contains
(
Value
[]
values
)
{
throw
DbException
.
getUnsupportedException
(
"contains()"
);
}
@Override
public
synchronized
ResultExternal
createShallowCopy
()
{
if
(
parent
!=
null
)
{
return
parent
.
createShallowCopy
();
}
if
(
closed
)
{
return
null
;
}
childCount
++;
return
new
MVPlainTempResult
(
this
);
}
@Override
public
Value
[]
next
()
{
if
(
cursor
==
null
)
{
cursor
=
map
.
cursor
(
null
);
}
if
(!
cursor
.
hasNext
())
{
return
null
;
}
cursor
.
next
();
return
cursor
.
getValue
().
getList
();
}
@Override
public
int
removeRow
(
Value
[]
values
)
{
throw
DbException
.
getUnsupportedException
(
"removeRow()"
);
}
@Override
public
void
reset
()
{
cursor
=
null
;
}
}
h2/src/main/org/h2/mvstore/db/MVSortedTempResult.java
0 → 100644
浏览文件 @
c7b592e3
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
mvstore
.
db
;
import
java.util.BitSet
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.mvstore.Cursor
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVMap.Builder
;
import
org.h2.result.ResultExternal
;
import
org.h2.result.SortOrder
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
/**
* Sorted temporary result.
*/
class
MVSortedTempResult
extends
MVTempResult
{
private
final
boolean
distinct
;
private
final
int
[]
indexes
;
private
final
MVMap
<
ValueArray
,
Long
>
map
;
private
Cursor
<
ValueArray
,
Long
>
cursor
;
private
Value
[]
current
;
private
long
valueCount
;
private
MVSortedTempResult
(
MVSortedTempResult
parent
)
{
super
(
parent
);
this
.
distinct
=
parent
.
distinct
;
this
.
indexes
=
parent
.
indexes
;
this
.
map
=
parent
.
map
;
this
.
rowCount
=
parent
.
rowCount
;
}
/**
* Creates a new sorted temporary result.
*/
MVSortedTempResult
(
Session
session
,
Expression
[]
expressions
,
boolean
distinct
,
SortOrder
sort
)
{
super
(
session
);
this
.
distinct
=
distinct
;
Database
db
=
session
.
getDatabase
();
int
length
=
expressions
.
length
;
int
[]
sortTypes
=
new
int
[
length
];
int
[]
indexes
;
if
(
sort
!=
null
)
{
indexes
=
new
int
[
length
];
int
[]
colIndex
=
sort
.
getQueryColumnIndexes
();
int
len
=
colIndex
.
length
;
BitSet
used
=
new
BitSet
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
idx
=
colIndex
[
i
];
used
.
set
(
idx
);
indexes
[
i
]
=
idx
;
sortTypes
[
i
]
=
sort
.
getSortTypes
()[
i
];
}
int
idx
=
0
;
for
(
int
i
=
len
;
i
<
length
;
i
++)
{
idx
=
used
.
nextClearBit
(
idx
);
indexes
[
i
]
=
idx
;
idx
++;
}
sameOrder:
{
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
if
(
indexes
[
i
]
!=
i
)
{
break
sameOrder
;
}
}
indexes
=
null
;
}
}
else
{
indexes
=
null
;
}
this
.
indexes
=
indexes
;
ValueDataType
keyType
=
new
ValueDataType
(
db
.
getCompareMode
(),
db
,
sortTypes
);
Builder
<
ValueArray
,
Long
>
builder
=
new
MVMap
.
Builder
<
ValueArray
,
Long
>().
keyType
(
keyType
);
map
=
store
.
openMap
(
"tmp"
,
builder
);
}
@Override
public
int
addRow
(
Value
[]
values
)
{
ValueArray
key
=
getKey
(
values
);
if
(
distinct
)
{
if
(
map
.
putIfAbsent
(
key
,
1L
)
==
null
)
{
rowCount
++;
}
}
else
{
Long
old
=
map
.
putIfAbsent
(
key
,
1L
);
if
(
old
!=
null
)
{
map
.
put
(
key
,
old
+
1
);
}
rowCount
++;
}
return
rowCount
;
}
@Override
public
boolean
contains
(
Value
[]
values
)
{
return
map
.
containsKey
(
getKey
(
values
));
}
@Override
public
synchronized
ResultExternal
createShallowCopy
()
{
if
(
parent
!=
null
)
{
return
parent
.
createShallowCopy
();
}
if
(
closed
)
{
return
null
;
}
childCount
++;
return
new
MVSortedTempResult
(
this
);
}
private
ValueArray
getKey
(
Value
[]
values
)
{
if
(
indexes
!=
null
)
{
Value
[]
r
=
new
Value
[
indexes
.
length
];
for
(
int
i
=
0
;
i
<
indexes
.
length
;
i
++)
{
r
[
indexes
[
i
]]
=
values
[
i
];
}
values
=
r
;
}
return
ValueArray
.
get
(
values
);
}
private
Value
[]
getValue
(
Value
[]
key
)
{
if
(
indexes
!=
null
)
{
Value
[]
r
=
new
Value
[
indexes
.
length
];
for
(
int
i
=
0
;
i
<
indexes
.
length
;
i
++)
{
r
[
i
]
=
key
[
indexes
[
i
]];
}
key
=
r
;
}
return
key
;
}
@Override
public
Value
[]
next
()
{
if
(
cursor
==
null
)
{
cursor
=
map
.
cursor
(
null
);
current
=
null
;
valueCount
=
0L
;
}
if
(--
valueCount
>
0
)
{
return
current
;
}
current
=
null
;
if
(!
cursor
.
hasNext
())
{
return
null
;
}
current
=
getValue
(
cursor
.
next
().
getList
());
valueCount
=
cursor
.
getValue
();
return
current
;
}
@Override
public
int
removeRow
(
Value
[]
values
)
{
ValueArray
key
=
getKey
(
values
);
if
(
distinct
)
{
if
(
map
.
remove
(
key
)
!=
null
)
{
rowCount
--;
}
}
else
{
Long
old
=
map
.
remove
(
key
);
if
(
old
!=
null
)
{
long
l
=
old
;
if
(
l
>
1
)
{
map
.
put
(
key
,
l
-
1
);
}
rowCount
--;
}
}
return
rowCount
;
}
@Override
public
void
reset
()
{
cursor
=
null
;
current
=
null
;
valueCount
=
0L
;
}
}
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
浏览文件 @
c7b592e3
...
@@ -75,12 +75,7 @@ public class MVTableEngine implements TableEngine {
...
@@ -75,12 +75,7 @@ public class MVTableEngine implements TableEngine {
}
}
if
(
key
!=
null
)
{
if
(
key
!=
null
)
{
encrypted
=
true
;
encrypted
=
true
;
char
[]
password
=
new
char
[
key
.
length
/
2
];
builder
.
encryptionKey
(
decodePassword
(
key
));
for
(
int
i
=
0
;
i
<
password
.
length
;
i
++)
{
password
[
i
]
=
(
char
)
(((
key
[
i
+
i
]
&
255
)
<<
16
)
|
((
key
[
i
+
i
+
1
])
&
255
));
}
builder
.
encryptionKey
(
password
);
}
}
if
(
db
.
getSettings
().
compressData
)
{
if
(
db
.
getSettings
().
compressData
)
{
builder
.
compress
();
builder
.
compress
();
...
@@ -101,6 +96,15 @@ public class MVTableEngine implements TableEngine {
...
@@ -101,6 +96,15 @@ public class MVTableEngine implements TableEngine {
return
store
;
return
store
;
}
}
static
char
[]
decodePassword
(
byte
[]
key
)
{
char
[]
password
=
new
char
[
key
.
length
/
2
];
for
(
int
i
=
0
;
i
<
password
.
length
;
i
++)
{
password
[
i
]
=
(
char
)
(((
key
[
i
+
i
]
&
255
)
<<
16
)
|
((
key
[
i
+
i
+
1
])
&
255
));
}
return
password
;
}
@Override
@Override
public
TableBase
createTable
(
CreateTableData
data
)
{
public
TableBase
createTable
(
CreateTableData
data
)
{
Database
db
=
data
.
session
.
getDatabase
();
Database
db
=
data
.
session
.
getDatabase
();
...
...
h2/src/main/org/h2/mvstore/db/MVTempResult.java
0 → 100644
浏览文件 @
c7b592e3
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
mvstore
.
db
;
import
java.io.IOException
;
import
java.lang.ref.Reference
;
import
java.util.ArrayList
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Session
;
import
org.h2.expression.Expression
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.MVStore
;
import
org.h2.mvstore.MVStore.Builder
;
import
org.h2.result.ResultExternal
;
import
org.h2.result.SortOrder
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.util.TempFileDeleter
;
import
org.h2.value.Value
;
/**
* Temporary result.
*/
public
abstract
class
MVTempResult
implements
ResultExternal
{
/**
* Creates MVStore-based temporary result.
*
* @param session
* session
* @param expressions
* expressions
* @param distinct
* is output distinct
* @param sort
* sort order, or {@code null}
* @return temporary result
*/
public
static
ResultExternal
of
(
Session
session
,
Expression
[]
expressions
,
boolean
distinct
,
SortOrder
sort
)
{
return
distinct
||
sort
!=
null
?
new
MVSortedTempResult
(
session
,
expressions
,
distinct
,
sort
)
:
new
MVPlainTempResult
(
session
,
expressions
);
}
final
MVStore
store
;
int
rowCount
;
final
MVTempResult
parent
;
int
childCount
;
boolean
closed
;
private
final
TempFileDeleter
tempFileDeleter
;
private
final
String
fileName
;
private
final
Reference
<?>
fileRef
;
MVTempResult
(
MVTempResult
parent
)
{
this
.
parent
=
parent
;
this
.
store
=
parent
.
store
;
this
.
fileName
=
null
;
this
.
tempFileDeleter
=
null
;
this
.
fileRef
=
null
;
}
MVTempResult
(
Session
session
)
{
try
{
fileName
=
FileUtils
.
createTempFile
(
"h2tmp"
,
Constants
.
SUFFIX_TEMP_FILE
,
false
,
true
);
Builder
builder
=
new
MVStore
.
Builder
().
autoCommitDisabled
().
fileName
(
fileName
);
byte
[]
key
=
session
.
getDatabase
().
getFileEncryptionKey
();
if
(
key
!=
null
)
{
builder
.
encryptionKey
(
MVTableEngine
.
decodePassword
(
key
));
}
store
=
builder
.
open
();
tempFileDeleter
=
session
.
getDatabase
().
getTempFileDeleter
();
fileRef
=
tempFileDeleter
.
addFile
(
fileName
,
this
);
}
catch
(
IOException
e
)
{
throw
DbException
.
convert
(
e
);
}
parent
=
null
;
}
@Override
public
int
addRows
(
ArrayList
<
Value
[]>
rows
)
{
for
(
Value
[]
row
:
rows
)
{
addRow
(
row
);
}
return
rowCount
;
}
@Override
public
synchronized
void
close
()
{
if
(
closed
)
{
return
;
}
closed
=
true
;
if
(
parent
!=
null
)
{
parent
.
closeChild
();
}
else
{
if
(
childCount
==
0
)
{
delete
();
}
}
}
private
synchronized
void
closeChild
()
{
if
(--
childCount
==
0
&&
closed
)
{
delete
();
}
}
private
void
delete
()
{
store
.
closeImmediately
();
tempFileDeleter
.
deleteFile
(
fileRef
,
fileName
);
}
@Override
public
void
done
()
{
// Do nothing
}
}
h2/src/main/org/h2/result/LocalResult.java
浏览文件 @
c7b592e3
...
@@ -15,6 +15,7 @@ import org.h2.engine.Session;
...
@@ -15,6 +15,7 @@ import org.h2.engine.Session;
import
org.h2.engine.SessionInterface
;
import
org.h2.engine.SessionInterface
;
import
org.h2.expression.Expression
;
import
org.h2.expression.Expression
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.db.MVTempResult
;
import
org.h2.util.Utils
;
import
org.h2.util.Utils
;
import
org.h2.util.ValueHashMap
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.DataType
;
import
org.h2.value.DataType
;
...
@@ -290,7 +291,9 @@ public class LocalResult implements ResultInterface, ResultTarget {
...
@@ -290,7 +291,9 @@ public class LocalResult implements ResultInterface, ResultTarget {
}
}
private
void
createExternalResult
()
{
private
void
createExternalResult
()
{
external
=
new
ResultTempTable
(
session
,
expressions
,
distinct
,
sort
);
external
=
session
.
getDatabase
().
getMvStore
()
!=
null
?
MVTempResult
.
of
(
session
,
expressions
,
distinct
,
sort
)
:
new
ResultTempTable
(
session
,
expressions
,
distinct
,
sort
);
}
}
/**
/**
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论