Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ce1d452a
提交
ce1d452a
authored
6 年前
作者:
tledkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#1057, #1072 set neverLazy for subquery in nested joins
上级
f03f4781
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
26 行增加
和
10 行删除
+26
-10
Select.java
h2/src/main/org/h2/command/dml/Select.java
+1
-1
TestSubqueryPerformanceOnLazyExecutionMode.java
...test/unit/TestSubqueryPerformanceOnLazyExecutionMode.java
+25
-9
没有找到文件。
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
ce1d452a
...
@@ -870,7 +870,7 @@ public class Select extends Query {
...
@@ -870,7 +870,7 @@ public class Select extends Query {
}
}
private
void
disableLazyForJoinSubqueries
(
TableFilter
f
)
{
private
void
disableLazyForJoinSubqueries
(
TableFilter
f
)
{
for
(;
f
!=
null
;
f
=
f
.
getJoin
())
{
for
(;
f
!=
null
;
f
=
f
.
getJoin
()
!=
null
?
f
.
getJoin
()
:
f
.
getNestedJoin
()
)
{
if
(
f
.
getTable
().
getTableType
()
==
TableType
.
VIEW
)
{
if
(
f
.
getTable
().
getTableType
()
==
TableType
.
VIEW
)
{
ViewIndex
idx
=
(
ViewIndex
)
f
.
getIndex
();
ViewIndex
idx
=
(
ViewIndex
)
f
.
getIndex
();
if
(
idx
!=
null
&&
idx
.
getQuery
()
!=
null
)
{
if
(
idx
!=
null
&&
idx
.
getQuery
()
!=
null
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestSubqueryPerformanceOnLazyExecutionMode.java
浏览文件 @
ce1d452a
...
@@ -51,6 +51,7 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
...
@@ -51,6 +51,7 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
testSubqueryInJoin
(
stmt
);
testSubqueryInJoin
(
stmt
);
testSubqueryInJoinFirst
(
stmt
);
testSubqueryInJoinFirst
(
stmt
);
testJoinTwoSubqueries
(
stmt
);
testJoinTwoSubqueries
(
stmt
);
testSubqueryInNestedJoin
(
stmt
);
}
}
}
}
finally
{
finally
{
...
@@ -75,8 +76,8 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
...
@@ -75,8 +76,8 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
private
void
testSubqueryInJoinFirst
(
Statement
stmt
)
throws
Exception
{
private
void
testSubqueryInJoinFirst
(
Statement
stmt
)
throws
Exception
{
String
sql
=
String
sql
=
"SELECT COUNT (one.x) FROM "
+
"SELECT COUNT (one.x) FROM "
+
"(SELECT y AS val FROM one WHERE y < 50) AS subq "
+
"(SELECT y AS val FROM one WHERE y < 50) AS subq "
+
"JOIN one ON subq.val=one.x"
;
"JOIN one ON subq.val=one.x"
;
checkExecutionTime
(
stmt
,
sql
);
checkExecutionTime
(
stmt
,
sql
);
}
}
...
@@ -84,17 +85,32 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
...
@@ -84,17 +85,32 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
private
void
testJoinTwoSubqueries
(
Statement
stmt
)
throws
Exception
{
private
void
testJoinTwoSubqueries
(
Statement
stmt
)
throws
Exception
{
String
sql
=
String
sql
=
"SELECT COUNT (one_sub.x) FROM "
+
"SELECT COUNT (one_sub.x) FROM "
+
"(SELECT y AS val FROM one WHERE y < 50) AS subq "
+
"(SELECT y AS val FROM one WHERE y < 50) AS subq "
+
"JOIN (SELECT x FROM one) AS one_sub ON subq.val=one_sub.x"
;
"JOIN (SELECT x FROM one) AS one_sub ON subq.val=one_sub.x"
;
checkExecutionTime
(
stmt
,
sql
);
checkExecutionTime
(
stmt
,
sql
);
}
}
private
void
testSubqueryInNestedJoin
(
Statement
stmt
)
throws
Exception
{
String
sql
=
"SELECT COUNT (one.x) FROM one "
+
"LEFT JOIN (SELECT 1 AS val_1) AS subq0 "
+
"JOIN (SELECT y AS val FROM one WHERE y < 30) AS subq1 ON subq0.val_1 < subq1.val "
+
"ON one.x = subq1.val "
+
"WHERE one.x < 30"
;
checkExecutionTime
(
stmt
,
sql
,
3000
);
}
private
void
checkExecutionTime
(
Statement
stmt
,
String
sql
)
throws
Exception
{
checkExecutionTime
(
stmt
,
sql
,
ROWS
);
}
/**
/**
* Compare execution time when lazy execution mode is disabled and enabled.
* Compare execution time when lazy execution mode is disabled and enabled.
* The execution time must be almost the same.
* The execution time must be almost the same.
*/
*/
private
void
checkExecutionTime
(
Statement
stmt
,
String
sql
)
throws
Exception
{
private
void
checkExecutionTime
(
Statement
stmt
,
String
sql
,
int
expected
)
throws
Exception
{
long
totalNotLazy
=
0
;
long
totalNotLazy
=
0
;
long
totalLazy
=
0
;
long
totalLazy
=
0
;
...
@@ -102,8 +118,8 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
...
@@ -102,8 +118,8 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
int
failCnt
=
0
;
int
failCnt
=
0
;
for
(
int
i
=
0
;
i
<
FAIL_REPEATS
;
++
i
)
{
for
(
int
i
=
0
;
i
<
FAIL_REPEATS
;
++
i
)
{
long
t
NotLazy
=
executeAndCheckResult
(
stmt
,
sql
,
false
);
long
t
Lazy
=
executeAndCheckResult
(
stmt
,
sql
,
true
,
expected
);
long
t
Lazy
=
executeAndCheckResult
(
stmt
,
sql
,
true
);
long
t
NotLazy
=
executeAndCheckResult
(
stmt
,
sql
,
false
,
expected
);
totalNotLazy
+=
tNotLazy
;
totalNotLazy
+=
tNotLazy
;
totalLazy
+=
tLazy
;
totalLazy
+=
tLazy
;
...
@@ -127,7 +143,7 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
...
@@ -127,7 +143,7 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
/**
/**
* @return Time of the query execution.
* @return Time of the query execution.
*/
*/
private
long
executeAndCheckResult
(
Statement
stmt
,
String
sql
,
boolean
lazy
)
throws
SQLException
{
private
long
executeAndCheckResult
(
Statement
stmt
,
String
sql
,
boolean
lazy
,
int
expected
)
throws
SQLException
{
if
(
lazy
)
{
if
(
lazy
)
{
stmt
.
execute
(
"SET LAZY_QUERY_EXECUTION 1"
);
stmt
.
execute
(
"SET LAZY_QUERY_EXECUTION 1"
);
}
}
...
@@ -138,7 +154,7 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
...
@@ -138,7 +154,7 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
long
t0
=
System
.
currentTimeMillis
();
long
t0
=
System
.
currentTimeMillis
();
try
(
ResultSet
rs
=
stmt
.
executeQuery
(
sql
))
{
try
(
ResultSet
rs
=
stmt
.
executeQuery
(
sql
))
{
rs
.
next
();
rs
.
next
();
assertEquals
(
ROWS
,
rs
.
getInt
(
1
));
assertEquals
(
expected
,
rs
.
getInt
(
1
));
}
}
return
System
.
currentTimeMillis
()
-
t0
;
return
System
.
currentTimeMillis
()
-
t0
;
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论