Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
18808fa8
提交
18808fa8
authored
12月 13, 2012
作者:
noelgrandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a DISK_SPACE_USED system function. Fixes issue 270.
上级
cf7ee9c5
隐藏空白字符变更
内嵌
并排
正在显示
33 个修改的文件
包含
175 行增加
和
3 行删除
+175
-3
help.csv
h2/src/docsrc/help/help.csv
+10
-0
changelog.html
h2/src/docsrc/html/changelog.html
+1
-0
Parser.java
h2/src/main/org/h2/command/Parser.java
+12
-0
Function.java
h2/src/main/org/h2/expression/Function.java
+13
-1
FunctionIndex.java
h2/src/main/org/h2/index/FunctionIndex.java
+4
-0
HashIndex.java
h2/src/main/org/h2/index/HashIndex.java
+4
-0
Index.java
h2/src/main/org/h2/index/Index.java
+5
-0
LinkedIndex.java
h2/src/main/org/h2/index/LinkedIndex.java
+3
-0
MetaIndex.java
h2/src/main/org/h2/index/MetaIndex.java
+4
-0
MultiVersionIndex.java
h2/src/main/org/h2/index/MultiVersionIndex.java
+4
-0
PageBtreeIndex.java
h2/src/main/org/h2/index/PageBtreeIndex.java
+4
-0
PageData.java
h2/src/main/org/h2/index/PageData.java
+6
-1
PageDataIndex.java
h2/src/main/org/h2/index/PageDataIndex.java
+5
-0
PageDataLeaf.java
h2/src/main/org/h2/index/PageDataLeaf.java
+4
-0
PageDataNode.java
h2/src/main/org/h2/index/PageDataNode.java
+16
-1
PageDelegateIndex.java
h2/src/main/org/h2/index/PageDelegateIndex.java
+4
-0
RangeIndex.java
h2/src/main/org/h2/index/RangeIndex.java
+3
-0
ScanIndex.java
h2/src/main/org/h2/index/ScanIndex.java
+4
-0
TreeIndex.java
h2/src/main/org/h2/index/TreeIndex.java
+4
-0
ViewIndex.java
h2/src/main/org/h2/index/ViewIndex.java
+4
-0
MVDelegateIndex.java
h2/src/main/org/h2/mvstore/db/MVDelegateIndex.java
+4
-0
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+4
-0
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+4
-0
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+4
-0
FunctionTable.java
h2/src/main/org/h2/table/FunctionTable.java
+4
-0
MetaTable.java
h2/src/main/org/h2/table/MetaTable.java
+4
-0
RangeTable.java
h2/src/main/org/h2/table/RangeTable.java
+4
-0
RegularTable.java
h2/src/main/org/h2/table/RegularTable.java
+5
-0
Table.java
h2/src/main/org/h2/table/Table.java
+2
-0
TableLink.java
h2/src/main/org/h2/table/TableLink.java
+4
-0
TableView.java
h2/src/main/org/h2/table/TableView.java
+4
-0
TestTableEngines.java
h2/src/test/org/h2/test/db/TestTableEngines.java
+8
-0
test-1.3.txt
h2/src/test/org/h2/test/test-1.3.txt
+10
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
18808fa8
...
...
@@ -3573,6 +3573,16 @@ This function is provided for Oracle compatibility (see there for details).
CALL DECODE(RAND()>0.5, 0, 'Red', 1, 'Black');
"
"Functions (System)","DISK_SPACE_USED","
DISK_SPACE_USED(tablename)
","
Returns the approximate amount of space used by the table specified.
Does not currently take into account indexes or LOB's.
This function may be expensive since it has to load every page in the table.
","
CALL DISK_SPACE_USED('my_table');
"
"Functions (System)","FILE_READ","
FILE_READ(fileNameString [,encodingString])
","
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
18808fa8
...
...
@@ -36,6 +36,7 @@ Change Log
</ul><li>
Support ALTER TABLE ADD ... AFTER. Patch from Andrew Gaul (argaul at gmail.com). Fixes issue 401.
</ul><li>
support "SELECT version()". Patch from Andrew Gaul. Fixes issue 406.
</ul><li>
Improved OSGi support. H2 now registers itself as a DataSourceFactory service. Fixes issue 365.
</ul><li>
Add a DISK_SPACE_USED system function. Fixes issue 270.
</li></ul>
<h2>
Version 1.3.170 (2012-11-30)
</h2>
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
18808fa8
...
...
@@ -5379,4 +5379,16 @@ public class Parser {
return
readExpression
();
}
/**
* Parse a SQL code snippet that represents a table name.
*
* @param sql the code snippet
* @return the table object
*/
public
Table
parseTableName
(
String
sql
)
{
parameters
=
New
.
arrayList
();
initialize
(
sql
);
read
();
return
readTableOrView
();
}
}
h2/src/main/org/h2/expression/Function.java
浏览文件 @
18808fa8
...
...
@@ -40,6 +40,7 @@ import org.h2.store.fs.FileUtils;
import
org.h2.table.Column
;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.LinkSchema
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
import
org.h2.tools.CompressTool
;
import
org.h2.tools.Csv
;
...
...
@@ -92,7 +93,7 @@ public class Function extends Expression implements FunctionCall {
ISO_YEAR
=
123
,
ISO_WEEK
=
124
,
ISO_DAY_OF_WEEK
=
125
;
public
static
final
int
DATABASE
=
150
,
USER
=
151
,
CURRENT_USER
=
152
,
IDENTITY
=
153
,
SCOPE_IDENTITY
=
154
,
AUTOCOMMIT
=
155
,
READONLY
=
156
,
DATABASE_PATH
=
157
,
LOCK_TIMEOUT
=
158
;
AUTOCOMMIT
=
155
,
READONLY
=
156
,
DATABASE_PATH
=
157
,
LOCK_TIMEOUT
=
158
,
DISK_SPACE_USED
=
159
;
public
static
final
int
IFNULL
=
200
,
CASEWHEN
=
201
,
CONVERT
=
202
,
CAST
=
203
,
COALESCE
=
204
,
NULLIF
=
205
,
CASE
=
206
,
NEXTVAL
=
207
,
CURRVAL
=
208
,
ARRAY_GET
=
209
,
CSVREAD
=
210
,
CSVWRITE
=
211
,
...
...
@@ -346,6 +347,7 @@ public class Function extends Expression implements FunctionCall {
addFunctionNotDeterministic
(
"TRANSACTION_ID"
,
TRANSACTION_ID
,
0
,
Value
.
STRING
);
addFunctionWithNull
(
"DECODE"
,
DECODE
,
VAR_ARGS
,
Value
.
NULL
);
addFunction
(
"VERSION"
,
VERSION
,
0
,
Value
.
STRING
);
addFunctionNotDeterministic
(
"DISK_SPACE_USED"
,
DISK_SPACE_USED
,
1
,
Value
.
LONG
);
// TableFunction
addFunctionWithNull
(
"TABLE"
,
TABLE
,
VAR_ARGS
,
Value
.
RESULT_SET
);
...
...
@@ -760,6 +762,9 @@ public class Function extends Expression implements FunctionCall {
case
LOCK_TIMEOUT:
result
=
ValueInt
.
get
(
session
.
getLockTimeout
());
break
;
case
DISK_SPACE_USED:
result
=
ValueLong
.
get
(
getDiskSpaceUsed
(
session
,
v0
));
break
;
case
CAST:
case
CONVERT:
{
v0
=
v0
.
convertTo
(
dataType
);
...
...
@@ -942,6 +947,13 @@ public class Function extends Expression implements FunctionCall {
return
false
;
}
private
static
long
getDiskSpaceUsed
(
Session
session
,
Value
v0
)
{
Parser
p
=
new
Parser
(
session
);
String
sql
=
v0
.
getString
();
Table
table
=
p
.
parseTableName
(
sql
);
return
table
.
getDiskSpaceUsed
();
}
private
static
Value
getNullOrValue
(
Session
session
,
Expression
[]
args
,
Value
[]
values
,
int
i
)
{
if
(
i
>=
args
.
length
)
{
return
null
;
...
...
h2/src/main/org/h2/index/FunctionIndex.java
浏览文件 @
18808fa8
...
...
@@ -90,6 +90,10 @@ public class FunctionIndex extends BaseIndex {
return
functionTable
.
getRowCountApproximation
();
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
public
String
getPlanSQL
()
{
return
"function"
;
}
...
...
h2/src/main/org/h2/index/HashIndex.java
浏览文件 @
18808fa8
...
...
@@ -81,6 +81,10 @@ public class HashIndex extends BaseIndex {
return
rows
.
size
();
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
public
void
close
(
Session
session
)
{
// nothing to do
}
...
...
h2/src/main/org/h2/index/Index.java
浏览文件 @
18808fa8
...
...
@@ -156,6 +156,11 @@ public interface Index extends SchemaObject {
*/
long
getRowCountApproximation
();
/**
* @return the estimated number of bytes of disk space used by this page and all child pages.
*/
long
getDiskSpaceUsed
();
/**
* Compare two rows.
*
...
...
h2/src/main/org/h2/index/LinkedIndex.java
浏览文件 @
18808fa8
...
...
@@ -246,4 +246,7 @@ public class LinkedIndex extends BaseIndex {
return
rowCount
;
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
}
h2/src/main/org/h2/index/MetaIndex.java
浏览文件 @
18808fa8
...
...
@@ -97,6 +97,10 @@ public class MetaIndex extends BaseIndex {
return
MetaTable
.
ROW_COUNT_APPROXIMATION
;
}
public
long
getDiskSpaceUsed
()
{
return
meta
.
getDiskSpaceUsed
();
}
public
String
getPlanSQL
()
{
return
"meta"
;
}
...
...
h2/src/main/org/h2/index/MultiVersionIndex.java
浏览文件 @
18808fa8
...
...
@@ -302,6 +302,10 @@ public class MultiVersionIndex implements Index {
return
base
.
getRowCountApproximation
();
}
public
long
getDiskSpaceUsed
()
{
return
base
.
getDiskSpaceUsed
();
}
public
Index
getBaseIndex
()
{
return
base
;
}
...
...
h2/src/main/org/h2/index/PageBtreeIndex.java
浏览文件 @
18808fa8
...
...
@@ -300,6 +300,10 @@ public class PageBtreeIndex extends PageIndex {
return
tableData
.
getRowCountApproximation
();
}
public
long
getDiskSpaceUsed
()
{
return
tableData
.
getDiskSpaceUsed
();
}
public
long
getRowCount
(
Session
session
)
{
return
rowCount
;
}
...
...
h2/src/main/org/h2/index/PageData.java
浏览文件 @
18808fa8
...
...
@@ -88,6 +88,11 @@ abstract class PageData extends Page {
*/
abstract
void
setRowCountStored
(
int
rowCount
);
/**
* @return the estimated number of bytes of disk space used by this page and all child pages.
*/
abstract
long
getDiskSpaceUsed
();
/**
* Find an entry by key.
*
...
...
@@ -229,7 +234,7 @@ abstract class PageData extends Page {
// to how much memory a row needs on average
return
memoryEstimated
;
}
int
getParentPageId
()
{
return
parentPageId
;
}
...
...
h2/src/main/org/h2/index/PageDataIndex.java
浏览文件 @
18808fa8
...
...
@@ -427,6 +427,11 @@ public class PageDataIndex extends PageIndex {
return
rowCount
;
}
public
long
getDiskSpaceUsed
()
{
PageData
root
=
getPage
(
rootPageId
,
0
);
return
root
.
getDiskSpaceUsed
();
}
public
String
getCreateSQL
()
{
return
null
;
}
...
...
h2/src/main/org/h2/index/PageDataLeaf.java
浏览文件 @
18808fa8
...
...
@@ -451,6 +451,10 @@ public class PageDataLeaf extends PageData {
// ignore
}
long
getDiskSpaceUsed
()
{
return
index
.
getPageStore
().
getPageSize
();
}
public
void
write
()
{
writeData
();
index
.
getPageStore
().
writePage
(
getPos
(),
data
);
...
...
h2/src/main/org/h2/index/PageDataNode.java
浏览文件 @
18808fa8
...
...
@@ -277,7 +277,7 @@ public class PageDataNode extends PageData {
int
child
=
childPageIds
[
i
];
PageData
page
=
index
.
getPage
(
child
,
getPos
());
if
(
getPos
()
==
page
.
getPos
())
{
throw
DbException
.
throwInternalError
(
"Page i
t
its own child: "
+
getPos
());
throw
DbException
.
throwInternalError
(
"Page i
s
its own child: "
+
getPos
());
}
count
+=
page
.
getRowCount
();
index
.
getDatabase
().
setProgress
(
DatabaseEventListener
.
STATE_SCAN_FILE
,
...
...
@@ -288,6 +288,21 @@ public class PageDataNode extends PageData {
return
rowCount
;
}
long
getDiskSpaceUsed
()
{
long
count
=
0
;
for
(
int
i
=
0
;
i
<
entryCount
+
1
;
i
++)
{
int
child
=
childPageIds
[
i
];
PageData
page
=
index
.
getPage
(
child
,
getPos
());
if
(
getPos
()
==
page
.
getPos
())
{
throw
DbException
.
throwInternalError
(
"Page is its own child: "
+
getPos
());
}
count
+=
page
.
getDiskSpaceUsed
();
index
.
getDatabase
().
setProgress
(
DatabaseEventListener
.
STATE_SCAN_FILE
,
index
.
getTable
()
+
"."
+
index
.
getName
(),
(
int
)
(
count
>>
16
),
Integer
.
MAX_VALUE
);
}
return
count
;
}
void
setRowCountStored
(
int
rowCount
)
{
this
.
rowCount
=
rowCount
;
if
(
rowCountStored
!=
rowCount
)
{
...
...
h2/src/main/org/h2/index/PageDelegateIndex.java
浏览文件 @
18808fa8
...
...
@@ -117,6 +117,10 @@ public class PageDelegateIndex extends PageIndex {
return
mainIndex
.
getRowCountApproximation
();
}
public
long
getDiskSpaceUsed
()
{
return
mainIndex
.
getDiskSpaceUsed
();
}
public
void
writeRowCount
()
{
// ignore
}
...
...
h2/src/main/org/h2/index/RangeIndex.java
浏览文件 @
18808fa8
...
...
@@ -95,4 +95,7 @@ public class RangeIndex extends BaseIndex {
return
rangeTable
.
getRowCountApproximation
();
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
}
h2/src/main/org/h2/index/ScanIndex.java
浏览文件 @
18808fa8
...
...
@@ -232,6 +232,10 @@ public class ScanIndex extends BaseIndex {
return
rowCount
;
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
public
String
getPlanSQL
()
{
return
table
.
getSQL
()
+
".tableScan"
;
}
...
...
h2/src/main/org/h2/index/TreeIndex.java
浏览文件 @
18808fa8
...
...
@@ -383,4 +383,8 @@ public class TreeIndex extends BaseIndex {
return
rowCount
;
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
}
h2/src/main/org/h2/index/ViewIndex.java
浏览文件 @
18808fa8
...
...
@@ -375,6 +375,10 @@ public class ViewIndex extends BaseIndex {
return
0
;
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
public
boolean
isRecursive
()
{
return
recursive
;
}
...
...
h2/src/main/org/h2/mvstore/db/MVDelegateIndex.java
浏览文件 @
18808fa8
...
...
@@ -118,4 +118,8 @@ public class MVDelegateIndex extends BaseIndex {
return
mainIndex
.
getRowCountApproximation
();
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
}
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
18808fa8
...
...
@@ -187,6 +187,10 @@ public class MVPrimaryIndex extends BaseIndex {
return
map
.
getSize
();
}
public
long
getDiskSpaceUsed
()
{
return
0
;
// TODO
}
@Override
public
void
checkRename
()
{
// ok
...
...
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
18808fa8
...
...
@@ -150,6 +150,10 @@ public class MVSecondaryIndex extends BaseIndex {
return
map
.
getSize
();
}
public
long
getDiskSpaceUsed
()
{
return
0
;
// TODO
}
@Override
public
void
checkRename
()
{
// ok
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
18808fa8
...
...
@@ -418,6 +418,10 @@ public class MVTable extends TableBase {
return
primaryIndex
.
getRowCountApproximation
();
}
public
long
getDiskSpaceUsed
()
{
return
primaryIndex
.
getDiskSpaceUsed
();
}
@Override
public
void
checkRename
()
{
// ok
...
...
h2/src/main/org/h2/table/FunctionTable.java
浏览文件 @
18808fa8
...
...
@@ -216,6 +216,10 @@ public class FunctionTable extends Table {
public
long
getRowCountApproximation
()
{
return
rowCount
;
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
public
boolean
isDeterministic
()
{
return
function
.
isDeterministic
();
...
...
h2/src/main/org/h2/table/MetaTable.java
浏览文件 @
18808fa8
...
...
@@ -1801,6 +1801,10 @@ public class MetaTable extends Table {
return
ROW_COUNT_APPROXIMATION
;
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
public
boolean
isDeterministic
()
{
return
true
;
}
...
...
h2/src/main/org/h2/table/RangeTable.java
浏览文件 @
18808fa8
...
...
@@ -167,6 +167,10 @@ public class RangeTable extends Table {
return
100
;
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
public
boolean
isDeterministic
()
{
return
true
;
}
...
...
h2/src/main/org/h2/table/RegularTable.java
浏览文件 @
18808fa8
...
...
@@ -724,6 +724,11 @@ public class RegularTable extends TableBase {
public
long
getRowCountApproximation
()
{
return
scanIndex
.
getRowCountApproximation
();
}
@Override
public
long
getDiskSpaceUsed
()
{
return
scanIndex
.
getDiskSpaceUsed
();
}
public
void
setCompareMode
(
CompareMode
compareMode
)
{
this
.
compareMode
=
compareMode
;
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
18808fa8
...
...
@@ -293,6 +293,8 @@ public abstract class Table extends SchemaObjectBase {
*/
public
abstract
long
getRowCountApproximation
();
public
abstract
long
getDiskSpaceUsed
();
/**
* Get the row id column if this table has one.
*
...
...
h2/src/main/org/h2/table/TableLink.java
浏览文件 @
18808fa8
...
...
@@ -598,6 +598,10 @@ public class TableLink extends Table {
return
ROW_COUNT_APPROXIMATION
;
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
/**
* Add this prepared statement to the list of cached statements.
*
...
...
h2/src/main/org/h2/table/TableView.java
浏览文件 @
18808fa8
...
...
@@ -437,6 +437,10 @@ public class TableView extends Table {
return
ROW_COUNT_APPROXIMATION
;
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
public
int
getParameterOffset
()
{
return
topQuery
==
null
?
0
:
topQuery
.
getParameters
().
size
();
}
...
...
h2/src/test/org/h2/test/db/TestTableEngines.java
浏览文件 @
18808fa8
...
...
@@ -148,6 +148,10 @@ public class TestTableEngines extends TestBase {
return
table
.
getRowCountApproximation
();
}
public
long
getDiskSpaceUsed
()
{
return
table
.
getDiskSpaceUsed
();
}
public
long
getRowCount
(
Session
session
)
{
return
table
.
getRowCount
(
session
);
}
...
...
@@ -257,6 +261,10 @@ public class TestTableEngines extends TestBase {
return
row
==
null
?
0
:
1
;
}
public
long
getDiskSpaceUsed
()
{
return
0
;
}
@Override
public
Index
getScanIndex
(
Session
session
)
{
return
scanIndex
;
...
...
h2/src/test/org/h2/test/test-1.3.txt
浏览文件 @
18808fa8
...
...
@@ -9972,3 +9972,13 @@ select * from word;
drop table word;
> ok
create table test(id int, name varchar);
> ok
insert into test values(5, 'b'), (5, 'b'), (20, 'a');
> update count: 3
CALL DISK_SPACE_USED('test');
> DISK_SPACE_USED('test')
> -----------------------
> 2048
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论