Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
0001e98d
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0001e98d
编写于
8月 02, 2005
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Code and docs review for pg_column_size() patch.
上级
f023fc66
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
130 addition
and
108 deletion
+130
-108
doc/src/sgml/func.sgml
doc/src/sgml/func.sgml
+65
-44
src/backend/access/heap/tuptoaster.c
src/backend/access/heap/tuptoaster.c
+33
-43
src/backend/utils/adt/varlena.c
src/backend/utils/adt/varlena.c
+30
-19
src/include/catalog/pg_proc.h
src/include/catalog/pg_proc.h
+2
-2
未找到文件。
doc/src/sgml/func.sgml
浏览文件 @
0001e98d
<!--
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.27
5 2005/07/30 22:53:15
tgl Exp $
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.27
6 2005/08/02 16:11:56
tgl Exp $
PostgreSQL documentation
-->
...
...
@@ -2206,14 +2206,6 @@ PostgreSQL documentation
<entry><literal>5</literal></entry>
</row>
<row>
<entry><literal><function>pg_column_size</function>(<parameter>string</parameter>)</literal></entry>
<entry><type>integer</type></entry>
<entry>Number of bytes required to store the value, which might be compressed</entry>
<entry><literal>pg_column_size('jo\\000se'::bytea)</literal></entry>
<entry><literal>5</literal></entry>
</row>
<row>
<entry><literal><function>position</function>(<parameter>substring</parameter> in <parameter>string</parameter>)</literal></entry>
<entry><type>integer</type></entry>
...
...
@@ -9181,11 +9173,29 @@ SELECT set_config('log_statement_stats', 'off', false);
</para>
<para>
The functions shown in <xref
linkend="functions-admin-dbsize"> calculate the actual disk space
usage of database objects.
The functions shown in <xref linkend="functions-admin-dbsize"> calculate
the actual disk space usage of database objects.
</para>
<indexterm zone="functions-admin">
<primary>pg_column_size</primary>
</indexterm>
<indexterm zone="functions-admin">
<primary>pg_tablespace_size</primary>
</indexterm>
<indexterm zone="functions-admin">
<primary>pg_database_size</primary>
</indexterm>
<indexterm zone="functions-admin">
<primary>pg_relation_size</primary>
</indexterm>
<indexterm zone="functions-admin">
<primary>pg_complete_relation_size</primary>
</indexterm>
<indexterm zone="functions-admin">
<primary>pg_size_pretty</primary>
</indexterm>
<table id="functions-admin-dbsize">
<title>Database Object Size Functions</title>
<tgroup cols="3">
...
...
@@ -9195,97 +9205,108 @@ SELECT set_config('log_statement_stats', 'off', false);
</thead>
<tbody>
<row>
<entry><function>pg_column_size</function>(<parameter>any</parameter>)</entry>
<entry><type>integer</type></entry>
<entry>Number of bytes used to store a particular value (possibly compressed)</entry>
</row>
<row>
<entry>
<literal><function>pg_tablespace_size</function>(<parameter>oid</parameter>)</literal>
</entry>
<entry><type>
int8
</type></entry>
<entry>
Calculates the t
otal disk space used by the tablespace with the specified OID</entry>
<entry><type>
bigint
</type></entry>
<entry>
T
otal disk space used by the tablespace with the specified OID</entry>
</row>
<row>
<entry>
<literal><function>pg_tablespace_size</function>(<parameter>name</parameter>)</literal>
</entry>
<entry><type>
int8
</type></entry>
<entry>
Calculates the t
otal disk space used by the tablespace with the specified name</entry>
<entry><type>
bigint
</type></entry>
<entry>
T
otal disk space used by the tablespace with the specified name</entry>
</row>
<row>
<entry>
<literal><function>pg_database_size</function>(<parameter>oid</parameter>)</literal>
</entry>
<entry><type>
int8
</type></entry>
<entry>
Calculates the t
otal disk space used by the database with the specified OID</entry>
<entry><type>
bigint
</type></entry>
<entry>
T
otal disk space used by the database with the specified OID</entry>
</row>
<row>
<entry>
<literal><function>pg_database_size</function>(<parameter>name</parameter>)</literal>
</entry>
<entry><type>
int8
</type></entry>
<entry>
Calculates the t
otal disk space used by the database with the specified name</entry>
<entry><type>
bigint
</type></entry>
<entry>
T
otal disk space used by the database with the specified name</entry>
</row>
<row>
<entry>
<literal><function>pg_relation_size</function>(<parameter>oid</parameter>)</literal>
</entry>
<entry><type>
int8
</type></entry>
<entry>
Calculates the d
isk space used by the table or index with the specified OID</entry>
<entry><type>
bigint
</type></entry>
<entry>
D
isk space used by the table or index with the specified OID</entry>
</row>
<row>
<entry>
<literal><function>pg_relation_size</function>(<parameter>text</parameter>)</literal>
</entry>
<entry><type>
int8
</type></entry>
<entry>
Calculates the disk space used by the index or table with the specified name.
The name may be
prefixed with a schema name if required
</entry>
<entry><type>
bigint
</type></entry>
<entry>
Disk space used by the table or index with the specified name.
The name may be
qualified with a schema name
</entry>
</row>
<row>
<entry>
<literal><function>pg_complete_relation_size</function>(<parameter>oid</parameter>)</literal>
</entry>
<entry><type>
int8
</type></entry>
<entry>
Calculates the t
otal disk space used by the table with the specified OID,
<entry><type>
bigint
</type></entry>
<entry>
T
otal disk space used by the table with the specified OID,
including indexes and toasted data</entry>
</row>
<row>
<entry>
<literal><function>pg_complete_relation_size</function>(<parameter>text</parameter>)</literal>
</entry>
<entry><type>
int8
</type></entry>
<entry>
Calculates the t
otal disk space used by the table with the specified name,
including indexes and toasted data.
The name may be prefixed with a schema name if
required
</entry>
<entry><type>
bigint
</type></entry>
<entry>
T
otal disk space used by the table with the specified name,
including indexes and toasted data.
The table name may be qualified with a schema name
</entry>
</row>
<row>
<entry>
<literal><function>pg_size_pretty</function>(<parameter>
int8
</parameter>)</literal>
<literal><function>pg_size_pretty</function>(<parameter>
bigint
</parameter>)</literal>
</entry>
<entry><type>text</type></entry>
<entry>
Formats the size value (in bytes) into a human readable format with size units
</entry>
<entry>
Converts a size in bytes into a human-readable format with size units
</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
<function>pg_
tablespace_size</> and <function>pg_database_size</> accept an
oid or name of a tablespace or database, and return the disk space usage of the specified object.
<function>pg_
column_size</> shows the space used to store any individual
data value.
</para>
<indexterm zone="functions-admin">
<primary>pg_relation_size</primary>
</indexterm>
<para>
<function>pg_relation_size</> accepts the oid or name of a table, index or
<function>pg_tablespace_size</> and <function>pg_database_size</> accept
the OID or name of a tablespace or database, and return the total disk
space used therein.
</para>
<para>
<function>pg_relation_size</> accepts the OID or name of a table, index or
toast table, and returns the size in bytes.
</para>
<para>
<function>pg_complete_relation_size</> accepts the
oid or name of a table or
toast table, and returns the size in bytes of the data and all associated
indexes and toast tables.
<function>pg_complete_relation_size</> accepts the
OID or name of a table
or toast table, and returns the size in bytes of the data and all
associated
indexes and toast tables.
</para>
<para>
<function>pg_size_pretty</> can be used to format the size of the
database objects in a human readable way, using kB, MB, GB or TB as appropriate.
<function>pg_size_pretty</> can be used to format the result of one of
the other functions in a human-readable way, using kB, MB, GB or TB as
appropriate.
</para>
</sect1>
...
...
src/backend/access/heap/tuptoaster.c
浏览文件 @
0001e98d
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.5
0 2005/07/06 19:02:52 momjian
Exp $
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.5
1 2005/08/02 16:11:57 tgl
Exp $
*
*
* INTERFACE ROUTINES
...
...
@@ -268,6 +268,38 @@ toast_raw_datum_size(Datum value)
return
result
;
}
/* ----------
* toast_datum_size
*
* Return the physical storage size (possibly compressed) of a varlena datum
* ----------
*/
Size
toast_datum_size
(
Datum
value
)
{
varattrib
*
attr
=
(
varattrib
*
)
DatumGetPointer
(
value
);
Size
result
;
if
(
VARATT_IS_EXTERNAL
(
attr
))
{
/*
* Attribute is stored externally - return the extsize whether
* compressed or not. We do not count the size of the toast
* pointer ... should we?
*/
result
=
attr
->
va_content
.
va_external
.
va_extsize
;
}
else
{
/*
* Attribute is stored inline either compressed or not, just
* calculate the size of the datum in either case.
*/
result
=
VARSIZE
(
attr
);
}
return
result
;
}
/* ----------
* toast_delete -
...
...
@@ -1436,45 +1468,3 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length)
return
result
;
}
/* ----------
* toast_datum_size
*
* Show the (possibly compressed) size of a datum
* ----------
*/
Size
toast_datum_size
(
Datum
value
)
{
varattrib
*
attr
=
(
varattrib
*
)
DatumGetPointer
(
value
);
Size
result
;
if
(
VARATT_IS_EXTERNAL
(
attr
))
{
/*
* Attribute is stored externally - If it is compressed too,
* then we need to get the external datum and calculate its size,
* otherwise we just use the external rawsize.
*/
if
(
VARATT_IS_COMPRESSED
(
attr
))
{
varattrib
*
attrext
=
toast_fetch_datum
(
attr
);
result
=
VARSIZE
(
attrext
);
pfree
(
attrext
);
}
else
result
=
attr
->
va_content
.
va_external
.
va_rawsize
;
}
else
{
/*
* Attribute is stored inline either compressed or not, just
* calculate the size of the datum in either case.
*/
result
=
VARSIZE
(
attr
);
}
return
result
;
}
src/backend/utils/adt/varlena.c
浏览文件 @
0001e98d
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.13
0 2005/07/29 03:17:55 momjian
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.13
1 2005/08/02 16:11:57 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -2574,38 +2574,49 @@ md5_bytea(PG_FUNCTION_ARGS)
}
/*
* Return the length of a datum, possibly compressed
* Return the size of a datum, possibly compressed
*
* Works on any data type
*/
Datum
pg_column_size
(
PG_FUNCTION_ARGS
)
{
Datum
value
=
PG_GETARG_DATUM
(
0
);
int
result
;
Datum
value
=
PG_GETARG_DATUM
(
0
);
int32
result
;
int
typlen
;
/*
fn_extra stores the fixed column length, or -1 for varlena.
*/
if
(
fcinfo
->
flinfo
->
fn_extra
==
NULL
)
/* first call? */
/*
On first call, get the input type's typlen, and save at *fn_extra
*/
if
(
fcinfo
->
flinfo
->
fn_extra
==
NULL
)
{
/* On the first call lookup the datatype of the supplied argument */
Oid
argtypeid
=
get_fn_expr_argtype
(
fcinfo
->
flinfo
,
0
);
int
typlen
=
get_typlen
(
argtypeid
);
/* Lookup the datatype of the supplied argument */
Oid
argtypeid
=
get_fn_expr_argtype
(
fcinfo
->
flinfo
,
0
);
if
(
typlen
==
0
)
{
/* Oid not in pg_type, should never happen. */
typlen
=
get_typlen
(
argtypeid
);
if
(
typlen
==
0
)
/* should not happen */
elog
(
ERROR
,
"cache lookup failed for type %u"
,
argtypeid
);
}
fcinfo
->
flinfo
->
fn_extra
=
MemoryContextAlloc
(
fcinfo
->
flinfo
->
fn_mcxt
,
sizeof
(
int
));
*
(
int
*
)
fcinfo
->
flinfo
->
fn_extra
=
typlen
;
*
(
(
int
*
)
fcinfo
->
flinfo
->
fn_extra
)
=
typlen
;
}
else
typlen
=
*
((
int
*
)
fcinfo
->
flinfo
->
fn_extra
);
if
(
*
(
int
*
)
fcinfo
->
flinfo
->
fn_extra
!=
-
1
)
PG_RETURN_INT32
(
*
(
int
*
)
fcinfo
->
flinfo
->
fn_extra
);
if
(
typlen
==
-
1
)
{
/* varlena type, possibly toasted */
result
=
toast_datum_size
(
value
);
}
else
if
(
typlen
==
-
2
)
{
/* cstring */
result
=
strlen
(
DatumGetCString
(
value
))
+
1
;
}
else
{
result
=
toast_datum_size
(
value
)
-
VARHDRSZ
;
PG_RETURN_INT32
(
result
)
;
/* ordinary fixed-width type */
result
=
typlen
;
}
PG_RETURN_INT32
(
result
);
}
src/include/catalog/pg_proc.h
浏览文件 @
0001e98d
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.3
79 2005/07/29 14:47:01 momjian
Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.3
80 2005/08/02 16:11:57 tgl
Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
...
...
@@ -3701,7 +3701,7 @@ DATA(insert OID = 2560 ( pg_postmaster_start_time PGNSP PGUID 12 f f t f s 0 11
DESCR
(
"postmaster start time"
);
/* Column storage size */
DATA
(
insert
OID
=
1269
(
pg_column_size
PGNSP
PGUID
12
f
f
t
f
i
1
23
"2276"
_null_
_null_
_null_
pg_column_size
-
_null_
));
DATA
(
insert
OID
=
1269
(
pg_column_size
PGNSP
PGUID
12
f
f
t
f
s
1
23
"2276"
_null_
_null_
_null_
pg_column_size
-
_null_
));
DESCR
(
"bytes required to store the value, perhaps with compression"
);
/* new functions for Y-direction rtree opclasses */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录