Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d70793f2
提交
d70793f2
authored
9月 03, 2013
作者:
noelgrandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- only expose the top 100 results in the query statistics table
- fix an occasional error in the test-case
上级
51f65d81
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
14 行增加
和
8 行删除
+14
-8
QueryStatisticsData.java
h2/src/main/org/h2/engine/QueryStatisticsData.java
+10
-2
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+2
-5
TestMetaData.java
h2/src/test/org/h2/test/jdbc/TestMetaData.java
+2
-1
没有找到文件。
h2/src/main/org/h2/engine/QueryStatisticsData.java
浏览文件 @
d70793f2
...
@@ -12,6 +12,7 @@ import java.util.Comparator;
...
@@ -12,6 +12,7 @@ import java.util.Comparator;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
/**
/**
...
@@ -22,6 +23,8 @@ public class QueryStatisticsData {
...
@@ -22,6 +23,8 @@ public class QueryStatisticsData {
private
static
final
int
MAX_QUERY_ENTRIES
=
100
;
private
static
final
int
MAX_QUERY_ENTRIES
=
100
;
public
static
final
class
QueryEntry
{
public
static
final
class
QueryEntry
{
public
String
sqlStatement
;
public
long
lastUpdateTime
;
public
long
lastUpdateTime
;
public
int
count
;
public
int
count
;
public
long
executionTimeMin
;
public
long
executionTimeMin
;
...
@@ -64,6 +67,7 @@ public class QueryStatisticsData {
...
@@ -64,6 +67,7 @@ public class QueryStatisticsData {
QueryEntry
entry
=
map
.
get
(
sqlStatement
);
QueryEntry
entry
=
map
.
get
(
sqlStatement
);
if
(
entry
==
null
)
{
if
(
entry
==
null
)
{
entry
=
new
QueryEntry
();
entry
=
new
QueryEntry
();
entry
.
sqlStatement
=
sqlStatement
;
entry
.
count
=
1
;
entry
.
count
=
1
;
entry
.
executionTimeMin
=
executionTime
;
entry
.
executionTimeMin
=
executionTime
;
entry
.
executionTimeMax
=
executionTime
;
entry
.
executionTimeMax
=
executionTime
;
...
@@ -113,9 +117,13 @@ public class QueryStatisticsData {
...
@@ -113,9 +117,13 @@ public class QueryStatisticsData {
}
}
}
}
public
synchronized
HashMap
<
String
,
QueryEntry
>
getQueryMap
()
{
public
synchronized
List
<
QueryEntry
>
getQueries
()
{
// return a copy of the map so we don't have to worry about external synchronization
// return a copy of the map so we don't have to worry about external synchronization
return
new
HashMap
<
String
,
QueryEntry
>(
map
);
ArrayList
<
QueryEntry
>
list
=
new
ArrayList
<
QueryEntry
>();
list
.
addAll
(
map
.
values
());
// only return the newest 100 entries
Collections
.
sort
(
list
,
QUERY_ENTRY_COMPARATOR
);
return
list
.
subList
(
0
,
Math
.
min
(
list
.
size
(),
MAX_QUERY_ENTRIES
));
}
}
private
static
final
Comparator
<
QueryEntry
>
QUERY_ENTRY_COMPARATOR
=
new
Comparator
<
QueryEntry
>()
{
private
static
final
Comparator
<
QueryEntry
>
QUERY_ENTRY_COMPARATOR
=
new
Comparator
<
QueryEntry
>()
{
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
d70793f2
...
@@ -17,7 +17,6 @@ import java.util.ArrayList;
...
@@ -17,7 +17,6 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.Map
;
import
org.h2.command.Command
;
import
org.h2.command.Command
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.Constraint
;
import
org.h2.constraint.ConstraintCheck
;
import
org.h2.constraint.ConstraintCheck
;
...
@@ -1642,12 +1641,10 @@ public class MetaTable extends Table {
...
@@ -1642,12 +1641,10 @@ public class MetaTable extends Table {
case
QUERY_STATISTICS:
{
case
QUERY_STATISTICS:
{
QueryStatisticsData
control
=
database
.
getQueryStatisticsData
();
QueryStatisticsData
control
=
database
.
getQueryStatisticsData
();
if
(
control
!=
null
)
{
if
(
control
!=
null
)
{
HashMap
<
String
,
QueryStatisticsData
.
QueryEntry
>
map
=
control
.
getQueryMap
();
for
(
QueryStatisticsData
.
QueryEntry
entry
:
control
.
getQueries
())
{
for
(
Map
.
Entry
<
String
,
QueryStatisticsData
.
QueryEntry
>
mapEntry
:
map
.
entrySet
())
{
QueryStatisticsData
.
QueryEntry
entry
=
mapEntry
.
getValue
();
add
(
rows
,
add
(
rows
,
// SQL_STATEMENT
// SQL_STATEMENT
mapEntry
.
getKey
()
,
entry
.
sqlStatement
,
// EXECUTION_COUNT
// EXECUTION_COUNT
""
+
entry
.
count
,
""
+
entry
.
count
,
// MIN_EXECUTION_TIME
// MIN_EXECUTION_TIME
...
...
h2/src/test/org/h2/test/jdbc/TestMetaData.java
浏览文件 @
d70793f2
...
@@ -1010,7 +1010,8 @@ public class TestMetaData extends TestBase {
...
@@ -1010,7 +1010,8 @@ public class TestMetaData extends TestBase {
stat
.
execute
(
"SET QUERY_STATISTICS TRUE"
);
stat
.
execute
(
"SET QUERY_STATISTICS TRUE"
);
stat
.
execute
(
"select * from test limit 10"
);
stat
.
execute
(
"select * from test limit 10"
);
stat
.
execute
(
"select * from test limit 10"
);
stat
.
execute
(
"select * from test limit 10"
);
rs
=
stat
.
executeQuery
(
"select * from INFORMATION_SCHEMA.QUERY_STATISTICS"
);
// The "order by" makes the resultset more stable on windows, where the timer resolution is not that great
rs
=
stat
.
executeQuery
(
"select * from INFORMATION_SCHEMA.QUERY_STATISTICS ORDER BY EXECUTION_COUNT"
);
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
next
());
assertEquals
(
"select * from test limit 10"
,
rs
.
getString
(
"SQL_STATEMENT"
));
assertEquals
(
"select * from test limit 10"
,
rs
.
getString
(
"SQL_STATEMENT"
));
assertEquals
(
2
,
rs
.
getInt
(
"EXECUTION_COUNT"
));
assertEquals
(
2
,
rs
.
getInt
(
"EXECUTION_COUNT"
));
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论