Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f8067a70
提交
f8067a70
authored
11月 10, 2015
作者:
S.Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more fixes
上级
b24cbdf5
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
27 行增加
和
18 行删除
+27
-18
Select.java
h2/src/main/org/h2/command/dml/Select.java
+3
-3
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+3
-6
Table.java
h2/src/main/org/h2/table/Table.java
+5
-0
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+9
-8
TableView.java
h2/src/main/org/h2/table/TableView.java
+7
-1
没有找到文件。
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
f8067a70
...
@@ -900,8 +900,8 @@ public class Select extends Query {
...
@@ -900,8 +900,8 @@ public class Select extends Query {
}
}
if
(
sort
!=
null
&&
!
isQuickAggregateQuery
&&
!
isGroupQuery
)
{
if
(
sort
!=
null
&&
!
isQuickAggregateQuery
&&
!
isGroupQuery
)
{
Index
index
=
getSortIndex
();
Index
index
=
getSortIndex
();
if
(
index
!=
null
)
{
Index
current
=
topTableFilter
.
getIndex
();
Index
current
=
topTableFilter
.
getIndex
();
if
(
index
!=
null
&&
current
!=
null
)
{
if
(
current
.
getIndexType
().
isScan
()
||
current
==
index
)
{
if
(
current
.
getIndexType
().
isScan
()
||
current
==
index
)
{
topTableFilter
.
setIndex
(
index
);
topTableFilter
.
setIndex
(
index
);
if
(!
topTableFilter
.
hasInComparisons
())
{
if
(!
topTableFilter
.
hasInComparisons
())
{
...
@@ -934,7 +934,7 @@ public class Select extends Query {
...
@@ -934,7 +934,7 @@ public class Select extends Query {
getGroupByExpressionCount
()
>
0
)
{
getGroupByExpressionCount
()
>
0
)
{
Index
index
=
getGroupSortedIndex
();
Index
index
=
getGroupSortedIndex
();
Index
current
=
topTableFilter
.
getIndex
();
Index
current
=
topTableFilter
.
getIndex
();
if
(
index
!=
null
&&
(
current
.
getIndexType
().
isScan
()
||
if
(
index
!=
null
&&
current
!=
null
&&
(
current
.
getIndexType
().
isScan
()
||
current
==
index
))
{
current
==
index
))
{
topTableFilter
.
setIndex
(
index
);
topTableFilter
.
setIndex
(
index
);
isGroupSortedQuery
=
true
;
isGroupSortedQuery
=
true
;
...
...
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
f8067a70
...
@@ -88,7 +88,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
...
@@ -88,7 +88,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
this
.
indexMasks
=
masks
;
this
.
indexMasks
=
masks
;
this
.
createSession
=
session
;
this
.
createSession
=
session
;
columns
=
new
Column
[
0
];
columns
=
new
Column
[
0
];
if
(!
recursive
&&
filters
!=
null
)
{
if
(!
recursive
)
{
query
=
getQuery
(
session
,
masks
,
filters
,
filter
,
sortOrder
);
query
=
getQuery
(
session
,
masks
,
filters
,
filter
,
sortOrder
);
}
}
}
}
...
@@ -136,7 +136,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
...
@@ -136,7 +136,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
@Override
@Override
public
synchronized
double
getCost
(
Session
session
,
int
[]
masks
,
public
synchronized
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
if
(
recursive
||
filters
==
null
)
{
if
(
recursive
)
{
return
1000
;
return
1000
;
}
}
IntArray
masksArray
=
new
IntArray
(
masks
==
null
?
IntArray
masksArray
=
new
IntArray
(
masks
==
null
?
...
@@ -177,10 +177,6 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
...
@@ -177,10 +177,6 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
String
sql
=
q
.
getPlanSQL
();
String
sql
=
q
.
getPlanSQL
();
q
=
prepareSubQuery
(
sql
,
session
,
masks
,
filters
,
filter
,
sortOrder
,
false
);
q
=
prepareSubQuery
(
sql
,
session
,
masks
,
filters
,
filter
,
sortOrder
,
false
);
}
}
if
(
query
==
null
)
{
// this is possible when scan index has been taken and the cost was recalculated
query
=
q
;
}
double
cost
=
q
.
getCost
();
double
cost
=
q
.
getCost
();
cachedCost
=
new
CostElement
();
cachedCost
=
new
CostElement
();
cachedCost
.
evaluatedAt
=
System
.
currentTimeMillis
();
cachedCost
.
evaluatedAt
=
System
.
currentTimeMillis
();
...
@@ -201,6 +197,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
...
@@ -201,6 +197,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
private
static
Query
prepareSubQuery
(
String
sql
,
Session
session
,
int
[]
masks
,
private
static
Query
prepareSubQuery
(
String
sql
,
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
,
boolean
preliminary
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
,
boolean
preliminary
)
{
assert
filters
!=
null
;
Prepared
p
;
Prepared
p
;
SubQueryInfo
upper
=
session
.
getSubQueryInfo
();
SubQueryInfo
upper
=
session
.
getSubQueryInfo
();
SubQueryInfo
info
=
new
SubQueryInfo
(
upper
,
SubQueryInfo
info
=
new
SubQueryInfo
(
upper
,
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
f8067a70
...
@@ -236,6 +236,11 @@ public abstract class Table extends SchemaObjectBase {
...
@@ -236,6 +236,11 @@ public abstract class Table extends SchemaObjectBase {
*/
*/
public
abstract
Index
getScanIndex
(
Session
session
);
public
abstract
Index
getScanIndex
(
Session
session
);
public
Index
getScanIndex
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
getScanIndex
(
session
);
}
/**
/**
* Get any unique index for this table if one exists.
* Get any unique index for this table if one exists.
*
*
...
...
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
f8067a70
...
@@ -202,10 +202,14 @@ public class TableFilter implements ColumnResolver {
...
@@ -202,10 +202,14 @@ public class TableFilter implements ColumnResolver {
*/
*/
public
PlanItem
getBestPlanItem
(
Session
s
,
TableFilter
[]
filters
,
int
filter
)
{
public
PlanItem
getBestPlanItem
(
Session
s
,
TableFilter
[]
filters
,
int
filter
)
{
PlanItem
item
;
PlanItem
item
;
SortOrder
sortOrder
=
null
;
if
(
select
!=
null
)
{
sortOrder
=
select
.
getSortOrder
();
}
if
(
indexConditions
.
size
()
==
0
)
{
if
(
indexConditions
.
size
()
==
0
)
{
item
=
new
PlanItem
();
item
=
new
PlanItem
();
item
.
setIndex
(
table
.
getScanIndex
(
s
));
item
.
setIndex
(
table
.
getScanIndex
(
s
,
null
,
filters
,
filter
,
sortOrder
));
item
.
cost
=
item
.
getIndex
().
getCost
(
s
,
null
,
filters
,
filter
,
null
);
item
.
cost
=
item
.
getIndex
().
getCost
(
s
,
null
,
filters
,
filter
,
sortOrder
);
}
else
{
}
else
{
int
len
=
table
.
getColumns
().
length
;
int
len
=
table
.
getColumns
().
length
;
int
[]
masks
=
new
int
[
len
];
int
[]
masks
=
new
int
[
len
];
...
@@ -221,10 +225,6 @@ public class TableFilter implements ColumnResolver {
...
@@ -221,10 +225,6 @@ public class TableFilter implements ColumnResolver {
}
}
}
}
}
}
SortOrder
sortOrder
=
null
;
if
(
select
!=
null
)
{
sortOrder
=
select
.
getSortOrder
();
}
item
=
table
.
getBestPlanItem
(
s
,
masks
,
filters
,
filter
,
sortOrder
);
item
=
table
.
getBestPlanItem
(
s
,
masks
,
filters
,
filter
,
sortOrder
);
item
.
setMasks
(
masks
);
item
.
setMasks
(
masks
);
// The more index conditions, the earlier the table.
// The more index conditions, the earlier the table.
...
@@ -241,8 +241,9 @@ public class TableFilter implements ColumnResolver {
...
@@ -241,8 +241,9 @@ public class TableFilter implements ColumnResolver {
}
}
if
(
join
!=
null
)
{
if
(
join
!=
null
)
{
setEvaluatable
(
join
);
setEvaluatable
(
join
);
filter
+=
nestedJoin
==
null
?
1
:
2
;
do
{
assert
filters
[
filter
]
==
join
;
filter
++;
}
while
(
filters
[
filter
]
!=
join
);
item
.
setJoinPlan
(
join
.
getBestPlanItem
(
s
,
filters
,
filter
));
item
.
setJoinPlan
(
join
.
getBestPlanItem
(
s
,
filters
,
filter
));
// TODO optimizer: calculate cost of a join: should use separate
// TODO optimizer: calculate cost of a join: should use separate
// expected row number and lookup cost
// expected row number and lookup cost
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
f8067a70
...
@@ -435,12 +435,18 @@ public class TableView extends Table {
...
@@ -435,12 +435,18 @@ public class TableView extends Table {
@Override
@Override
public
Index
getScanIndex
(
Session
session
)
{
public
Index
getScanIndex
(
Session
session
)
{
return
getBestPlanItem
(
session
,
null
,
null
,
-
1
,
null
).
getIndex
();
}
@Override
public
Index
getScanIndex
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
if
(
createException
!=
null
)
{
if
(
createException
!=
null
)
{
String
msg
=
createException
.
getMessage
();
String
msg
=
createException
.
getMessage
();
throw
DbException
.
get
(
ErrorCode
.
VIEW_IS_INVALID_2
,
throw
DbException
.
get
(
ErrorCode
.
VIEW_IS_INVALID_2
,
createException
,
getSQL
(),
msg
);
createException
,
getSQL
(),
msg
);
}
}
PlanItem
item
=
getBestPlanItem
(
session
,
null
,
null
,
-
1
,
null
);
PlanItem
item
=
getBestPlanItem
(
session
,
masks
,
filters
,
filter
,
sortOrder
);
return
item
.
getIndex
();
return
item
.
getIndex
();
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论