Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
129a021d
提交
129a021d
authored
11月 30, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new experimental page store
上级
f1c816b8
显示空白字符变更
内嵌
并排
正在显示
15 个修改的文件
包含
104 行增加
和
18 行删除
+104
-18
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+1
-1
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+0
-5
BtreeIndex.java
h2/src/main/org/h2/index/BtreeIndex.java
+9
-0
FunctionIndex.java
h2/src/main/org/h2/index/FunctionIndex.java
+9
-1
HashIndex.java
h2/src/main/org/h2/index/HashIndex.java
+9
-0
Index.java
h2/src/main/org/h2/index/Index.java
+7
-0
LinkedIndex.java
h2/src/main/org/h2/index/LinkedIndex.java
+9
-0
MetaIndex.java
h2/src/main/org/h2/index/MetaIndex.java
+10
-2
MultiVersionIndex.java
h2/src/main/org/h2/index/MultiVersionIndex.java
+4
-0
PageDataLeaf.java
h2/src/main/org/h2/index/PageDataLeaf.java
+0
-4
PageScanIndex.java
h2/src/main/org/h2/index/PageScanIndex.java
+12
-1
RangeIndex.java
h2/src/main/org/h2/index/RangeIndex.java
+8
-0
ScanIndex.java
h2/src/main/org/h2/index/ScanIndex.java
+8
-3
TreeIndex.java
h2/src/main/org/h2/index/TreeIndex.java
+10
-1
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+8
-0
没有找到文件。
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
129a021d
...
@@ -229,7 +229,7 @@ public class ScriptCommand extends ScriptBase {
...
@@ -229,7 +229,7 @@ public class ScriptCommand extends ScriptBase {
add
(
sql
,
false
);
add
(
sql
,
false
);
if
(
Table
.
TABLE
.
equals
(
tableType
))
{
if
(
Table
.
TABLE
.
equals
(
tableType
))
{
if
(
table
.
canGetRowCount
())
{
if
(
table
.
canGetRowCount
())
{
String
rowcount
=
"-- "
+
table
.
getRowCount
(
session
)
+
" =
SELECT COUNT(*) FROM "
String
rowcount
=
"-- "
+
table
.
getRowCount
Approximation
()
+
" +/-
SELECT COUNT(*) FROM "
+
table
.
getSQL
();
+
table
.
getSQL
();
add
(
rowcount
,
false
);
add
(
rowcount
,
false
);
}
}
...
...
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
129a021d
...
@@ -36,7 +36,6 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -36,7 +36,6 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
protected
int
[]
columnIds
;
protected
int
[]
columnIds
;
protected
Table
table
;
protected
Table
table
;
protected
IndexType
indexType
;
protected
IndexType
indexType
;
protected
long
rowCount
;
protected
boolean
isMultiVersion
;
protected
boolean
isMultiVersion
;
/**
/**
...
@@ -179,10 +178,6 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
...
@@ -179,10 +178,6 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
throw
Message
.
getInternalError
();
throw
Message
.
getInternalError
();
}
}
public
long
getRowCount
(
Session
session
)
{
return
rowCount
;
}
public
int
getLookupCost
(
long
rowCount
)
{
public
int
getLookupCost
(
long
rowCount
)
{
return
2
;
return
2
;
}
}
...
...
h2/src/main/org/h2/index/BtreeIndex.java
浏览文件 @
129a021d
...
@@ -54,6 +54,7 @@ public class BtreeIndex extends BaseIndex implements RecordReader {
...
@@ -54,6 +54,7 @@ public class BtreeIndex extends BaseIndex implements RecordReader {
private
boolean
needRebuild
;
private
boolean
needRebuild
;
private
int
headPos
;
private
int
headPos
;
private
long
lastChange
;
private
long
lastChange
;
private
long
rowCount
;
/**
/**
* Create a new b tree index with the given properties. If the index does
* Create a new b tree index with the given properties. If the index does
...
@@ -424,4 +425,12 @@ public class BtreeIndex extends BaseIndex implements RecordReader {
...
@@ -424,4 +425,12 @@ public class BtreeIndex extends BaseIndex implements RecordReader {
return
cursor
;
return
cursor
;
}
}
public
long
getRowCount
(
Session
session
)
{
return
rowCount
;
}
public
long
getRowCountApproximation
()
{
return
rowCount
;
}
}
}
h2/src/main/org/h2/index/FunctionIndex.java
浏览文件 @
129a021d
...
@@ -56,7 +56,7 @@ public class FunctionIndex extends BaseIndex {
...
@@ -56,7 +56,7 @@ public class FunctionIndex extends BaseIndex {
}
}
long
expectedRows
;
long
expectedRows
;
if
(
functionTable
.
canGetRowCount
())
{
if
(
functionTable
.
canGetRowCount
())
{
expectedRows
=
functionTable
.
getRowCount
(
session
);
expectedRows
=
functionTable
.
getRowCount
Approximation
(
);
}
else
{
}
else
{
expectedRows
=
SysProperties
.
ESTIMATED_FUNCTION_TABLE_ROWS
;
expectedRows
=
SysProperties
.
ESTIMATED_FUNCTION_TABLE_ROWS
;
}
}
...
@@ -87,4 +87,12 @@ public class FunctionIndex extends BaseIndex {
...
@@ -87,4 +87,12 @@ public class FunctionIndex extends BaseIndex {
throw
Message
.
getUnsupportedException
();
throw
Message
.
getUnsupportedException
();
}
}
public
long
getRowCount
(
Session
session
)
{
return
functionTable
.
getRowCount
(
session
);
}
public
long
getRowCountApproximation
()
{
return
functionTable
.
getRowCountApproximation
();
}
}
}
h2/src/main/org/h2/index/HashIndex.java
浏览文件 @
129a021d
...
@@ -29,6 +29,7 @@ public class HashIndex extends BaseIndex {
...
@@ -29,6 +29,7 @@ public class HashIndex extends BaseIndex {
private
ValueHashMap
rows
;
private
ValueHashMap
rows
;
private
IntIntHashMap
intMap
;
private
IntIntHashMap
intMap
;
private
TableData
tableData
;
private
TableData
tableData
;
private
long
rowCount
;
public
HashIndex
(
TableData
table
,
int
id
,
String
indexName
,
IndexColumn
[]
columns
,
IndexType
indexType
)
{
public
HashIndex
(
TableData
table
,
int
id
,
String
indexName
,
IndexColumn
[]
columns
,
IndexType
indexType
)
{
initBaseIndex
(
table
,
id
,
indexName
,
columns
,
indexType
);
initBaseIndex
(
table
,
id
,
indexName
,
columns
,
indexType
);
...
@@ -152,4 +153,12 @@ public class HashIndex extends BaseIndex {
...
@@ -152,4 +153,12 @@ public class HashIndex extends BaseIndex {
throw
Message
.
getUnsupportedException
();
throw
Message
.
getUnsupportedException
();
}
}
public
long
getRowCount
(
Session
session
)
{
return
rowCount
;
}
public
long
getRowCountApproximation
()
{
return
rowCount
;
}
}
}
h2/src/main/org/h2/index/Index.java
浏览文件 @
129a021d
...
@@ -151,6 +151,13 @@ public interface Index extends SchemaObject {
...
@@ -151,6 +151,13 @@ public interface Index extends SchemaObject {
*/
*/
long
getRowCount
(
Session
session
);
long
getRowCount
(
Session
session
);
/**
* Get the approximated row count for this table.
*
* @return the approximated row count
*/
long
getRowCountApproximation
();
/**
/**
* Estimate the cost required to search a number of rows.
* Estimate the cost required to search a number of rows.
*
*
...
...
h2/src/main/org/h2/index/LinkedIndex.java
浏览文件 @
129a021d
...
@@ -30,6 +30,7 @@ public class LinkedIndex extends BaseIndex {
...
@@ -30,6 +30,7 @@ public class LinkedIndex extends BaseIndex {
private
TableLink
link
;
private
TableLink
link
;
private
String
targetTableName
;
private
String
targetTableName
;
private
long
rowCount
;
public
LinkedIndex
(
TableLink
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
)
{
public
LinkedIndex
(
TableLink
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
)
{
initBaseIndex
(
table
,
id
,
null
,
columns
,
indexType
);
initBaseIndex
(
table
,
id
,
null
,
columns
,
indexType
);
...
@@ -285,4 +286,12 @@ public class LinkedIndex extends BaseIndex {
...
@@ -285,4 +286,12 @@ public class LinkedIndex extends BaseIndex {
return
Message
.
getSQLException
(
ErrorCode
.
ERROR_ACCESSING_LINKED_TABLE_2
,
new
String
[]
{
sql
,
e
.
toString
()
},
e
);
return
Message
.
getSQLException
(
ErrorCode
.
ERROR_ACCESSING_LINKED_TABLE_2
,
new
String
[]
{
sql
,
e
.
toString
()
},
e
);
}
}
public
long
getRowCount
(
Session
session
)
{
return
rowCount
;
}
public
long
getRowCountApproximation
()
{
return
rowCount
;
}
}
}
h2/src/main/org/h2/index/MetaIndex.java
浏览文件 @
129a021d
...
@@ -49,9 +49,9 @@ public class MetaIndex extends BaseIndex {
...
@@ -49,9 +49,9 @@ public class MetaIndex extends BaseIndex {
public
double
getCost
(
Session
session
,
int
[]
masks
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
)
{
if
(
scan
)
{
if
(
scan
)
{
return
10
000
;
return
10
*
MetaTable
.
ROW_COUNT_APPROXIMATION
;
}
}
return
getCostRangeIndex
(
masks
,
1000
);
return
getCostRangeIndex
(
masks
,
MetaTable
.
ROW_COUNT_APPROXIMATION
);
}
}
public
void
truncate
(
Session
session
)
throws
SQLException
{
public
void
truncate
(
Session
session
)
throws
SQLException
{
...
@@ -90,4 +90,12 @@ public class MetaIndex extends BaseIndex {
...
@@ -90,4 +90,12 @@ public class MetaIndex extends BaseIndex {
throw
Message
.
getUnsupportedException
();
throw
Message
.
getUnsupportedException
();
}
}
public
long
getRowCount
(
Session
session
)
{
return
MetaTable
.
ROW_COUNT_APPROXIMATION
;
}
public
long
getRowCountApproximation
()
{
return
MetaTable
.
ROW_COUNT_APPROXIMATION
;
}
}
}
h2/src/main/org/h2/index/MultiVersionIndex.java
浏览文件 @
129a021d
...
@@ -308,4 +308,8 @@ public class MultiVersionIndex implements Index {
...
@@ -308,4 +308,8 @@ public class MultiVersionIndex implements Index {
base
.
setTemporary
(
temporary
);
base
.
setTemporary
(
temporary
);
}
}
public
long
getRowCountApproximation
()
{
return
base
.
getRowCountApproximation
();
}
}
}
h2/src/main/org/h2/index/PageDataLeaf.java
浏览文件 @
129a021d
...
@@ -240,10 +240,6 @@ class PageDataLeaf extends PageData {
...
@@ -240,10 +240,6 @@ class PageDataLeaf extends PageData {
* @return the row
* @return the row
*/
*/
Row
getRowAt
(
int
at
)
throws
SQLException
{
Row
getRowAt
(
int
at
)
throws
SQLException
{
if
(
at
>=
rows
.
length
)
{
int
test
;
System
.
out
.
println
(
"test"
);
}
Row
r
=
rows
[
at
];
Row
r
=
rows
[
at
];
if
(
r
==
null
)
{
if
(
r
==
null
)
{
if
(
firstOverflowPageId
!=
0
)
{
if
(
firstOverflowPageId
!=
0
)
{
...
...
h2/src/main/org/h2/index/PageScanIndex.java
浏览文件 @
129a021d
...
@@ -38,6 +38,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -38,6 +38,8 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
// TODO use an undo log and maybe redo log (for performance)
// TODO use an undo log and maybe redo log (for performance)
// TODO file position, content checksums
// TODO file position, content checksums
private
int
nextKey
;
private
int
nextKey
;
private
long
rowCount
;
private
long
rowCountApproximation
;
public
PageScanIndex
(
TableData
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
,
int
headPos
)
throws
SQLException
{
public
PageScanIndex
(
TableData
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
,
int
headPos
)
throws
SQLException
{
initBaseIndex
(
table
,
id
,
table
.
getName
()
+
"_TABLE_SCAN"
,
columns
,
indexType
);
initBaseIndex
(
table
,
id
,
table
.
getName
()
+
"_TABLE_SCAN"
,
columns
,
indexType
);
...
@@ -137,7 +139,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -137,7 +139,7 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
}
}
public
double
getCost
(
Session
session
,
int
[]
masks
)
throws
SQLException
{
public
double
getCost
(
Session
session
,
int
[]
masks
)
throws
SQLException
{
long
cost
=
10
*
tableData
.
getRowCount
(
session
)
+
Constants
.
COST_ROW_OFFSET
;
long
cost
=
10
*
tableData
.
getRowCount
Approximation
(
)
+
Constants
.
COST_ROW_OFFSET
;
return
cost
;
return
cost
;
}
}
...
@@ -192,4 +194,13 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
...
@@ -192,4 +194,13 @@ public class PageScanIndex extends BaseIndex implements RowIndex {
return
tableData
.
readRow
(
data
);
return
tableData
.
readRow
(
data
);
}
}
public
long
getRowCountApproximation
()
{
return
rowCountApproximation
;
}
public
long
getRowCount
(
Session
session
)
{
int
todo
;
return
rowCount
;
}
}
}
h2/src/main/org/h2/index/RangeIndex.java
浏览文件 @
129a021d
...
@@ -81,4 +81,12 @@ public class RangeIndex extends BaseIndex {
...
@@ -81,4 +81,12 @@ public class RangeIndex extends BaseIndex {
return
new
RangeCursor
(
pos
,
pos
);
return
new
RangeCursor
(
pos
,
pos
);
}
}
public
long
getRowCount
(
Session
session
)
{
return
rangeTable
.
getRowCountApproximation
();
}
public
long
getRowCountApproximation
()
{
return
rangeTable
.
getRowCountApproximation
();
}
}
}
h2/src/main/org/h2/index/ScanIndex.java
浏览文件 @
129a021d
...
@@ -41,6 +41,7 @@ public class ScanIndex extends BaseIndex implements RowIndex {
...
@@ -41,6 +41,7 @@ public class ScanIndex extends BaseIndex implements RowIndex {
private
int
rowCountDiff
;
private
int
rowCountDiff
;
private
HashMap
sessionRowCount
;
private
HashMap
sessionRowCount
;
private
HashSet
delta
;
private
HashSet
delta
;
private
long
rowCount
;
public
ScanIndex
(
TableData
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
)
{
public
ScanIndex
(
TableData
table
,
int
id
,
IndexColumn
[]
columns
,
IndexType
indexType
)
{
initBaseIndex
(
table
,
id
,
table
.
getName
()
+
"_TABLE_SCAN"
,
columns
,
indexType
);
initBaseIndex
(
table
,
id
,
table
.
getName
()
+
"_TABLE_SCAN"
,
columns
,
indexType
);
...
@@ -201,7 +202,7 @@ public class ScanIndex extends BaseIndex implements RowIndex {
...
@@ -201,7 +202,7 @@ public class ScanIndex extends BaseIndex implements RowIndex {
}
}
public
double
getCost
(
Session
session
,
int
[]
masks
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
)
{
long
cost
=
tableData
.
getRowCount
(
session
)
+
Constants
.
COST_ROW_OFFSET
;
long
cost
=
tableData
.
getRowCount
Approximation
(
)
+
Constants
.
COST_ROW_OFFSET
;
if
(
storage
!=
null
)
{
if
(
storage
!=
null
)
{
cost
*=
10
;
cost
*=
10
;
}
}
...
@@ -212,11 +213,11 @@ public class ScanIndex extends BaseIndex implements RowIndex {
...
@@ -212,11 +213,11 @@ public class ScanIndex extends BaseIndex implements RowIndex {
if
(
database
.
isMultiVersion
())
{
if
(
database
.
isMultiVersion
())
{
Integer
i
=
(
Integer
)
sessionRowCount
.
get
(
ObjectUtils
.
getInteger
(
session
.
getId
()));
Integer
i
=
(
Integer
)
sessionRowCount
.
get
(
ObjectUtils
.
getInteger
(
session
.
getId
()));
long
count
=
i
==
null
?
0
:
i
.
intValue
();
long
count
=
i
==
null
?
0
:
i
.
intValue
();
count
+=
super
.
getRowCount
(
session
)
;
count
+=
rowCount
;
count
-=
rowCountDiff
;
count
-=
rowCountDiff
;
return
count
;
return
count
;
}
}
return
super
.
getRowCount
(
session
)
;
return
rowCount
;
}
}
/**
/**
...
@@ -277,4 +278,8 @@ public class ScanIndex extends BaseIndex implements RowIndex {
...
@@ -277,4 +278,8 @@ public class ScanIndex extends BaseIndex implements RowIndex {
return
delta
==
null
?
Collections
.
EMPTY_LIST
.
iterator
()
:
delta
.
iterator
();
return
delta
==
null
?
Collections
.
EMPTY_LIST
.
iterator
()
:
delta
.
iterator
();
}
}
public
long
getRowCountApproximation
()
{
return
rowCount
;
}
}
}
h2/src/main/org/h2/index/TreeIndex.java
浏览文件 @
129a021d
...
@@ -25,6 +25,7 @@ public class TreeIndex extends BaseIndex {
...
@@ -25,6 +25,7 @@ public class TreeIndex extends BaseIndex {
private
TreeNode
root
;
private
TreeNode
root
;
private
TableData
tableData
;
private
TableData
tableData
;
private
long
rowCount
;
public
TreeIndex
(
TableData
table
,
int
id
,
String
indexName
,
IndexColumn
[]
columns
,
IndexType
indexType
)
{
public
TreeIndex
(
TableData
table
,
int
id
,
String
indexName
,
IndexColumn
[]
columns
,
IndexType
indexType
)
{
initBaseIndex
(
table
,
id
,
indexName
,
columns
,
indexType
);
initBaseIndex
(
table
,
id
,
indexName
,
columns
,
indexType
);
...
@@ -293,7 +294,7 @@ public class TreeIndex extends BaseIndex {
...
@@ -293,7 +294,7 @@ public class TreeIndex extends BaseIndex {
}
}
public
double
getCost
(
Session
session
,
int
[]
masks
)
{
public
double
getCost
(
Session
session
,
int
[]
masks
)
{
return
getCostRangeIndex
(
masks
,
tableData
.
getRowCount
(
session
));
return
getCostRangeIndex
(
masks
,
tableData
.
getRowCount
Approximation
(
));
}
}
public
void
remove
(
Session
session
)
{
public
void
remove
(
Session
session
)
{
...
@@ -414,4 +415,12 @@ public class TreeIndex extends BaseIndex {
...
@@ -414,4 +415,12 @@ public class TreeIndex extends BaseIndex {
return
cursor
;
return
cursor
;
}
}
public
long
getRowCount
(
Session
session
)
{
return
rowCount
;
}
public
long
getRowCountApproximation
()
{
return
rowCount
;
}
}
}
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
129a021d
...
@@ -265,4 +265,12 @@ public class ViewIndex extends BaseIndex {
...
@@ -265,4 +265,12 @@ public class ViewIndex extends BaseIndex {
this
.
recursive
=
value
;
this
.
recursive
=
value
;
}
}
public
long
getRowCount
(
Session
session
)
{
return
0
;
}
public
long
getRowCountApproximation
()
{
return
0
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论