Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7dff79ad
提交
7dff79ad
authored
7月 08, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New experimental query cache.
上级
12048e0f
隐藏空白字符变更
内嵌
并排
正在显示
15 个修改的文件
包含
155 行增加
和
21 行删除
+155
-21
changelog.html
h2/src/docsrc/html/changelog.html
+12
-1
roadmap.html
h2/src/docsrc/html/roadmap.html
+0
-1
Command.java
h2/src/main/org/h2/command/Command.java
+5
-0
CommandContainer.java
h2/src/main/org/h2/command/CommandContainer.java
+5
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+8
-13
Prepared.java
h2/src/main/org/h2/command/Prepared.java
+4
-0
Query.java
h2/src/main/org/h2/command/dml/Query.java
+10
-2
Select.java
h2/src/main/org/h2/command/dml/Select.java
+5
-0
Set.java
h2/src/main/org/h2/command/dml/Set.java
+3
-0
SysProperties.java
h2/src/main/org/h2/constant/SysProperties.java
+10
-0
Session.java
h2/src/main/org/h2/engine/Session.java
+21
-1
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+8
-0
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+4
-1
TestQueryCache.java
h2/src/test/org/h2/test/db/TestQueryCache.java
+59
-0
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
7dff79ad
...
...
@@ -18,7 +18,15 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
Conditions with many OR operations could throw an UnsupportedOperationException if
<ul><li>
New experimental query cache.
The cache is only used if the SQL statement and all parameters match.
Each session has it's own cache with the given size.
Only the last returned result per query is cached.
Only SELECT statements are cached (excluding UNION and FOR UPDATE statements).
This works for both statements and prepared statement.
To enable, set the system property h2.commandCacheSize to a value larger than 0.
There is currently no plan to enable this option by default in future versions.
</li><li>
Conditions with many OR operations could throw an UnsupportedOperationException if
h2.optimizeOr was enabled.
</li><li>
XA connection: after transaction commit or rollback,
the physical connection is set into autocommit mode.
...
...
@@ -32,6 +40,9 @@ Change Log
The API was unified a bit.
</li><li>
ODBC: MS Access could not link to a table with unique index or primary key.
To solve this problem, index meta data is currently disabled for ODBC.
When using the new H2 version to access a database over ODBC, the PostgreSQL catalog
is automatically upgraded. Using a database with an upgraded PostgreSQL catalog
with an older version of H2 is still possible, but not over ODBC.
</li><li>
ODBC: MS Access could not link to a table with a name containing '_'.
</li><li>
ODBC: additional connection settings can now be added to the database name.
Example: ~/test;cipher=xtea. Therefore, encrypted databases are supported.
...
...
h2/src/docsrc/html/roadmap.html
浏览文件 @
7dff79ad
...
...
@@ -43,7 +43,6 @@ See also <a href="build.html#providing_patches">Providing Patches</a>.
<h2>
Priority 1
</h2>
<ul><li>
Bugfixes
</li><li>
More tests with MULTI_THREADED=1
</li><li>
Optimization: result set caching (like MySQL); option to disable
</li><li>
Server side cursors
</li></ul>
...
...
h2/src/main/org/h2/command/Command.java
浏览文件 @
7dff79ad
...
...
@@ -261,4 +261,9 @@ public abstract class Command implements CommandInterface {
public
String
toString
()
{
return
TraceObject
.
toString
(
sql
,
getParameters
());
}
public
boolean
isCacheable
()
{
return
false
;
}
}
h2/src/main/org/h2/command/CommandContainer.java
浏览文件 @
7dff79ad
...
...
@@ -45,7 +45,7 @@ public class CommandContainer extends Command {
String
sql
=
prepared
.
getSQL
();
ArrayList
<
Parameter
>
oldParams
=
prepared
.
getParameters
();
Parser
parser
=
new
Parser
(
session
);
prepared
=
parser
.
parse
Only
(
sql
);
prepared
=
parser
.
parse
(
sql
);
long
mod
=
prepared
.
getModificationMetaId
();
prepared
.
setModificationMetaId
(
0
);
ArrayList
<
Parameter
>
newParams
=
prepared
.
getParameters
();
...
...
@@ -90,4 +90,8 @@ public class CommandContainer extends Command {
return
prepared
.
queryMeta
();
}
public
boolean
isCacheable
()
{
return
prepared
.
isCacheable
();
}
}
h2/src/main/org/h2/command/Parser.java
浏览文件 @
7dff79ad
...
...
@@ -204,16 +204,6 @@ public class Parser {
return
p
;
}
/**
* Parse the statement, but don't prepare it for execution.
*
* @param sql the SQL statement to parse
* @return the prepared object
*/
public
Prepared
parseOnly
(
String
sql
)
{
return
parse
(
sql
);
}
/**
* Parse a statement or a list of statements, and prepare it for execution.
*
...
...
@@ -222,8 +212,7 @@ public class Parser {
*/
public
Command
prepareCommand
(
String
sql
)
{
try
{
Prepared
p
=
parse
(
sql
);
p
.
prepare
();
Prepared
p
=
prepare
(
sql
);
Command
c
=
new
CommandContainer
(
this
,
sql
,
p
);
p
.
setCommand
(
c
);
if
(
isToken
(
";"
))
{
...
...
@@ -246,7 +235,13 @@ public class Parser {
}
}
private
Prepared
parse
(
String
sql
)
{
/**
* Parse the statement, but don't prepare it for execution.
*
* @param sql the SQL statement to parse
* @return the prepared object
*/
Prepared
parse
(
String
sql
)
{
Prepared
p
;
try
{
// first, try the fast variant
...
...
h2/src/main/org/h2/command/Prepared.java
浏览文件 @
7dff79ad
...
...
@@ -410,4 +410,8 @@ public abstract class Prepared {
return
e
.
addSQL
(
buff
.
toString
());
}
public
boolean
isCacheable
()
{
return
false
;
}
}
h2/src/main/org/h2/command/dml/Query.java
浏览文件 @
7dff79ad
...
...
@@ -55,6 +55,7 @@ public abstract class Query extends Prepared {
private
long
lastEvaluated
;
private
LocalResult
lastResult
;
private
Value
[]
lastParameters
;
private
boolean
cacheableChecked
,
cacheable
;
public
Query
(
Session
session
)
{
super
(
session
);
...
...
@@ -180,8 +181,15 @@ public abstract class Query extends Prepared {
return
true
;
}
private
boolean
sameResultAsLast
(
Session
s
,
Value
[]
params
,
Value
[]
lastParams
,
long
lastEval
)
{
private
boolean
sameResultAsLast
(
Session
s
,
Value
[]
params
,
Value
[]
lastParams
,
long
lastEval
)
{
if
(!
cacheableChecked
)
{
long
max
=
getMaxDataModificationId
();
cacheable
=
max
!=
Long
.
MAX_VALUE
;
cacheableChecked
=
true
;
}
if
(!
cacheable
)
{
return
false
;
}
Database
db
=
s
.
getDatabase
();
for
(
int
i
=
0
;
i
<
params
.
length
;
i
++)
{
if
(!
db
.
areEqual
(
lastParams
[
i
],
params
[
i
]))
{
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
7dff79ad
...
...
@@ -1167,4 +1167,9 @@ public class Select extends Query {
return
isEverything
(
ExpressionVisitor
.
READONLY
);
}
public
boolean
isCacheable
()
{
return
!
isForUpdate
;
}
}
h2/src/main/org/h2/command/dml/Set.java
浏览文件 @
7dff79ad
...
...
@@ -350,6 +350,9 @@ public class Set extends Prepared {
}
// the meta data information has changed
database
.
getNextModificationDataId
();
// query caches might be affected as well, for example
// when changing the compatibility mode
database
.
getNextModificationMetaId
();
return
0
;
}
...
...
h2/src/main/org/h2/constant/SysProperties.java
浏览文件 @
7dff79ad
...
...
@@ -180,6 +180,16 @@ public class SysProperties {
*/
public
static
final
String
CLIENT_TRACE_DIRECTORY
=
getStringSetting
(
"h2.clientTraceDirectory"
,
"trace.db/"
);
/**
* System property <code>h2.commandCacheSize</code> (default: 0).<br />
* The size of the query cache. Each session has it's own cache with the
* given size. The cache is only used if the SQL statement and all
* parameters match. Only the last returned result per query is cached. Only
* SELECT statements are cached (excluding UNION and FOR UPDATE statements).
* This works for both statements and prepared statement.
*/
public
static
final
int
QUERY_CACHE_SIZE
=
getIntSetting
(
"h2.queryCacheSize"
,
0
);
/**
* System property <code>h2.consoleStream</code> (default: true).<br />
* H2 Console: stream query results.
...
...
h2/src/main/org/h2/engine/Session.java
浏览文件 @
7dff79ad
...
...
@@ -31,6 +31,7 @@ import org.h2.store.InDoubtTransaction;
import
org.h2.store.LobStorage
;
import
org.h2.table.Table
;
import
org.h2.util.New
;
import
org.h2.util.SmallLRUCache
;
import
org.h2.value.Value
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueNull
;
...
...
@@ -100,6 +101,8 @@ public class Session extends SessionWithState implements SessionFactory {
private
int
modificationId
;
private
int
modificationIdState
;
private
int
objectId
;
private
int
queryCacheSize
=
SysProperties
.
QUERY_CACHE_SIZE
;
private
SmallLRUCache
<
String
,
Command
>
queryCache
;
public
Session
()
{
// to create a new session using the factory
...
...
@@ -416,8 +419,25 @@ public class Session extends SessionWithState implements SessionFactory {
if
(
closed
)
{
throw
DbException
.
get
(
ErrorCode
.
CONNECTION_BROKEN_1
,
"session closed"
);
}
Command
command
;
if
(
queryCacheSize
>
0
)
{
if
(
queryCache
==
null
)
{
queryCache
=
SmallLRUCache
.
newInstance
(
queryCacheSize
);
}
else
{
command
=
queryCache
.
get
(
sql
);
if
(
command
!=
null
)
{
return
command
;
}
}
}
Parser
parser
=
new
Parser
(
this
);
return
parser
.
prepareCommand
(
sql
);
command
=
parser
.
prepareCommand
(
sql
);
if
(
queryCache
!=
null
)
{
if
(
command
.
isCacheable
())
{
queryCache
.
put
(
sql
,
command
);
}
}
return
command
;
}
public
Database
getDatabase
()
{
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
7dff79ad
...
...
@@ -1747,6 +1747,14 @@ public class MetaTable extends Table {
}
public
long
getMaxDataModificationId
()
{
switch
(
type
)
{
case
SETTINGS:
case
IN_DOUBT:
case
SESSIONS:
case
LOCKS:
case
SESSION_STATE:
return
Long
.
MAX_VALUE
;
}
return
database
.
getModificationDataId
();
}
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
7dff79ad
...
...
@@ -44,6 +44,7 @@ import org.h2.test.db.TestOpenClose;
import
org.h2.test.db.TestOptimizations
;
import
org.h2.test.db.TestOutOfMemory
;
import
org.h2.test.db.TestPowerOff
;
import
org.h2.test.db.TestQueryCache
;
import
org.h2.test.db.TestReadOnly
;
import
org.h2.test.db.TestRights
;
import
org.h2.test.db.TestRunscript
;
...
...
@@ -308,7 +309,8 @@ java org.h2.test.TestAll timer
// System.setProperty("h2.analyzeAuto", "100");
// System.setProperty("h2.nestedJoins", "true");
// System.setProperty("h2.optimizeOr", "true");
// System.setProperty("h2.dropRestrict", "true");
// System.setProperty("h2.queryCacheSize", "100");
// System.setProperty("h2.dropRestrict", "true");
int
speedup
;
// System.setProperty("h2.syncMethod", "");
...
...
@@ -529,6 +531,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new
TestOptimizations
().
runTest
(
this
);
new
TestOutOfMemory
().
runTest
(
this
);
new
TestPowerOff
().
runTest
(
this
);
new
TestQueryCache
().
runTest
(
this
);
new
TestReadOnly
().
runTest
(
this
);
new
TestRights
().
runTest
(
this
);
new
TestRunscript
().
runTest
(
this
);
...
...
h2/src/test/org/h2/test/db/TestQueryCache.java
0 → 100644
浏览文件 @
7dff79ad
package
org
.
h2
.
test
.
db
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
org.h2.test.TestBase
;
/**
* Tests the query cache.
*/
public
class
TestQueryCache
extends
TestBase
{
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
System
.
setProperty
(
"h2.queryCacheSize"
,
"10"
);
TestBase
.
createCaller
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
if
(
Integer
.
parseInt
(
System
.
getProperty
(
"h2.queryCacheSize"
))
<=
0
)
{
return
;
}
deleteDb
(
"queryCache"
);
Connection
conn
=
getConnection
(
"queryCache"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int, name varchar) as select x, space(100) from system_range(1, 1000)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"select count(*) from test t1, test t2"
);
long
time
;
ResultSet
rs
;
long
first
=
0
;
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
// this should both ensure results are not re-used
// stat.execute("set mode regular");
// stat.execute("create table x()");
// stat.execute("drop table x");
time
=
System
.
currentTimeMillis
();
prep
=
conn
.
prepareStatement
(
"select count(*) from test t1, test t2"
);
rs
=
prep
.
executeQuery
();
rs
=
stat
.
executeQuery
(
"select count(*) from test t1, test t2"
);
rs
.
next
();
int
c
=
rs
.
getInt
(
1
);
assertEquals
(
1000000
,
c
);
time
=
System
.
currentTimeMillis
()
-
time
;
if
(
first
==
0
)
{
first
=
time
;
}
else
{
assertSmaller
(
time
,
first
);
}
}
conn
.
close
();
deleteDb
(
"queryCache"
);
}
}
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
7dff79ad
...
...
@@ -649,4 +649,4 @@ importing cumulative fired convenient sums judged anybody vacuum encountered
corresponds cnf informatique ilm boundaries shao crossed retroweaver usr pico
pengxiang china timestampadd picked releasing autoboxing conversions
pagestore addon defaults introduced customized histogram transact locker activemq
iml unified regclass netbeans geqo servername creator
iml unified regclass netbeans geqo servername creator
eclipsecs cacheable
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论