Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
895b9dad
提交
895b9dad
authored
9 年前
作者:
S.Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sub-query or view cost could be wrong for cached ViewIndex
上级
c5d3a33e
master
noel-pr1
plus33-master
pr/267
stumc-Issue#576
version-1.4.198
version-1.4.197
version-1.4.196
version-1.4.195
version-1.4.194
version-1.4.193
version-1.4.192
version-1.4.191
无相关合并请求
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
25 行增加
和
56 行删除
+25
-56
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+22
-53
TableView.java
h2/src/main/org/h2/table/TableView.java
+3
-3
没有找到文件。
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
895b9dad
...
...
@@ -6,6 +6,7 @@
package
org
.
h2
.
index
;
import
java.util.ArrayList
;
import
java.util.concurrent.TimeUnit
;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Prepared
;
import
org.h2.command.dml.Query
;
...
...
@@ -26,9 +27,6 @@ import org.h2.table.TableFilter;
import
org.h2.table.TableView
;
import
org.h2.util.IntArray
;
import
org.h2.util.New
;
import
org.h2.util.SmallLRUCache
;
import
org.h2.util.SynchronizedVerifier
;
import
org.h2.util.Utils
;
import
org.h2.value.Value
;
/**
...
...
@@ -37,16 +35,22 @@ import org.h2.value.Value;
*/
public
class
ViewIndex
extends
BaseIndex
implements
SpatialIndex
{
private
static
final
long
MAX_AGE_NANOS
=
TimeUnit
.
MILLISECONDS
.
toNanos
(
Constants
.
VIEW_COST_CACHE_MAX_AGE
);
private
final
TableView
view
;
private
final
String
querySQL
;
private
final
ArrayList
<
Parameter
>
originalParameters
;
private
final
SmallLRUCache
<
IntArray
,
CostElement
>
costCache
=
SmallLRUCache
.
newInstance
(
Constants
.
VIEW_INDEX_CACHE_SIZE
);
private
boolean
recursive
;
private
final
int
[]
indexMasks
;
private
Query
query
;
private
final
Session
createSession
;
/**
* The time in nanoseconds when this index (and its cost) was calculated.
*/
private
final
long
evaluatedAt
;
/**
* Constructor for the original index in {@link TableView}.
*
...
...
@@ -65,6 +69,8 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
columns
=
new
Column
[
0
];
this
.
createSession
=
null
;
this
.
indexMasks
=
null
;
// this is a main index of TableView, it does not need eviction time stamp
evaluatedAt
=
Long
.
MIN_VALUE
;
}
/**
...
...
@@ -90,6 +96,10 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
columns
=
new
Column
[
0
];
if
(!
recursive
)
{
query
=
getQuery
(
session
,
masks
,
filters
,
filter
,
sortOrder
);
evaluatedAt
=
System
.
nanoTime
();
}
else
{
// we don't need eviction for recursive views since we can't calculate their cost
evaluatedAt
=
Long
.
MAX_VALUE
;
}
}
...
...
@@ -106,6 +116,11 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
return
createSession
;
}
public
boolean
isExpired
()
{
assert
evaluatedAt
!=
Long
.
MIN_VALUE
:
"must not be called for main index of TableView"
;
return
!
recursive
&&
System
.
nanoTime
()
-
evaluatedAt
>
MAX_AGE_NANOS
;
}
@Override
public
String
getPlanSQL
()
{
return
query
==
null
?
null
:
query
.
getPlanSQL
();
...
...
@@ -143,55 +158,9 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
}
@Override
public
synchronized
double
getCost
(
Session
session
,
int
[]
masks
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
if
(
recursive
)
{
return
1000
;
}
IntArray
masksArray
=
new
IntArray
(
masks
==
null
?
Utils
.
EMPTY_INT_ARRAY
:
masks
);
SynchronizedVerifier
.
check
(
costCache
);
CostElement
cachedCost
=
costCache
.
get
(
masksArray
);
if
(
cachedCost
!=
null
)
{
long
time
=
System
.
currentTimeMillis
();
if
(
time
<
cachedCost
.
evaluatedAt
+
Constants
.
VIEW_COST_CACHE_MAX_AGE
)
{
return
cachedCost
.
cost
;
}
}
Query
q
=
prepareSubQuery
(
querySQL
,
session
,
masks
,
filters
,
filter
,
sortOrder
);
if
(
masks
!=
null
)
{
for
(
int
idx
=
0
;
idx
<
masks
.
length
;
idx
++)
{
int
mask
=
masks
[
idx
];
if
(
mask
==
0
)
{
continue
;
}
int
nextParamIndex
=
q
.
getParameters
().
size
()
+
view
.
getParameterOffset
();
if
((
mask
&
IndexCondition
.
EQUALITY
)
!=
0
)
{
Parameter
param
=
new
Parameter
(
nextParamIndex
);
q
.
addGlobalCondition
(
param
,
idx
,
Comparison
.
EQUAL_NULL_SAFE
);
}
else
if
((
mask
&
IndexCondition
.
SPATIAL_INTERSECTS
)
!=
0
)
{
Parameter
param
=
new
Parameter
(
nextParamIndex
);
q
.
addGlobalCondition
(
param
,
idx
,
Comparison
.
SPATIAL_INTERSECTS
);
}
else
{
if
((
mask
&
IndexCondition
.
START
)
!=
0
)
{
Parameter
param
=
new
Parameter
(
nextParamIndex
);
q
.
addGlobalCondition
(
param
,
idx
,
Comparison
.
BIGGER_EQUAL
);
}
if
((
mask
&
IndexCondition
.
END
)
!=
0
)
{
Parameter
param
=
new
Parameter
(
nextParamIndex
);
q
.
addGlobalCondition
(
param
,
idx
,
Comparison
.
SMALLER_EQUAL
);
}
}
}
String
sql
=
q
.
getPlanSQL
();
q
=
prepareSubQuery
(
sql
,
session
,
masks
,
filters
,
filter
,
sortOrder
);
}
double
cost
=
q
.
getCost
();
cachedCost
=
new
CostElement
();
cachedCost
.
evaluatedAt
=
System
.
currentTimeMillis
();
cachedCost
.
cost
=
cost
;
costCache
.
put
(
masksArray
,
cachedCost
);
return
cost
;
return
recursive
?
1000
:
query
.
getCost
();
}
@Override
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableView.java
浏览文件 @
895b9dad
...
...
@@ -235,15 +235,15 @@ public class TableView extends Table {
@Override
public
PlanItem
getBestPlanItem
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
PlanItem
item
=
new
PlanItem
();
item
.
cost
=
index
.
getCost
(
session
,
masks
,
filters
,
filter
,
sortOrder
);
final
CacheKey
cacheKey
=
new
CacheKey
(
masks
,
this
);
Map
<
Object
,
ViewIndex
>
indexCache
=
session
.
getViewIndexCache
(
topQuery
!=
null
);
ViewIndex
i
=
indexCache
.
get
(
cacheKey
);
if
(
i
==
null
)
{
if
(
i
==
null
||
i
.
isExpired
()
)
{
i
=
new
ViewIndex
(
this
,
index
,
session
,
masks
,
filters
,
filter
,
sortOrder
);
indexCache
.
put
(
cacheKey
,
i
);
}
PlanItem
item
=
new
PlanItem
();
item
.
cost
=
i
.
getCost
(
session
,
masks
,
filters
,
filter
,
sortOrder
);
item
.
setIndex
(
i
);
return
item
;
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论