Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e3578c9e
提交
e3578c9e
authored
8月 04, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Views using functions were not re-evaluated when necessary.
上级
13ff8d02
显示空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
99 行增加
和
8 行删除
+99
-8
Query.java
h2/src/main/org/h2/command/dml/Query.java
+8
-6
Select.java
h2/src/main/org/h2/command/dml/Select.java
+8
-0
FunctionTable.java
h2/src/main/org/h2/table/FunctionTable.java
+4
-0
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+4
-0
RangeTable.java
h2/src/main/org/h2/table/RangeTable.java
+4
-0
Table.java
h2/src/main/org/h2/table/Table.java
+7
-0
TableData.java
h2/src/main/org/h2/table/TableData.java
+4
-0
TableLink.java
h2/src/main/org/h2/table/TableLink.java
+4
-1
TableView.java
h2/src/main/org/h2/table/TableView.java
+5
-0
TestView.java
h2/src/test/org/h2/test/db/TestView.java
+51
-1
没有找到文件。
h2/src/main/org/h2/command/dml/Query.java
浏览文件 @
e3578c9e
...
...
@@ -220,6 +220,7 @@ public abstract class Query extends Prepared {
}
Value
[]
params
=
getParameterValues
();
long
now
=
session
.
getDatabase
().
getModificationDataId
();
if
(
isEverything
(
ExpressionVisitor
.
DETERMINISTIC
))
{
if
(
lastResult
!=
null
&&
!
lastResult
.
isClosed
()
&&
limit
==
lastLimit
)
{
if
(
sameResultAsLast
(
session
,
params
,
lastParameters
,
lastEvaluated
))
{
lastResult
=
lastResult
.
createShallowCopy
(
session
);
...
...
@@ -229,6 +230,7 @@ public abstract class Query extends Prepared {
}
}
}
}
lastParameters
=
params
;
closeLastResult
();
lastResult
=
queryWithoutCache
(
limit
);
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
e3578c9e
...
...
@@ -1047,6 +1047,14 @@ public class Select extends Query {
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
switch
(
visitor
.
getType
())
{
case
ExpressionVisitor
.
DETERMINISTIC
:
{
for
(
TableFilter
f
:
filters
)
{
if
(!
f
.
getTable
().
isDeterministic
())
{
return
false
;
}
}
break
;
}
case
ExpressionVisitor
.
SET_MAX_DATA_MODIFICATION_ID
:
{
for
(
TableFilter
f
:
filters
)
{
long
m
=
f
.
getTable
().
getMaxDataModificationId
();
...
...
h2/src/main/org/h2/table/FunctionTable.java
浏览文件 @
e3578c9e
...
...
@@ -192,4 +192,8 @@ public class FunctionTable extends Table {
return
rowCount
;
}
public
boolean
isDeterministic
()
{
return
function
.
isDeterministic
();
}
}
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
e3578c9e
...
...
@@ -1746,4 +1746,8 @@ public class MetaTable extends Table {
return
ROW_COUNT_APPROXIMATION
;
}
public
boolean
isDeterministic
()
{
return
true
;
}
}
h2/src/main/org/h2/table/RangeTable.java
浏览文件 @
e3578c9e
...
...
@@ -168,4 +168,8 @@ public class RangeTable extends Table {
return
100
;
}
public
boolean
isDeterministic
()
{
return
true
;
}
}
h2/src/main/org/h2/table/Table.java
浏览文件 @
e3578c9e
...
...
@@ -231,6 +231,13 @@ public abstract class Table extends SchemaObjectBase {
*/
public
abstract
long
getMaxDataModificationId
();
/**
* Check if the table is deterministic.
*
* @return true if it is
*/
public
abstract
boolean
isDeterministic
();
/**
* Check if the row count can be retrieved quickly.
*
...
...
h2/src/main/org/h2/table/TableData.java
浏览文件 @
e3578c9e
...
...
@@ -712,4 +712,8 @@ public class TableData extends Table implements RecordReader {
this
.
compareMode
=
compareMode
;
}
public
boolean
isDeterministic
()
{
return
true
;
}
}
h2/src/main/org/h2/table/TableLink.java
浏览文件 @
e3578c9e
...
...
@@ -14,7 +14,6 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.sql.Types
;
import
java.util.HashMap
;
import
org.h2.command.Prepared
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Session
;
...
...
@@ -535,4 +534,8 @@ public class TableLink extends Table {
prepared
.
put
(
sql
,
prep
);
}
public
boolean
isDeterministic
()
{
return
false
;
}
}
h2/src/main/org/h2/table/TableView.java
浏览文件 @
e3578c9e
...
...
@@ -14,6 +14,7 @@ import org.h2.engine.Constants;
import
org.h2.engine.Session
;
import
org.h2.engine.User
;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionVisitor
;
import
org.h2.expression.Parameter
;
import
org.h2.index.Index
;
import
org.h2.index.IndexType
;
...
...
@@ -359,4 +360,8 @@ public class TableView extends Table {
return
topQuery
==
null
?
0
:
topQuery
.
getParameters
().
size
();
}
public
boolean
isDeterministic
()
{
return
viewQuery
.
isEverything
(
ExpressionVisitor
.
DETERMINISTIC
);
}
}
h2/src/test/org/h2/test/db/TestView.java
浏览文件 @
e3578c9e
...
...
@@ -11,7 +11,6 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -19,6 +18,8 @@ import org.h2.test.TestBase;
*/
public
class
TestView
extends
TestBase
{
private
static
int
x
;
/**
* Run just this test.
*
...
...
@@ -29,12 +30,61 @@ public class TestView extends TestBase {
}
public
void
test
()
throws
SQLException
{
testCache
();
testCacheFunction
(
true
);
testCacheFunction
(
false
);
testInSelect
();
testUnionReconnect
();
testManyViews
();
deleteDb
(
"view"
);
}
private
void
testCacheFunction
(
boolean
deterministic
)
throws
SQLException
{
deleteDb
(
"view"
);
Connection
conn
=
getConnection
(
"view"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE ALIAS GET_X "
+
(
deterministic
?
"DETERMINISTIC"
:
""
)
+
" FOR \""
+
getClass
().
getName
()
+
".getX\""
);
stat
.
execute
(
"CREATE VIEW V AS SELECT * FROM (SELECT GET_X())"
);
ResultSet
rs
;
x
=
8
;
rs
=
stat
.
executeQuery
(
"SELECT * FROM V"
);
rs
.
next
();
assertEquals
(
8
,
rs
.
getInt
(
1
));
x
=
5
;
rs
=
stat
.
executeQuery
(
"SELECT * FROM V"
);
rs
.
next
();
assertEquals
(
deterministic
?
8
:
5
,
rs
.
getInt
(
1
));
conn
.
close
();
}
/**
* This method is called via reflection from the database.
*
* @return the static value x
*/
public
static
int
getX
()
{
return
x
;
}
private
void
testCache
()
throws
SQLException
{
deleteDb
(
"view"
);
Connection
conn
=
getConnection
(
"view"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET @X 8"
);
stat
.
execute
(
"CREATE VIEW V AS SELECT * FROM (SELECT @X)"
);
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"SELECT * FROM V"
);
rs
.
next
();
assertEquals
(
8
,
rs
.
getInt
(
1
));
stat
.
execute
(
"SET @X 5"
);
rs
=
stat
.
executeQuery
(
"SELECT * FROM V"
);
rs
.
next
();
assertEquals
(
5
,
rs
.
getInt
(
1
));
conn
.
close
();
}
private
void
testInSelect
()
throws
SQLException
{
deleteDb
(
"view"
);
Connection
conn
=
getConnection
(
"view"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论