diff options
author | Bruce Momjian <bruce@momjian.us> | 2007-05-15 17:39:54 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2007-05-15 17:39:54 +0000 |
commit | 178214d2ae46b1b1a67b168b510a224881f60efd (patch) | |
tree | 7356fbab0f5623187d26e182f95b8aeb30333f76 /doc/src | |
parent | 39712d1184f184ee348e701ca794fdf8d6a51510 (diff) |
Update comments for PG_DETOAST_PACKED and VARDATA_ANY on a structures
that require alignment.
Add a paragraph to the "User-Defined Types" chapter on using these
macros since it seems like they're a hit.
Gregory Stark
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/xtypes.sgml | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/doc/src/sgml/xtypes.sgml b/doc/src/sgml/xtypes.sgml index e1ec4ea189b..bc84ccd1c4b 100644 --- a/doc/src/sgml/xtypes.sgml +++ b/doc/src/sgml/xtypes.sgml @@ -1,4 +1,4 @@ -<!-- $PostgreSQL: pgsql/doc/src/sgml/xtypes.sgml,v 1.28 2006/09/16 00:30:16 momjian Exp $ --> +<!-- $PostgreSQL: pgsql/doc/src/sgml/xtypes.sgml,v 1.29 2007/05/15 17:39:54 momjian Exp $ --> <sect1 id="xtypes"> <title>User-Defined Types</title> @@ -237,20 +237,38 @@ CREATE TYPE complex ( <primary>TOAST</primary> <secondary>and user-defined types</secondary> </indexterm> - If the values of your data type might exceed a few hundred bytes in - size (in internal form), you should make the data type - <acronym>TOAST</>-able (see <xref linkend="storage-toast">). - To do this, the internal - representation must follow the standard layout for variable-length - data: the first four bytes must be an <type>int32</type> containing - the total length in bytes of the datum (including itself). The C - functions operating on the data type must be careful to unpack any + If the values of your data type vary in size (in internal form), you should + make the data type <acronym>TOAST</>-able (see <xref + linkend="storage-toast">). You should do this even if the data are always + too small to be compressed or stored externally because + <productname>Postgres</> can save space on small data using + <acronym>TOAST</> as well. + </para> + + <para> + To do this, the internal representation must follow the standard layout for + variable-length data: the first four bytes must be an <type>int32</type> + which is never accessed directly (customarily named <literal>vl_len_</>). You + must use <function>SET_VARSIZE()</function> to store the size of the datum + in this field and <function>VARSIZE()</function> to retrieve it. The C + functions operating on the data type must always be careful to unpack any toasted values they are handed, by using <function>PG_DETOAST_DATUM</>. (This detail is customarily hidden by defining type-specific - <function>GETARG</function> macros.) Then, - when running the <command>CREATE TYPE</command> command, specify the - internal length as <literal>variable</> and select the appropriate - storage option. + <function>GETARG_DATATYPE_P</function> macros.) Then, when running the + <command>CREATE TYPE</command> command, specify the internal length as + <literal>variable</> and select the appropriate storage option. + </para> + + <para> + If the alignment is unimportant (either just for a specific function or + because the data type specifies byte alignment anyways) then it's possible + to avoid some of the overhead of <function>PG_DETOAST_DATUM</>. You can use + <function>PG_DETOAST_DATUM_PACKED</> instead (customarily hidden by + defining a <function>GETARG_DATATYPE_PP</> macro) and using the macros + <function>VARSIZE_ANY_EXHDR</> and <function>VARDATA_ANY</> macros. + Again, the data returned by these macros is not aligned even if the data + type definition specifies an alignment. If the alignment is important you + must go through the regular <function>PG_DETOAST_DATUM</> interface. </para> <para> |