1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-23 03:21:12 +03:00

Add pg_column_size() to return storage size of a column, including

possible compression.

Mark Kirkwood
This commit is contained in:
Bruce Momjian
2005-07-06 19:02:54 +00:00
parent b9cb132648
commit a923602855
6 changed files with 114 additions and 6 deletions

View File

@ -8,7 +8,7 @@
*
*
* 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
@ -1436,3 +1436,45 @@ 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;
}