Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b9283ea4
提交
b9283ea4
authored
10月 11, 2015
作者:
Thomas Mueller Graf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Formatting / Javadocs
上级
2134953d
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
64 行增加
和
51 行删除
+64
-51
Optimizer.java
h2/src/main/org/h2/command/dml/Optimizer.java
+5
-3
OptimizerHints.java
h2/src/main/org/h2/command/dml/OptimizerHints.java
+25
-16
TestOptimizerHints.java
h2/src/test/org/h2/test/db/TestOptimizerHints.java
+14
-14
TestMvcc4.java
h2/src/test/org/h2/test/mvcc/TestMvcc4.java
+19
-17
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
没有找到文件。
h2/src/main/org/h2/command/dml/Optimizer.java
浏览文件 @
b9283ea4
...
...
@@ -54,13 +54,15 @@ class Optimizer {
}
/**
* @return {@code true} If join reordering is enabled (it can be disabled by hint).
* Whether join reordering is enabled (it can be disabled by hint).
*
* @return {@code true} if yes
*/
private
static
boolean
isJoinReorderingEnabled
()
{
OptimizerHints
hints
=
OptimizerHints
.
get
();
return
hints
==
null
||
hints
.
joinReorderEnabled
;
return
hints
==
null
||
hints
.
getJoinReorderEnabled
()
;
}
/**
* How many filter to calculate using brute force. The remaining filters are
* selected using a greedy algorithm which has a runtime of (1 + 2 + ... +
...
...
h2/src/main/org/h2/command/dml/OptimizerHints.java
浏览文件 @
b9283ea4
...
...
@@ -6,23 +6,26 @@
package
org
.
h2
.
command
.
dml
;
/**
* Thread local hints for H2 query optimizer. All the ongoing queries in the current thread
* will run with respect to these hints, so if they are needed only for a single
* operation it is preferable to setup and drop them in try-finally block.
*
* Thread local hints for H2 query optimizer. All the ongoing queries in the
* current thread will run with respect to these hints, so if they are needed
* only for a single operation it is preferable to setup and drop them in
* try-finally block.
*
* Currently works only in embedded mode.
*
*
* @author Sergi Vladykin
*/
public
class
OptimizerHints
{
private
static
final
ThreadLocal
<
OptimizerHints
>
HINTS
=
new
ThreadLocal
<
OptimizerHints
>();
boolean
joinReorderEnabled
=
true
;
private
static
final
ThreadLocal
<
OptimizerHints
>
HINTS
=
new
ThreadLocal
<
OptimizerHints
>();
private
boolean
joinReorderEnabled
=
true
;
/**
* Set thread local hints or {@code null} to drop any existing hints.
*
* @param hints
*
* @param hints
the hints
*/
public
static
void
set
(
OptimizerHints
hints
)
{
if
(
hints
!=
null
)
{
...
...
@@ -31,21 +34,27 @@ public class OptimizerHints {
HINTS
.
remove
();
}
}
/**
* @return Current thread local hints or {@code null} if none.
* Get the current thread local hints or {@code null} if none.
*
* @return the hints
*/
public
static
OptimizerHints
get
()
{
return
HINTS
.
get
();
}
/**
* Set whether reordering of tables (or anything else in the {@code FROM}
clause) is enabled.
* By default is {@code true}.
*
* Set whether reordering of tables (or anything else in the {@code FROM}
*
clause) is enabled.
By default is {@code true}.
*
* @param joinReorderEnabled Flag value.
*/
public
void
setJoinReorderEnabled
(
boolean
joinReorderEnabled
)
{
this
.
joinReorderEnabled
=
joinReorderEnabled
;
}
public
boolean
getJoinReorderEnabled
()
{
return
joinReorderEnabled
;
}
}
h2/src/test/org/h2/test/db/TestOptimizerHints.java
浏览文件 @
b9283ea4
...
...
@@ -13,8 +13,8 @@ import org.h2.command.dml.OptimizerHints;
import
org.h2.test.TestBase
;
/**
* Test for optimizer hints.
*
* Test for optimizer hints.
*
* @author Sergi Vladykin
*/
public
class
TestOptimizerHints
extends
TestBase
{
...
...
@@ -36,34 +36,34 @@ public class TestOptimizerHints extends TestBase {
deleteDb
(
"testOptimizerHints"
);
Connection
conn
=
getConnection
(
"testOptimizerHints"
);
Statement
s
=
conn
.
createStatement
();
s
.
execute
(
"create table t1(id int)"
);
s
.
execute
(
"create table t2(id int, ref_id int)"
);
s
.
execute
(
"insert into t1 values(1),(2),(3)"
);
s
.
execute
(
"insert into t2 values(1,2),(2,3),(3,4),(4,6),(5,1),(6,4)"
);
s
.
execute
(
"create unique index idx1_id on t1(id)"
);
s
.
execute
(
"create index idx2_id on t2(id)"
);
s
.
execute
(
"create index idx2_ref_id on t2(ref_id)"
);
enableJoinReordering
(
false
);
try
{
String
plan
;
plan
=
plan
(
s
,
"select * from t1, t2 where t1.id = t2.ref_id"
);
assertTrue
(
plan
,
plan
.
contains
(
"INNER JOIN PUBLIC.T2"
));
plan
=
plan
(
s
,
"select * from t2, t1 where t1.id = t2.ref_id"
);
assertTrue
(
plan
,
plan
.
contains
(
"INNER JOIN PUBLIC.T1"
));
plan
=
plan
(
s
,
"select * from t2, t1 where t1.id = 1"
);
assertTrue
(
plan
,
plan
.
contains
(
"INNER JOIN PUBLIC.T1"
));
plan
=
plan
(
s
,
"select * from t2, t1 where t1.id = t2.ref_id and t2.id = 1"
);
assertTrue
(
plan
,
plan
.
contains
(
"INNER JOIN PUBLIC.T1"
));
plan
=
plan
(
s
,
"select * from t1, t2 where t1.id = t2.ref_id and t2.id = 1"
);
assertTrue
(
plan
,
plan
.
contains
(
"INNER JOIN PUBLIC.T2"
));
}
finally
{
...
...
@@ -80,12 +80,12 @@ public class TestOptimizerHints extends TestBase {
hints
.
setJoinReorderEnabled
(
enable
);
OptimizerHints
.
set
(
hints
);
}
/**
* @param s Statement.
* @param query Query.
* @return Plan.
* @throws SQLException If failed.
* @throws SQLException If failed.
*/
private
String
plan
(
Statement
s
,
String
query
)
throws
SQLException
{
ResultSet
rs
=
s
.
executeQuery
(
"explain "
+
query
);
...
...
h2/src/test/org/h2/test/mvcc/TestMvcc4.java
浏览文件 @
b9283ea4
...
...
@@ -49,7 +49,8 @@ public class TestMvcc4 extends TestBase {
+
"entity_id VARCHAR(100) NOT NULL PRIMARY KEY, "
+
"lastUpdated TIMESTAMP NOT NULL)"
);
PreparedStatement
ps
=
setup
.
prepareStatement
(
"INSERT INTO test (entity_id, lastUpdated) VALUES (?, ?)"
);
PreparedStatement
ps
=
setup
.
prepareStatement
(
"INSERT INTO test (entity_id, lastUpdated) VALUES (?, ?)"
);
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
String
id
=
""
+
i
;
ps
.
setString
(
1
,
id
);
...
...
@@ -72,7 +73,8 @@ public class TestMvcc4 extends TestBase {
Connection
c2
=
getConnection
(
"mvcc4"
);
c2
.
setAutoCommit
(
false
);
PreparedStatement
ps
=
c2
.
prepareStatement
(
"SELECT * FROM test WHERE entity_id = ? FOR UPDATE"
);
PreparedStatement
ps
=
c2
.
prepareStatement
(
"SELECT * FROM test WHERE entity_id = ? FOR UPDATE"
);
ps
.
setString
(
1
,
"1"
);
ps
.
executeQuery
().
next
();
...
...
@@ -93,32 +95,32 @@ public class TestMvcc4 extends TestBase {
}
catch
(
InterruptedException
e
)
{
}
{
//Execute an update. This should initially fail, and enter the waiting for lock case.
PreparedStatement
ps
=
c1
.
prepareStatement
(
"UPDATE test SET lastUpdated = ?"
);
ps
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
ps
.
executeUpdate
();
}
// Execute an update. This should initially fail, and enter the waiting
// for lock case.
PreparedStatement
ps
=
c1
.
prepareStatement
(
"UPDATE test SET lastUpdated = ?"
);
ps
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
ps
.
executeUpdate
();
c1
.
commit
();
c1
.
close
();
Connection
verify
=
getConnection
(
"mvcc4"
);
{
verify
.
setAutoCommit
(
false
);
PreparedStatement
ps
=
verify
.
prepareStatement
(
"SELECT COUNT(*) FROM test"
);
ResultSet
rs
=
ps
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
getInt
(
1
)
==
2
);
verify
.
commit
();
verify
.
close
();
}
verify
.
setAutoCommit
(
false
);
ps
=
verify
.
prepareStatement
(
"SELECT COUNT(*) FROM test"
);
ResultSet
rs
=
ps
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
getInt
(
1
)
==
2
);
verify
.
commit
();
verify
.
close
();
setup
.
close
();
}
private
static
void
waitForThreadToBlockOnDB
(
Thread
t
)
{
while
(
true
)
{
// TODO must not use getAllStackTraces, as the method names are
// implementation details
Map
<
Thread
,
StackTraceElement
[]>
threadMap
=
Thread
.
getAllStackTraces
();
StackTraceElement
[]
elements
=
threadMap
.
get
(
t
);
if
(
elements
!=
null
...
...
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
b9283ea4
...
...
@@ -777,4 +777,4 @@ bradmesserle dan incorporated keegan industries tagtraum cyr israels rafel
dance schedule hitting reverted youngest footers inliner deadlocked reorder nger
nullid syspublic sysibmts sysibminternal syscat sysfun sysstat systools sysibmadm
sysproc jcc expecting gpg showed unreferenced activating cvf stephane lacoin
centrale umr ecole nantes sticc lab
centrale umr ecole nantes sticc lab
reordering preferable
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论