diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-04-06 04:21:44 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-04-06 04:21:44 +0000 |
commit | 3e23b68dac006e8deb0afa327e855258df8de064 (patch) | |
tree | f5a555955dd954265dea1107e08dadd917714551 /src/include/utils/inet.h | |
parent | d44163953c2ce74d6db9d9807e030a0a3b725da5 (diff) | |
download | postgresql-3e23b68dac006e8deb0afa327e855258df8de064.tar.gz postgresql-3e23b68dac006e8deb0afa327e855258df8de064.zip |
Support varlena fields with single-byte headers and unaligned storage.
This commit breaks any code that assumes that the mere act of forming a tuple
(without writing it to disk) does not "toast" any fields. While all available
regression tests pass, I'm not totally sure that we've fixed every nook and
cranny, especially in contrib.
Greg Stark with some help from Tom Lane
Diffstat (limited to 'src/include/utils/inet.h')
-rw-r--r-- | src/include/utils/inet.h | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/include/utils/inet.h b/src/include/utils/inet.h index ca92f4ca9e1..d94855bb220 100644 --- a/src/include/utils/inet.h +++ b/src/include/utils/inet.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/inet.h,v 1.25 2007/01/05 22:19:59 momjian Exp $ + * $PostgreSQL: pgsql/src/include/utils/inet.h,v 1.26 2007/04/06 04:21:44 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -39,13 +39,19 @@ typedef struct /* * Both INET and CIDR addresses are represented within Postgres as varlena - * objects, ie, there is a varlena header (basically a length word) in front - * of the struct type depicted above. - * - * Although these types are variable-length, the maximum length - * is pretty short, so we make no provision for TOASTing them. + * objects, ie, there is a varlena header in front of the struct type + * depicted above. This struct depicts what we actually have in memory + * in "uncompressed" cases. Note that since the maximum data size is only + * 18 bytes, INET/CIDR will invariably be stored into tuples using the + * 1-byte-header varlena format. However, we have to be prepared to cope + * with the 4-byte-header format too, because various code may helpfully + * try to "decompress" 1-byte-header datums. */ -typedef struct varlena inet; +typedef struct +{ + int32 vl_len_; /* Do not touch this field directly! */ + inet_struct inet_data; +} inet; /* @@ -64,7 +70,7 @@ typedef struct macaddr /* * fmgr interface macros */ -#define DatumGetInetP(X) ((inet *) DatumGetPointer(X)) +#define DatumGetInetP(X) ((inet *) PG_DETOAST_DATUM_PACKED(X)) #define InetPGetDatum(X) PointerGetDatum(X) #define PG_GETARG_INET_P(n) DatumGetInetP(PG_GETARG_DATUM(n)) #define PG_RETURN_INET_P(x) return InetPGetDatum(x) |