Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
73e73d4b
提交
73e73d4b
authored
9月 04, 2015
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #170 from doblak/master
added SET QUERY_STATISTICS_MAX_ENTRIES
上级
01153a2e
52d63c30
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
102 行增加
和
5 行删除
+102
-5
help.csv
h2/src/docsrc/help/help.csv
+13
-0
Set.java
h2/src/main/org/h2/command/dml/Set.java
+10
-0
SetTypes.java
h2/src/main/org/h2/command/dml/SetTypes.java
+6
-0
Constants.java
h2/src/main/org/h2/engine/Constants.java
+5
-0
Database.java
h2/src/main/org/h2/engine/Database.java
+13
-1
QueryStatisticsData.java
h2/src/main/org/h2/engine/QueryStatisticsData.java
+12
-4
TestMetaData.java
h2/src/test/org/h2/test/jdbc/TestMetaData.java
+43
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
73e73d4b
...
@@ -1481,6 +1481,19 @@ Admin rights are required to execute this command, as it affects all connections
...
@@ -1481,6 +1481,19 @@ Admin rights are required to execute this command, as it affects all connections
SET QUERY_STATISTICS FALSE
SET QUERY_STATISTICS FALSE
"
"
"Commands (Other)","SET QUERY_STATISTICS_MAX_ENTRIES","
SET QUERY_STATISTICS int
","
Set the maximum number of entries in query statistics meta-table.
Default value is 100.
This setting is not persistent.
This command commits an open transaction in this connection.
Admin rights are required to execute this command, as it affects all connections.
","
SET QUERY_STATISTICS_MAX_ENTRIES 500
"
"Commands (Other)","SET QUERY_TIMEOUT","
"Commands (Other)","SET QUERY_TIMEOUT","
SET QUERY_TIMEOUT int
SET QUERY_TIMEOUT int
","
","
...
...
h2/src/main/org/h2/command/dml/Set.java
浏览文件 @
73e73d4b
...
@@ -393,6 +393,16 @@ public class Set extends Prepared {
...
@@ -393,6 +393,16 @@ public class Set extends Prepared {
database
.
setQueryStatistics
(
value
==
1
);
database
.
setQueryStatistics
(
value
==
1
);
break
;
break
;
}
}
case
SetTypes
.
QUERY_STATISTICS_MAX_ENTRIES
:
{
session
.
getUser
().
checkAdmin
();
int
value
=
getIntValue
();
if
(
value
<
1
)
{
throw
DbException
.
getInvalidValueException
(
"QUERY_STATISTICS_MAX_ENTRIES"
,
getIntValue
());
}
database
.
setQueryStatisticsMaxEntries
(
value
);
break
;
}
case
SetTypes
.
SCHEMA
:
{
case
SetTypes
.
SCHEMA
:
{
Schema
schema
=
database
.
getSchema
(
stringValue
);
Schema
schema
=
database
.
getSchema
(
stringValue
);
session
.
setCurrentSchema
(
schema
);
session
.
setCurrentSchema
(
schema
);
...
...
h2/src/main/org/h2/command/dml/SetTypes.java
浏览文件 @
73e73d4b
...
@@ -218,6 +218,11 @@ public class SetTypes {
...
@@ -218,6 +218,11 @@ public class SetTypes {
*/
*/
public
static
final
int
QUERY_STATISTICS
=
41
;
public
static
final
int
QUERY_STATISTICS
=
41
;
/**
* The type of a SET QUERY_STATISTICS_MAX_ENTRIES statement.
*/
public
static
final
int
QUERY_STATISTICS_MAX_ENTRIES
=
42
;
private
static
final
ArrayList
<
String
>
TYPES
=
New
.
arrayList
();
private
static
final
ArrayList
<
String
>
TYPES
=
New
.
arrayList
();
private
SetTypes
()
{
private
SetTypes
()
{
...
@@ -268,6 +273,7 @@ public class SetTypes {
...
@@ -268,6 +273,7 @@ public class SetTypes {
list
.
add
(
JAVA_OBJECT_SERIALIZER
,
"JAVA_OBJECT_SERIALIZER"
);
list
.
add
(
JAVA_OBJECT_SERIALIZER
,
"JAVA_OBJECT_SERIALIZER"
);
list
.
add
(
RETENTION_TIME
,
"RETENTION_TIME"
);
list
.
add
(
RETENTION_TIME
,
"RETENTION_TIME"
);
list
.
add
(
QUERY_STATISTICS
,
"QUERY_STATISTICS"
);
list
.
add
(
QUERY_STATISTICS
,
"QUERY_STATISTICS"
);
list
.
add
(
QUERY_STATISTICS_MAX_ENTRIES
,
"QUERY_STATISTICS_MAX_ENTRIES"
);
}
}
/**
/**
...
...
h2/src/main/org/h2/engine/Constants.java
浏览文件 @
73e73d4b
...
@@ -505,6 +505,11 @@ public class Constants {
...
@@ -505,6 +505,11 @@ public class Constants {
*/
*/
public
static
final
int
VIEW_INDEX_CACHE_SIZE
=
64
;
public
static
final
int
VIEW_INDEX_CACHE_SIZE
=
64
;
/**
* The maximum number of entries in query statistics.
*/
public
static
final
int
QUERY_STATISTICS_MAX_ENTRIES
=
100
;
private
Constants
()
{
private
Constants
()
{
// utility class
// utility class
}
}
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
73e73d4b
...
@@ -189,6 +189,7 @@ public class Database implements DataHandler {
...
@@ -189,6 +189,7 @@ public class Database implements DataHandler {
private
String
javaObjectSerializerName
;
private
String
javaObjectSerializerName
;
private
volatile
boolean
javaObjectSerializerInitialized
;
private
volatile
boolean
javaObjectSerializerInitialized
;
private
boolean
queryStatistics
;
private
boolean
queryStatistics
;
private
int
queryStatisticsMaxEntries
=
Constants
.
QUERY_STATISTICS_MAX_ENTRIES
;
private
QueryStatisticsData
queryStatisticsData
;
private
QueryStatisticsData
queryStatisticsData
;
public
Database
(
ConnectionInfo
ci
,
String
cipher
)
{
public
Database
(
ConnectionInfo
ci
,
String
cipher
)
{
...
@@ -2260,6 +2261,17 @@ public class Database implements DataHandler {
...
@@ -2260,6 +2261,17 @@ public class Database implements DataHandler {
return
queryStatistics
;
return
queryStatistics
;
}
}
public
void
setQueryStatisticsMaxEntries
(
int
n
)
{
queryStatisticsMaxEntries
=
n
;
if
(
queryStatisticsData
!=
null
)
{
synchronized
(
this
)
{
if
(
queryStatisticsData
!=
null
)
{
queryStatisticsData
.
setMaxQueryEntries
(
queryStatisticsMaxEntries
);
}
}
}
}
public
QueryStatisticsData
getQueryStatisticsData
()
{
public
QueryStatisticsData
getQueryStatisticsData
()
{
if
(!
queryStatistics
)
{
if
(!
queryStatistics
)
{
return
null
;
return
null
;
...
@@ -2267,7 +2279,7 @@ public class Database implements DataHandler {
...
@@ -2267,7 +2279,7 @@ public class Database implements DataHandler {
if
(
queryStatisticsData
==
null
)
{
if
(
queryStatisticsData
==
null
)
{
synchronized
(
this
)
{
synchronized
(
this
)
{
if
(
queryStatisticsData
==
null
)
{
if
(
queryStatisticsData
==
null
)
{
queryStatisticsData
=
new
QueryStatisticsData
();
queryStatisticsData
=
new
QueryStatisticsData
(
queryStatisticsMaxEntries
);
}
}
}
}
}
}
...
...
h2/src/main/org/h2/engine/QueryStatisticsData.java
浏览文件 @
73e73d4b
...
@@ -19,8 +19,6 @@ import java.util.Map.Entry;
...
@@ -19,8 +19,6 @@ import java.util.Map.Entry;
*/
*/
public
class
QueryStatisticsData
{
public
class
QueryStatisticsData
{
private
static
final
int
MAX_QUERY_ENTRIES
=
100
;
private
static
final
Comparator
<
QueryEntry
>
QUERY_ENTRY_COMPARATOR
=
private
static
final
Comparator
<
QueryEntry
>
QUERY_ENTRY_COMPARATOR
=
new
Comparator
<
QueryEntry
>()
{
new
Comparator
<
QueryEntry
>()
{
@Override
@Override
...
@@ -32,6 +30,16 @@ public class QueryStatisticsData {
...
@@ -32,6 +30,16 @@ public class QueryStatisticsData {
private
final
HashMap
<
String
,
QueryEntry
>
map
=
private
final
HashMap
<
String
,
QueryEntry
>
map
=
new
HashMap
<
String
,
QueryEntry
>();
new
HashMap
<
String
,
QueryEntry
>();
private
int
maxQueryEntries
;
public
QueryStatisticsData
(
int
maxQueryEntries
)
{
this
.
maxQueryEntries
=
maxQueryEntries
;
}
public
synchronized
void
setMaxQueryEntries
(
int
maxQueryEntries
)
{
this
.
maxQueryEntries
=
maxQueryEntries
;
}
public
synchronized
List
<
QueryEntry
>
getQueries
()
{
public
synchronized
List
<
QueryEntry
>
getQueries
()
{
// return a copy of the map so we don't have to
// return a copy of the map so we don't have to
// worry about external synchronization
// worry about external synchronization
...
@@ -39,7 +47,7 @@ public class QueryStatisticsData {
...
@@ -39,7 +47,7 @@ public class QueryStatisticsData {
list
.
addAll
(
map
.
values
());
list
.
addAll
(
map
.
values
());
// only return the newest 100 entries
// only return the newest 100 entries
Collections
.
sort
(
list
,
QUERY_ENTRY_COMPARATOR
);
Collections
.
sort
(
list
,
QUERY_ENTRY_COMPARATOR
);
return
list
.
subList
(
0
,
Math
.
min
(
list
.
size
(),
MAX_QUERY_ENTRIES
));
return
list
.
subList
(
0
,
Math
.
min
(
list
.
size
(),
maxQueryEntries
));
}
}
/**
/**
...
@@ -62,7 +70,7 @@ public class QueryStatisticsData {
...
@@ -62,7 +70,7 @@ public class QueryStatisticsData {
// Age-out the oldest entries if the map gets too big.
// Age-out the oldest entries if the map gets too big.
// Test against 1.5 x max-size so we don't do this too often
// Test against 1.5 x max-size so we don't do this too often
if
(
map
.
size
()
>
MAX_QUERY_ENTRIES
*
1.5f
)
{
if
(
map
.
size
()
>
maxQueryEntries
*
1.5f
)
{
// Sort the entries by age
// Sort the entries by age
ArrayList
<
QueryEntry
>
list
=
new
ArrayList
<
QueryEntry
>();
ArrayList
<
QueryEntry
>
list
=
new
ArrayList
<
QueryEntry
>();
list
.
addAll
(
map
.
values
());
list
.
addAll
(
map
.
values
());
...
...
h2/src/test/org/h2/test/jdbc/TestMetaData.java
浏览文件 @
73e73d4b
...
@@ -56,6 +56,7 @@ public class TestMetaData extends TestBase {
...
@@ -56,6 +56,7 @@ public class TestMetaData extends TestBase {
testClientInfo
();
testClientInfo
();
testSessionsUncommitted
();
testSessionsUncommitted
();
testQueryStatistics
();
testQueryStatistics
();
testQueryStatisticsLimit
();
}
}
private
void
testUnwrap
()
throws
SQLException
{
private
void
testUnwrap
()
throws
SQLException
{
...
@@ -1260,4 +1261,46 @@ public class TestMetaData extends TestBase {
...
@@ -1260,4 +1261,46 @@ public class TestMetaData extends TestBase {
conn
.
close
();
conn
.
close
();
deleteDb
(
"metaData"
);
deleteDb
(
"metaData"
);
}
}
private
void
testQueryStatisticsLimit
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"metaData"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar) as "
+
"select x, space(1000) from system_range(1, 2000)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select * from INFORMATION_SCHEMA.QUERY_STATISTICS"
);
assertFalse
(
rs
.
next
());
rs
.
close
();
//first, test setting the limit before activating statistics
int
statisticsMaxEntries
=
200
;
//prevent test limit being less than or equal to default limit
assertTrue
(
statisticsMaxEntries
>
Constants
.
QUERY_STATISTICS_MAX_ENTRIES
);
stat
.
execute
(
"SET QUERY_STATISTICS_MAX_ENTRIES "
+
statisticsMaxEntries
);
stat
.
execute
(
"SET QUERY_STATISTICS TRUE"
);
for
(
int
i
=
0
;
i
<
statisticsMaxEntries
*
2
;
i
++)
{
stat
.
execute
(
"select * from test where id = "
+
i
);
}
rs
=
stat
.
executeQuery
(
"select count(*) from INFORMATION_SCHEMA.QUERY_STATISTICS"
);
assertTrue
(
rs
.
next
());
assertEquals
(
statisticsMaxEntries
,
rs
.
getInt
(
1
));
rs
.
close
();
//first, test changing the limit once statistics is activated
int
statisticsMaxEntriesNew
=
50
;
//prevent new test limit being greater than or equal to default limit
assertTrue
(
statisticsMaxEntriesNew
<
Constants
.
QUERY_STATISTICS_MAX_ENTRIES
);
stat
.
execute
(
"SET QUERY_STATISTICS_MAX_ENTRIES "
+
statisticsMaxEntriesNew
);
for
(
int
i
=
0
;
i
<
statisticsMaxEntriesNew
*
2
;
i
++)
{
stat
.
execute
(
"select * from test where id = "
+
i
);
}
rs
=
stat
.
executeQuery
(
"select count(*) from INFORMATION_SCHEMA.QUERY_STATISTICS"
);
assertTrue
(
rs
.
next
());
assertEquals
(
statisticsMaxEntriesNew
,
rs
.
getInt
(
1
));
rs
.
close
();
conn
.
close
();
deleteDb
(
"metaData"
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论