Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3ca9d063
提交
3ca9d063
authored
5月 26, 2017
作者:
Sergi Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TestQueryCache fixed
上级
782069ef
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
9 行删除
+22
-9
TestQueryCache.java
h2/src/test/org/h2/test/db/TestQueryCache.java
+22
-9
没有找到文件。
h2/src/test/org/h2/test/db/TestQueryCache.java
浏览文件 @
3ca9d063
...
@@ -38,30 +38,43 @@ public class TestQueryCache extends TestBase {
...
@@ -38,30 +38,43 @@ public class TestQueryCache extends TestBase {
private
void
test1
()
throws
Exception
{
private
void
test1
()
throws
Exception
{
Connection
conn
=
getConnection
(
"queryCache;QUERY_CACHE_SIZE=10"
);
Connection
conn
=
getConnection
(
"queryCache;QUERY_CACHE_SIZE=10"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, name varchar) "
+
stat
.
execute
(
"create table test(id int, name varchar)"
);
"as select x, space(100) from system_range(1, 1000)"
);
PreparedStatement
prep
;
PreparedStatement
prep
;
conn
.
prepareStatement
(
"select count(*) from test t1, test t2"
);
// query execution may be fast here but the parsing must be slow
StringBuilder
queryBuilder
=
new
StringBuilder
(
"select count(*) from test t1 where \n"
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
if
(
i
!=
0
)
{
queryBuilder
.
append
(
" and "
);
}
queryBuilder
.
append
(
" TIMESTAMP '2005-12-31 23:59:59' = TIMESTAMP '2005-12-31 23:59:59' "
);
}
String
query
=
queryBuilder
.
toString
();
conn
.
prepareStatement
(
query
);
long
time
;
long
time
;
ResultSet
rs
;
ResultSet
rs
;
long
first
=
0
;
long
first
=
0
;
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
// 1000 iterations to warm up and avoid JIT effects
for
(
int
i
=
0
;
i
<
1010
;
i
++)
{
// this should both ensure results are not re-used
// this should both ensure results are not re-used
// stat.execute("set mode regular");
// stat.execute("set mode regular");
// stat.execute("create table x()");
// stat.execute("create table x()");
// stat.execute("drop table x");
// stat.execute("drop table x");
time
=
System
.
nanoTime
();
time
=
System
.
nanoTime
();
prep
=
conn
.
prepareStatement
(
"select count(*) from test t1, test t2"
);
prep
=
conn
.
prepareStatement
(
query
);
execute
(
prep
);
execute
(
prep
);
rs
=
stat
.
executeQuery
(
"select count(*) from test t1, test t2"
);
prep
.
close
();
rs
=
stat
.
executeQuery
(
query
);
rs
.
next
();
rs
.
next
();
int
c
=
rs
.
getInt
(
1
);
int
c
=
rs
.
getInt
(
1
);
rs
.
close
();
rs
.
close
();
assertEquals
(
100000
0
,
c
);
assertEquals
(
0
,
c
);
time
=
System
.
nanoTime
()
-
time
;
time
=
System
.
nanoTime
()
-
time
;
if
(
first
==
0
)
{
if
(
i
==
1000
)
{
// take from cache and do not close, so that next iteration will have a cache miss
prep
=
conn
.
prepareStatement
(
query
);
}
else
if
(
i
==
1001
)
{
first
=
time
;
first
=
time
;
}
else
{
}
else
if
(
i
>
1001
)
{
assertSmaller
(
time
,
first
);
assertSmaller
(
time
,
first
);
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论