Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
a9236028
Commit
a9236028
authored
Jul 06, 2005
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add pg_column_size() to return storage size of a column, including
possible compression. Mark Kirkwood
parent
b9cb1326
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
114 additions
and
6 deletions
+114
-6
doc/src/sgml/func.sgml
doc/src/sgml/func.sgml
+9
-1
src/backend/access/heap/tuptoaster.c
src/backend/access/heap/tuptoaster.c
+43
-1
src/backend/utils/adt/varlena.c
src/backend/utils/adt/varlena.c
+46
-1
src/include/access/tuptoaster.h
src/include/access/tuptoaster.h
+9
-1
src/include/catalog/pg_proc.h
src/include/catalog/pg_proc.h
+5
-1
src/include/utils/builtins.h
src/include/utils/builtins.h
+2
-1
No files found.
doc/src/sgml/func.sgml
View file @
a9236028
<!--
<!--
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.26
2 2005/06/29 01:52:56
momjian Exp $
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.26
3 2005/07/06 19:02:52
momjian Exp $
PostgreSQL documentation
PostgreSQL documentation
-->
-->
...
@@ -2186,6 +2186,14 @@ PostgreSQL documentation
...
@@ -2186,6 +2186,14 @@ PostgreSQL documentation
<entry><literal>5</literal></entry>
<entry><literal>5</literal></entry>
</row>
</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>
<row>
<entry><literal><function>position</function>(<parameter>substring</parameter> in <parameter>string</parameter>)</literal></entry>
<entry><literal><function>position</function>(<parameter>substring</parameter> in <parameter>string</parameter>)</literal></entry>
<entry><type>integer</type></entry>
<entry><type>integer</type></entry>
...
...
src/backend/access/heap/tuptoaster.c
View file @
a9236028
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.
49 2005/03/21 01:23:58 tgl
Exp $
* $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.
50 2005/07/06 19:02:52 momjian
Exp $
*
*
*
*
* INTERFACE ROUTINES
* INTERFACE ROUTINES
...
@@ -1436,3 +1436,45 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length)
...
@@ -1436,3 +1436,45 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length)
return
result
;
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
View file @
a9236028
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.12
4 2005/07/04 18:56:44
momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.12
5 2005/07/06 19:02:52
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
#include "utils/builtins.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/lsyscache.h"
#include "utils/pg_locale.h"
#include "utils/pg_locale.h"
#include "utils/syscache.h"
typedef
struct
varlena
unknown
;
typedef
struct
varlena
unknown
;
...
@@ -2348,3 +2349,47 @@ md5_bytea(PG_FUNCTION_ARGS)
...
@@ -2348,3 +2349,47 @@ md5_bytea(PG_FUNCTION_ARGS)
result_text
=
PG_STR_GET_TEXT
(
hexsum
);
result_text
=
PG_STR_GET_TEXT
(
hexsum
);
PG_RETURN_TEXT_P
(
result_text
);
PG_RETURN_TEXT_P
(
result_text
);
}
}
/*
* Return the length of a datum, possibly compressed
*/
Datum
pg_column_size
(
PG_FUNCTION_ARGS
)
{
Datum
value
=
PG_GETARG_DATUM
(
0
);
int
result
;
/* fn_extra stores the fixed column length, or -1 for varlena. */
if
(
fcinfo
->
flinfo
->
fn_extra
==
NULL
)
/* first call? */
{
/* On the first call lookup the datatype of the supplied argument */
Oid
argtypeid
=
get_fn_expr_argtype
(
fcinfo
->
flinfo
,
0
);
HeapTuple
tp
;
int
typlen
;
tp
=
SearchSysCache
(
TYPEOID
,
ObjectIdGetDatum
(
argtypeid
),
0
,
0
,
0
);
if
(
!
HeapTupleIsValid
(
tp
))
{
/* Oid not in pg_type, should never happen. */
ereport
(
ERROR
,
(
errcode
(
ERRCODE_INTERNAL_ERROR
),
errmsg
(
"invalid typid: %u"
,
argtypeid
)));
}
typlen
=
((
Form_pg_type
)
GETSTRUCT
(
tp
))
->
typlen
;
ReleaseSysCache
(
tp
);
fcinfo
->
flinfo
->
fn_extra
=
MemoryContextAlloc
(
fcinfo
->
flinfo
->
fn_mcxt
,
sizeof
(
int
));
*
(
int
*
)
fcinfo
->
flinfo
->
fn_extra
=
typlen
;
}
if
(
*
(
int
*
)
fcinfo
->
flinfo
->
fn_extra
!=
-
1
)
PG_RETURN_INT32
(
*
(
int
*
)
fcinfo
->
flinfo
->
fn_extra
);
else
{
result
=
toast_datum_size
(
value
)
-
VARHDRSZ
;
PG_RETURN_INT32
(
result
);
}
}
src/include/access/tuptoaster.h
View file @
a9236028
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/include/access/tuptoaster.h,v 1.2
2 2005/03/21 01:24:04 tgl
Exp $
* $PostgreSQL: pgsql/src/include/access/tuptoaster.h,v 1.2
3 2005/07/06 19:02:53 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -138,4 +138,12 @@ extern Datum toast_compress_datum(Datum value);
...
@@ -138,4 +138,12 @@ extern Datum toast_compress_datum(Datum value);
*/
*/
extern
Size
toast_raw_datum_size
(
Datum
value
);
extern
Size
toast_raw_datum_size
(
Datum
value
);
/* ----------
* toast_datum_size -
*
* Return the storage size of a varlena datum
* ----------
*/
extern
Size
toast_datum_size
(
Datum
value
);
#endif
/* TUPTOASTER_H */
#endif
/* TUPTOASTER_H */
src/include/catalog/pg_proc.h
View file @
a9236028
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.37
3 2005/07/01 19:19:03 tgl
Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.37
4 2005/07/06 19:02:53 momjian
Exp $
*
*
* NOTES
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
* The script catalog/genbki.sh reads this file and generates .bki
...
@@ -3658,6 +3658,10 @@ DESCR("current value from last used sequence");
...
@@ -3658,6 +3658,10 @@ DESCR("current value from last used sequence");
DATA
(
insert
OID
=
2560
(
pg_postmaster_start_time
PGNSP
PGUID
12
f
f
t
f
s
0
1184
""
_null_
_null_
_null_
pgsql_postmaster_start_time
-
_null_
));
DATA
(
insert
OID
=
2560
(
pg_postmaster_start_time
PGNSP
PGUID
12
f
f
t
f
s
0
1184
""
_null_
_null_
_null_
pgsql_postmaster_start_time
-
_null_
));
DESCR
(
"postmaster start time"
);
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_
));
DESCR
(
"bytes required to store the value, perhaps with compression"
);
/* new functions for Y-direction rtree opclasses */
/* new functions for Y-direction rtree opclasses */
DATA
(
insert
OID
=
2562
(
box_below
PGNSP
PGUID
12
f
f
t
f
i
2
16
"603 603"
_null_
_null_
_null_
box_below
-
_null_
));
DATA
(
insert
OID
=
2562
(
box_below
PGNSP
PGUID
12
f
f
t
f
i
2
16
"603 603"
_null_
_null_
_null_
box_below
-
_null_
));
DESCR
(
"is below"
);
DESCR
(
"is below"
);
...
...
src/include/utils/builtins.h
View file @
a9236028
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.25
8 2005/06/17 22:32:50 tgl
Exp $
* $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.25
9 2005/07/06 19:02:54 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -601,6 +601,7 @@ extern Datum byteacat(PG_FUNCTION_ARGS);
...
@@ -601,6 +601,7 @@ extern Datum byteacat(PG_FUNCTION_ARGS);
extern
Datum
byteapos
(
PG_FUNCTION_ARGS
);
extern
Datum
byteapos
(
PG_FUNCTION_ARGS
);
extern
Datum
bytea_substr
(
PG_FUNCTION_ARGS
);
extern
Datum
bytea_substr
(
PG_FUNCTION_ARGS
);
extern
Datum
bytea_substr_no_len
(
PG_FUNCTION_ARGS
);
extern
Datum
bytea_substr_no_len
(
PG_FUNCTION_ARGS
);
extern
Datum
pg_column_size
(
PG_FUNCTION_ARGS
);
/* version.c */
/* version.c */
extern
Datum
pgsql_version
(
PG_FUNCTION_ARGS
);
extern
Datum
pgsql_version
(
PG_FUNCTION_ARGS
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment