Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
0d91aa36
提交
0d91aa36
authored
11月 17, 2015
作者:
S.Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sub-query cache is getting dropped in Session.prepareLocal now + more tests.
上级
48942c18
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
54 行增加
和
5 行删除
+54
-5
Session.java
h2/src/main/org/h2/engine/Session.java
+4
-3
TestView.java
h2/src/test/org/h2/test/db/TestView.java
+50
-2
没有找到文件。
h2/src/main/org/h2/engine/Session.java
浏览文件 @
0d91aa36
...
...
@@ -483,6 +483,8 @@ public class Session extends SessionWithState {
}
Parser
parser
=
new
Parser
(
this
);
command
=
parser
.
prepareCommand
(
sql
);
// we can't reuse view indexes from sub-queries, so just drop the cache
subQueryIndexCache
=
null
;
if
(
queryCache
!=
null
)
{
if
(
command
.
isCacheable
())
{
queryCache
.
put
(
sql
,
command
);
...
...
@@ -1319,8 +1321,8 @@ public class Session extends SessionWithState {
public
Map
<
Object
,
ViewIndex
>
getViewIndexCache
(
boolean
subQuery
)
{
if
(
subQuery
)
{
// for sub-queries we don't need to use LRU because
it should not grow too large
//
for a single query and by the end of the statement we will drop the whole cache
// for sub-queries we don't need to use LRU because
the cache should not
//
grow too large for a single query (we drop the whole cache in the end of prepareLocal)
if
(
subQueryIndexCache
==
null
)
{
subQueryIndexCache
=
New
.
hashMap
();
}
...
...
@@ -1510,7 +1512,6 @@ public class Session extends SessionWithState {
*/
public
void
endStatement
()
{
startStatement
=
-
1
;
subQueryIndexCache
=
null
;
closeTemporaryResults
();
}
...
...
h2/src/test/org/h2/test/db/TestView.java
浏览文件 @
0d91aa36
...
...
@@ -10,8 +10,9 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Session
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -33,7 +34,7 @@ public class TestView extends TestBase {
@Override
public
void
test
()
throws
SQLException
{
deleteDb
(
"view"
);
testSubQueryViewIndexCache
();
testInnerSelectWithRownum
();
testInnerSelectWithRange
();
testEmptyColumn
();
...
...
@@ -51,6 +52,53 @@ public class TestView extends TestBase {
deleteDb
(
"view"
);
}
public
void
testSubQueryViewIndexCache
()
throws
SQLException
{
if
(
config
.
networked
)
{
return
;
}
Connection
conn
=
getConnection
(
"view"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"drop table test if exists"
);
stat
.
execute
(
"create table test(id int primary key, name varchar(25) unique, age int unique)"
);
// check that initial cache size is empty
Session
s
=
(
Session
)
((
JdbcConnection
)
conn
).
getSession
();
s
.
clearViewIndexCache
();
assertTrue
(
s
.
getViewIndexCache
(
true
).
isEmpty
());
assertTrue
(
s
.
getViewIndexCache
(
false
).
isEmpty
());
// create view command should not affect caches
stat
.
execute
(
"create view v as select * from test"
);
assertTrue
(
s
.
getViewIndexCache
(
true
).
isEmpty
());
assertTrue
(
s
.
getViewIndexCache
(
false
).
isEmpty
());
// check view index cache
stat
.
executeQuery
(
"select * from v where id > 0"
).
next
();
int
size1
=
s
.
getViewIndexCache
(
false
).
size
();
assertTrue
(
size1
>
0
);
assertTrue
(
s
.
getViewIndexCache
(
true
).
isEmpty
());
stat
.
executeQuery
(
"select * from v where name = 'xyz'"
).
next
();
int
size2
=
s
.
getViewIndexCache
(
false
).
size
();
assertTrue
(
size2
>
size1
);
assertTrue
(
s
.
getViewIndexCache
(
true
).
isEmpty
());
// check we did not add anything to view cache if we run a sub-query
stat
.
executeQuery
(
"select * from (select * from test) where age = 17"
).
next
();
int
size3
=
s
.
getViewIndexCache
(
false
).
size
();
assertEquals
(
size2
,
size3
);
assertTrue
(
s
.
getViewIndexCache
(
true
).
isEmpty
());
// check clear works
s
.
clearViewIndexCache
();
assertTrue
(
s
.
getViewIndexCache
(
false
).
isEmpty
());
assertTrue
(
s
.
getViewIndexCache
(
true
).
isEmpty
());
// drop everything
stat
.
execute
(
"drop view v"
);
stat
.
execute
(
"drop table test"
);
conn
.
close
();
}
private
void
testInnerSelectWithRownum
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"view"
);
Statement
stat
=
conn
.
createStatement
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论