Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
13fd5a10
提交
13fd5a10
authored
10月 28, 2015
作者:
S.Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
All joined table filters are passed into Index.getCost
上级
4574944c
隐藏空白字符变更
内嵌
并排
正在显示
27 个修改的文件
包含
80 行增加
和
81 行删除
+80
-81
Delete.java
h2/src/main/org/h2/command/dml/Delete.java
+1
-1
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+1
-1
Update.java
h2/src/main/org/h2/command/dml/Update.java
+1
-1
FunctionIndex.java
h2/src/main/org/h2/index/FunctionIndex.java
+2
-2
HashIndex.java
h2/src/main/org/h2/index/HashIndex.java
+2
-2
Index.java
h2/src/main/org/h2/index/Index.java
+3
-2
LinkedIndex.java
h2/src/main/org/h2/index/LinkedIndex.java
+3
-3
MetaIndex.java
h2/src/main/org/h2/index/MetaIndex.java
+3
-3
MultiVersionIndex.java
h2/src/main/org/h2/index/MultiVersionIndex.java
+3
-3
NonUniqueHashIndex.java
h2/src/main/org/h2/index/NonUniqueHashIndex.java
+2
-2
PageBtreeIndex.java
h2/src/main/org/h2/index/PageBtreeIndex.java
+3
-3
PageDataIndex.java
h2/src/main/org/h2/index/PageDataIndex.java
+2
-3
PageDelegateIndex.java
h2/src/main/org/h2/index/PageDelegateIndex.java
+3
-3
RangeIndex.java
h2/src/main/org/h2/index/RangeIndex.java
+2
-2
ScanIndex.java
h2/src/main/org/h2/index/ScanIndex.java
+2
-2
SpatialTreeIndex.java
h2/src/main/org/h2/index/SpatialTreeIndex.java
+3
-3
TreeIndex.java
h2/src/main/org/h2/index/TreeIndex.java
+2
-2
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+1
-1
MVDelegateIndex.java
h2/src/main/org/h2/mvstore/db/MVDelegateIndex.java
+4
-5
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+2
-3
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+4
-5
MVSpatialIndex.java
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
+3
-5
Plan.java
h2/src/main/org/h2/table/Plan.java
+3
-3
Table.java
h2/src/main/org/h2/table/Table.java
+5
-4
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+10
-8
TableView.java
h2/src/main/org/h2/table/TableView.java
+3
-3
TestTableEngines.java
h2/src/test/org/h2/test/db/TestTableEngines.java
+7
-6
没有找到文件。
h2/src/main/org/h2/command/dml/Delete.java
浏览文件 @
13fd5a10
...
...
@@ -130,7 +130,7 @@ public class Delete extends Prepared {
condition
=
condition
.
optimize
(
session
);
condition
.
createIndexConditions
(
session
,
tableFilter
);
}
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
1
);
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
new
TableFilter
[]{
tableFilter
},
0
);
tableFilter
.
setPlanItem
(
item
);
tableFilter
.
prepare
();
}
...
...
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
13fd5a10
...
...
@@ -389,7 +389,7 @@ public class ScriptCommand extends ScriptBase {
}
private
int
generateInsertValues
(
int
count
,
Table
table
)
throws
IOException
{
PlanItem
plan
=
table
.
getBestPlanItem
(
session
,
null
,
null
,
null
);
PlanItem
plan
=
table
.
getBestPlanItem
(
session
,
null
,
null
,
-
1
,
null
);
Index
index
=
plan
.
getIndex
();
Cursor
cursor
=
index
.
find
(
session
,
null
,
null
);
Column
[]
columns
=
table
.
getColumns
();
...
...
h2/src/main/org/h2/command/dml/Update.java
浏览文件 @
13fd5a10
...
...
@@ -187,7 +187,7 @@ public class Update extends Prepared {
e
.
mapColumns
(
tableFilter
,
0
);
expressionMap
.
put
(
c
,
e
.
optimize
(
session
));
}
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
1
);
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
new
TableFilter
[]
{
tableFilter
},
0
);
tableFilter
.
setPlanItem
(
item
);
tableFilter
.
prepare
();
}
...
...
h2/src/main/org/h2/index/FunctionIndex.java
浏览文件 @
13fd5a10
...
...
@@ -52,8 +52,8 @@ public class FunctionIndex extends BaseIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
if
(
masks
!=
null
)
{
throw
DbException
.
getUnsupportedException
(
"ALIAS"
);
}
...
...
h2/src/main/org/h2/index/HashIndex.java
浏览文件 @
13fd5a10
...
...
@@ -113,8 +113,8 @@ public class HashIndex extends BaseIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
for
(
Column
column
:
columns
)
{
int
index
=
column
.
getColumnId
();
int
mask
=
masks
[
index
];
...
...
h2/src/main/org/h2/index/Index.java
浏览文件 @
13fd5a10
...
...
@@ -83,11 +83,12 @@ public interface Index extends SchemaObject {
* @param session the session
* @param masks per-column comparison bit masks, null means 'always false',
* see constants in IndexCondition
* @param filter the table filter
* @param filters all joined table filters
* @param filter the current table filter index
* @param sortOrder the sort order
* @return the estimated cost
*/
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
);
/**
...
...
h2/src/main/org/h2/index/LinkedIndex.java
浏览文件 @
13fd5a10
...
...
@@ -141,10 +141,10 @@ public class LinkedIndex extends BaseIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
100
+
getCostRangeIndex
(
masks
,
rowCount
+
Constants
.
COST_ROW_OFFSET
,
filter
,
sortOrder
);
Constants
.
COST_ROW_OFFSET
,
filter
s
==
null
?
null
:
filters
[
filter
]
,
sortOrder
);
}
@Override
...
...
h2/src/main/org/h2/index/MetaIndex.java
浏览文件 @
13fd5a10
...
...
@@ -52,13 +52,13 @@ public class MetaIndex extends BaseIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
if
(
scan
)
{
return
10
*
MetaTable
.
ROW_COUNT_APPROXIMATION
;
}
return
getCostRangeIndex
(
masks
,
MetaTable
.
ROW_COUNT_APPROXIMATION
,
filter
,
sortOrder
);
filter
s
==
null
?
null
:
filters
[
filter
]
,
sortOrder
);
}
@Override
...
...
h2/src/main/org/h2/index/MultiVersionIndex.java
浏览文件 @
13fd5a10
...
...
@@ -142,9 +142,9 @@ public class MultiVersionIndex implements Index {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
return
base
.
getCost
(
session
,
masks
,
filter
,
sortOrder
);
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
base
.
getCost
(
session
,
masks
,
filter
s
,
filter
,
sortOrder
);
}
@Override
...
...
h2/src/main/org/h2/index/NonUniqueHashIndex.java
浏览文件 @
13fd5a10
...
...
@@ -130,8 +130,8 @@ public class NonUniqueHashIndex extends BaseIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
for
(
Column
column
:
columns
)
{
int
index
=
column
.
getColumnId
();
int
mask
=
masks
[
index
];
...
...
h2/src/main/org/h2/index/PageBtreeIndex.java
浏览文件 @
13fd5a10
...
...
@@ -217,10 +217,10 @@ public class PageBtreeIndex extends PageIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
10
*
getCostRangeIndex
(
masks
,
tableData
.
getRowCount
(
session
),
filter
,
sortOrder
);
filter
s
==
null
?
null
:
filters
[
filter
]
,
sortOrder
);
}
@Override
...
...
h2/src/main/org/h2/index/PageDataIndex.java
浏览文件 @
13fd5a10
...
...
@@ -10,7 +10,6 @@ import java.util.HashMap;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.List
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Session
;
...
...
@@ -310,8 +309,8 @@ public class PageDataIndex extends PageIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
long
cost
=
10
*
(
tableData
.
getRowCountApproximation
()
+
Constants
.
COST_ROW_OFFSET
);
return
cost
;
...
...
h2/src/main/org/h2/index/PageDelegateIndex.java
浏览文件 @
13fd5a10
...
...
@@ -96,10 +96,10 @@ public class PageDelegateIndex extends PageIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
10
*
getCostRangeIndex
(
masks
,
mainIndex
.
getRowCount
(
session
),
filter
,
sortOrder
);
filter
s
==
null
?
null
:
filters
[
filter
]
,
sortOrder
);
}
@Override
...
...
h2/src/main/org/h2/index/RangeIndex.java
浏览文件 @
13fd5a10
...
...
@@ -62,8 +62,8 @@ public class RangeIndex extends BaseIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
1
;
}
...
...
h2/src/main/org/h2/index/ScanIndex.java
浏览文件 @
13fd5a10
...
...
@@ -174,8 +174,8 @@ public class ScanIndex extends BaseIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
tableData
.
getRowCountApproximation
()
+
Constants
.
COST_ROW_OFFSET
;
}
...
...
h2/src/main/org/h2/index/SpatialTreeIndex.java
浏览文件 @
13fd5a10
...
...
@@ -208,10 +208,10 @@ public class SpatialTreeIndex extends BaseIndex implements SpatialIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
getCostRangeIndex
(
masks
,
table
.
getRowCountApproximation
(),
filter
,
sortOrder
);
filter
s
==
null
?
null
:
filters
[
filter
]
,
sortOrder
);
}
@Override
...
...
h2/src/main/org/h2/index/TreeIndex.java
浏览文件 @
13fd5a10
...
...
@@ -318,10 +318,10 @@ public class TreeIndex extends BaseIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
getCostRangeIndex
(
masks
,
tableData
.
getRowCountApproximation
(),
filter
,
sortOrder
);
filter
s
==
null
?
null
:
filters
[
filter
]
,
sortOrder
);
}
@Override
...
...
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
13fd5a10
...
...
@@ -115,7 +115,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
@Override
public
synchronized
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
if
(
recursive
)
{
return
1000
;
}
...
...
h2/src/main/org/h2/mvstore/db/MVDelegateIndex.java
浏览文件 @
13fd5a10
...
...
@@ -6,7 +6,6 @@
package
org
.
h2
.
mvstore
.
db
;
import
java.util.List
;
import
org.h2.engine.Session
;
import
org.h2.index.BaseIndex
;
import
org.h2.index.Cursor
;
...
...
@@ -89,10 +88,10 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
return
10
*
getCostRangeIndex
(
masks
,
mainIndex
.
getRowCountApproximation
(),
filter
,
sortOrder
);
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
10
*
getCostRangeIndex
(
masks
,
mainIndex
.
getRowCountApproximation
(),
filters
==
null
?
null
:
filters
[
filter
]
,
sortOrder
);
}
@Override
...
...
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
13fd5a10
...
...
@@ -10,7 +10,6 @@ import java.util.Collections;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map.Entry
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
...
...
@@ -217,8 +216,8 @@ public class MVPrimaryIndex extends BaseIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
try
{
long
cost
=
10
*
(
dataMap
.
sizeAsLongMax
()
+
Constants
.
COST_ROW_OFFSET
);
return
cost
;
...
...
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
13fd5a10
...
...
@@ -10,7 +10,6 @@ import java.util.Collections;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.TreeSet
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
...
...
@@ -352,11 +351,11 @@ public class MVSecondaryIndex extends BaseIndex implements MVIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
try
{
return
10
*
getCostRangeIndex
(
masks
,
dataMap
.
sizeAsLongMax
(),
filter
,
sortOrder
);
return
10
*
getCostRangeIndex
(
masks
,
dataMap
.
sizeAsLongMax
(),
filters
==
null
?
null
:
filters
[
filter
]
,
sortOrder
);
}
catch
(
IllegalStateException
e
)
{
throw
DbException
.
get
(
ErrorCode
.
OBJECT_CLOSED
,
e
);
}
...
...
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
浏览文件 @
13fd5a10
...
...
@@ -7,7 +7,6 @@ package org.h2.mvstore.db;
import
java.util.Iterator
;
import
java.util.List
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
...
...
@@ -33,7 +32,6 @@ import org.h2.value.Value;
import
org.h2.value.ValueGeometry
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueNull
;
import
com.vividsolutions.jts.geom.Envelope
;
import
com.vividsolutions.jts.geom.Geometry
;
...
...
@@ -239,10 +237,10 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
getCostRangeIndex
(
masks
,
table
.
getRowCountApproximation
(),
filter
,
sortOrder
);
filter
s
==
null
?
null
:
filters
[
filter
]
,
sortOrder
);
}
@Override
...
...
h2/src/main/org/h2/table/Plan.java
浏览文件 @
13fd5a10
...
...
@@ -106,9 +106,9 @@ public class Plan {
public
double
calculateCost
(
Session
session
)
{
double
cost
=
1
;
boolean
invalidPlan
=
false
;
int
level
=
1
;
for
(
TableFilter
tableFilter
:
allFilters
)
{
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
level
++
);
for
(
int
i
=
0
;
i
<
allFilters
.
length
;
i
++)
{
TableFilter
tableFilter
=
allFilters
[
i
];
PlanItem
item
=
tableFilter
.
getBestPlanItem
(
session
,
allFilters
,
i
);
planItems
.
put
(
tableFilter
,
item
);
cost
+=
cost
*
item
.
cost
;
setEvaluatable
(
tableFilter
,
true
);
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
13fd5a10
...
...
@@ -678,20 +678,21 @@ public abstract class Table extends SchemaObjectBase {
* @param session the session
* @param masks per-column comparison bit masks, null means 'always false',
* see constants in IndexCondition
* @param filter the table filter
* @param filters all joined table filters
* @param filter the current table filter index
* @param sortOrder the sort order
* @return the plan item
*/
public
PlanItem
getBestPlanItem
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
PlanItem
item
=
new
PlanItem
();
item
.
setIndex
(
getScanIndex
(
session
));
item
.
cost
=
item
.
getIndex
().
getCost
(
session
,
null
,
null
,
null
);
item
.
cost
=
item
.
getIndex
().
getCost
(
session
,
null
,
filters
,
filter
,
null
);
ArrayList
<
Index
>
indexes
=
getIndexes
();
if
(
indexes
!=
null
&&
masks
!=
null
)
{
for
(
int
i
=
1
,
size
=
indexes
.
size
();
i
<
size
;
i
++)
{
Index
index
=
indexes
.
get
(
i
);
double
cost
=
index
.
getCost
(
session
,
masks
,
filter
,
sortOrder
);
double
cost
=
index
.
getCost
(
session
,
masks
,
filter
s
,
filter
,
sortOrder
);
if
(
cost
<
item
.
cost
)
{
item
.
cost
=
cost
;
item
.
setIndex
(
index
);
...
...
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
13fd5a10
...
...
@@ -10,7 +10,6 @@ import java.util.ArrayList;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.ListIterator
;
import
java.util.concurrent.Future
;
import
org.h2.command.Parser
;
import
org.h2.command.dml.Select
;
...
...
@@ -196,15 +195,16 @@ public class TableFilter implements ColumnResolver {
* order.
*
* @param s the session
* @param level 1 for the first table in a join, 2 for the second, and so on
* @param filters all joined table filters
* @param filter the current table filter index
* @return the best plan item
*/
public
PlanItem
getBestPlanItem
(
Session
s
,
int
level
)
{
public
PlanItem
getBestPlanItem
(
Session
s
,
TableFilter
[]
filters
,
int
filter
)
{
PlanItem
item
;
if
(
indexConditions
.
size
()
==
0
)
{
item
=
new
PlanItem
();
item
.
setIndex
(
table
.
getScanIndex
(
s
));
item
.
cost
=
item
.
getIndex
().
getCost
(
s
,
null
,
null
,
null
);
item
.
cost
=
item
.
getIndex
().
getCost
(
s
,
null
,
filters
,
filter
,
null
);
}
else
{
int
len
=
table
.
getColumns
().
length
;
int
[]
masks
=
new
int
[
len
];
...
...
@@ -224,22 +224,24 @@ public class TableFilter implements ColumnResolver {
if
(
select
!=
null
)
{
sortOrder
=
select
.
getSortOrder
();
}
item
=
table
.
getBestPlanItem
(
s
,
masks
,
this
,
sortOrder
);
item
=
table
.
getBestPlanItem
(
s
,
masks
,
filters
,
filter
,
sortOrder
);
// The more index conditions, the earlier the table.
// This is to ensure joins without indexes run quickly:
// x (x.a=10); y (x.b=y.b) - see issue 113
item
.
cost
-=
item
.
cost
*
indexConditions
.
size
()
/
100
/
level
;
item
.
cost
-=
item
.
cost
*
indexConditions
.
size
()
/
100
/
(
filter
+
1
)
;
}
if
(
nestedJoin
!=
null
)
{
setEvaluatable
(
nestedJoin
);
item
.
setNestedJoinPlan
(
nestedJoin
.
getBestPlanItem
(
s
,
level
));
item
.
setNestedJoinPlan
(
nestedJoin
.
getBestPlanItem
(
s
,
filters
,
filter
));
// TODO optimizer: calculate cost of a join: should use separate
// expected row number and lookup cost
item
.
cost
+=
item
.
cost
*
item
.
getNestedJoinPlan
().
cost
;
}
if
(
join
!=
null
)
{
setEvaluatable
(
join
);
item
.
setJoinPlan
(
join
.
getBestPlanItem
(
s
,
level
));
filter
+=
nestedJoin
==
null
?
1
:
2
;
assert
filters
[
filter
]
==
join
;
item
.
setJoinPlan
(
join
.
getBestPlanItem
(
s
,
filters
,
filter
));
// TODO optimizer: calculate cost of a join: should use separate
// expected row number and lookup cost
item
.
cost
+=
item
.
cost
*
item
.
getJoinPlan
().
cost
;
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
13fd5a10
...
...
@@ -225,9 +225,9 @@ public class TableView extends Table {
@Override
public
PlanItem
getBestPlanItem
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
PlanItem
item
=
new
PlanItem
();
item
.
cost
=
index
.
getCost
(
session
,
masks
,
filter
,
sortOrder
);
item
.
cost
=
index
.
getCost
(
session
,
masks
,
filter
s
,
filter
,
sortOrder
);
final
CacheKey
cacheKey
=
new
CacheKey
(
masks
,
session
);
synchronized
(
this
)
{
...
...
@@ -434,7 +434,7 @@ public class TableView extends Table {
throw
DbException
.
get
(
ErrorCode
.
VIEW_IS_INVALID_2
,
createException
,
getSQL
(),
msg
);
}
PlanItem
item
=
getBestPlanItem
(
session
,
null
,
null
,
null
);
PlanItem
item
=
getBestPlanItem
(
session
,
null
,
null
,
-
1
,
null
);
return
item
.
getIndex
();
}
...
...
h2/src/test/org/h2/test/db/TestTableEngines.java
浏览文件 @
13fd5a10
...
...
@@ -660,7 +660,7 @@ public class TestTableEngines extends TestBase {
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
0
;
}
...
...
@@ -914,8 +914,8 @@ public class TestTableEngines extends TestBase {
TreeSetIndex
scan
=
new
TreeSetIndex
(
this
,
"scan"
,
IndexColumn
.
wrap
(
getColumns
()),
IndexType
.
createScan
(
false
))
{
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
getRowCount
(
session
)
+
Constants
.
COST_ROW_OFFSET
;
}
};
...
...
@@ -1204,9 +1204,10 @@ public class TestTableEngines extends TestBase {
}
@Override
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
filter
,
SortOrder
sortOrder
)
{
return
getCostRangeIndex
(
masks
,
set
.
size
(),
filter
,
sortOrder
);
public
double
getCost
(
Session
session
,
int
[]
masks
,
TableFilter
[]
filters
,
int
filter
,
SortOrder
sortOrder
)
{
return
getCostRangeIndex
(
masks
,
set
.
size
(),
filters
==
null
?
null
:
filters
[
filter
],
sortOrder
);
}
@Override
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论