Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e3578c9e
提交
e3578c9e
authored
15 年前
作者:
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,12 +220,14 @@ public abstract class Query extends Prepared {
...
@@ -220,12 +220,14 @@ public abstract class Query extends Prepared {
}
}
Value
[]
params
=
getParameterValues
();
Value
[]
params
=
getParameterValues
();
long
now
=
session
.
getDatabase
().
getModificationDataId
();
long
now
=
session
.
getDatabase
().
getModificationDataId
();
if
(
lastResult
!=
null
&&
!
lastResult
.
isClosed
()
&&
limit
==
lastLimit
)
{
if
(
isEverything
(
ExpressionVisitor
.
DETERMINISTIC
))
{
if
(
sameResultAsLast
(
session
,
params
,
lastParameters
,
lastEvaluated
))
{
if
(
lastResult
!=
null
&&
!
lastResult
.
isClosed
()
&&
limit
==
lastLimit
)
{
lastResult
=
lastResult
.
createShallowCopy
(
session
);
if
(
sameResultAsLast
(
session
,
params
,
lastParameters
,
lastEvaluated
))
{
if
(
lastResult
!=
null
)
{
lastResult
=
lastResult
.
createShallowCopy
(
session
);
lastResult
.
reset
();
if
(
lastResult
!=
null
)
{
return
lastResult
;
lastResult
.
reset
();
return
lastResult
;
}
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
e3578c9e
...
@@ -1047,6 +1047,14 @@ public class Select extends Query {
...
@@ -1047,6 +1047,14 @@ public class Select extends Query {
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
public
boolean
isEverything
(
ExpressionVisitor
visitor
)
{
switch
(
visitor
.
getType
())
{
switch
(
visitor
.
getType
())
{
case
ExpressionVisitor
.
DETERMINISTIC
:
{
for
(
TableFilter
f
:
filters
)
{
if
(!
f
.
getTable
().
isDeterministic
())
{
return
false
;
}
}
break
;
}
case
ExpressionVisitor
.
SET_MAX_DATA_MODIFICATION_ID
:
{
case
ExpressionVisitor
.
SET_MAX_DATA_MODIFICATION_ID
:
{
for
(
TableFilter
f
:
filters
)
{
for
(
TableFilter
f
:
filters
)
{
long
m
=
f
.
getTable
().
getMaxDataModificationId
();
long
m
=
f
.
getTable
().
getMaxDataModificationId
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/FunctionTable.java
浏览文件 @
e3578c9e
...
@@ -192,4 +192,8 @@ public class FunctionTable extends Table {
...
@@ -192,4 +192,8 @@ public class FunctionTable extends Table {
return
rowCount
;
return
rowCount
;
}
}
public
boolean
isDeterministic
()
{
return
function
.
isDeterministic
();
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
e3578c9e
...
@@ -1746,4 +1746,8 @@ public class MetaTable extends Table {
...
@@ -1746,4 +1746,8 @@ public class MetaTable extends Table {
return
ROW_COUNT_APPROXIMATION
;
return
ROW_COUNT_APPROXIMATION
;
}
}
public
boolean
isDeterministic
()
{
return
true
;
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/RangeTable.java
浏览文件 @
e3578c9e
...
@@ -168,4 +168,8 @@ public class RangeTable extends Table {
...
@@ -168,4 +168,8 @@ public class RangeTable extends Table {
return
100
;
return
100
;
}
}
public
boolean
isDeterministic
()
{
return
true
;
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/Table.java
浏览文件 @
e3578c9e
...
@@ -231,6 +231,13 @@ public abstract class Table extends SchemaObjectBase {
...
@@ -231,6 +231,13 @@ public abstract class Table extends SchemaObjectBase {
*/
*/
public
abstract
long
getMaxDataModificationId
();
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.
* Check if the row count can be retrieved quickly.
*
*
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableData.java
浏览文件 @
e3578c9e
...
@@ -712,4 +712,8 @@ public class TableData extends Table implements RecordReader {
...
@@ -712,4 +712,8 @@ public class TableData extends Table implements RecordReader {
this
.
compareMode
=
compareMode
;
this
.
compareMode
=
compareMode
;
}
}
public
boolean
isDeterministic
()
{
return
true
;
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableLink.java
浏览文件 @
e3578c9e
...
@@ -14,7 +14,6 @@ import java.sql.SQLException;
...
@@ -14,7 +14,6 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.sql.Types
;
import
java.sql.Types
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
org.h2.command.Prepared
;
import
org.h2.command.Prepared
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
...
@@ -535,4 +534,8 @@ public class TableLink extends Table {
...
@@ -535,4 +534,8 @@ public class TableLink extends Table {
prepared
.
put
(
sql
,
prep
);
prepared
.
put
(
sql
,
prep
);
}
}
public
boolean
isDeterministic
()
{
return
false
;
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableView.java
浏览文件 @
e3578c9e
...
@@ -14,6 +14,7 @@ import org.h2.engine.Constants;
...
@@ -14,6 +14,7 @@ import org.h2.engine.Constants;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
import
org.h2.engine.User
;
import
org.h2.engine.User
;
import
org.h2.expression.Expression
;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionVisitor
;
import
org.h2.expression.Parameter
;
import
org.h2.expression.Parameter
;
import
org.h2.index.Index
;
import
org.h2.index.Index
;
import
org.h2.index.IndexType
;
import
org.h2.index.IndexType
;
...
@@ -359,4 +360,8 @@ public class TableView extends Table {
...
@@ -359,4 +360,8 @@ public class TableView extends Table {
return
topQuery
==
null
?
0
:
topQuery
.
getParameters
().
size
();
return
topQuery
==
null
?
0
:
topQuery
.
getParameters
().
size
();
}
}
public
boolean
isDeterministic
()
{
return
viewQuery
.
isEverything
(
ExpressionVisitor
.
DETERMINISTIC
);
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestView.java
浏览文件 @
e3578c9e
...
@@ -11,7 +11,6 @@ import java.sql.PreparedStatement;
...
@@ -11,7 +11,6 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
/**
/**
...
@@ -19,6 +18,8 @@ import org.h2.test.TestBase;
...
@@ -19,6 +18,8 @@ import org.h2.test.TestBase;
*/
*/
public
class
TestView
extends
TestBase
{
public
class
TestView
extends
TestBase
{
private
static
int
x
;
/**
/**
* Run just this test.
* Run just this test.
*
*
...
@@ -29,12 +30,61 @@ public class TestView extends TestBase {
...
@@ -29,12 +30,61 @@ public class TestView extends TestBase {
}
}
public
void
test
()
throws
SQLException
{
public
void
test
()
throws
SQLException
{
testCache
();
testCacheFunction
(
true
);
testCacheFunction
(
false
);
testInSelect
();
testInSelect
();
testUnionReconnect
();
testUnionReconnect
();
testManyViews
();
testManyViews
();
deleteDb
(
"view"
);
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
{
private
void
testInSelect
()
throws
SQLException
{
deleteDb
(
"view"
);
deleteDb
(
"view"
);
Connection
conn
=
getConnection
(
"view"
);
Connection
conn
=
getConnection
(
"view"
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论