2005-04-28 23:47:18 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* htup.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* POSTGRES heap tuple definitions.
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*
|
2006-03-05 16:59:11 +01:00
|
|
|
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
2006-06-27 04:51:40 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/access/htup.h,v 1.83 2006/06/27 02:51:39 tgl Exp $
|
1996-08-27 23:50:29 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef HTUP_H
|
1996-08-27 23:50:29 +02:00
|
|
|
#define HTUP_H
|
|
|
|
|
1999-07-16 01:04:24 +02:00
|
|
|
#include "storage/bufpage.h"
|
2000-09-07 11:58:38 +02:00
|
|
|
#include "storage/relfilenode.h"
|
2002-06-15 21:54:24 +02:00
|
|
|
#include "access/transam.h"
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
|
2000-08-07 22:16:13 +02:00
|
|
|
/*
|
2002-05-27 21:53:33 +02:00
|
|
|
* MaxTupleAttributeNumber limits the number of (user) columns in a tuple.
|
2000-08-07 22:16:13 +02:00
|
|
|
* The key limit on this value is that the size of the fixed overhead for
|
|
|
|
* a tuple, plus the size of the null-values bitmap (at 1 bit per column),
|
|
|
|
* plus MAXALIGN alignment, must fit into t_hoff which is uint8. On most
|
2002-05-27 21:53:33 +02:00
|
|
|
* machines the upper limit without making t_hoff wider would be a little
|
|
|
|
* over 1700. We use round numbers here and for MaxHeapAttributeNumber
|
|
|
|
* so that alterations in HeapTupleHeaderData layout won't change the
|
|
|
|
* supported max number of columns.
|
|
|
|
*/
|
2002-09-04 22:31:48 +02:00
|
|
|
#define MaxTupleAttributeNumber 1664 /* 8 * 208 */
|
2002-05-27 21:53:33 +02:00
|
|
|
|
2006-06-27 04:51:40 +02:00
|
|
|
/*
|
2002-05-27 21:53:33 +02:00
|
|
|
* MaxHeapAttributeNumber limits the number of (user) columns in a table.
|
|
|
|
* This should be somewhat less than MaxTupleAttributeNumber. It must be
|
|
|
|
* at least one less, else we will fail to do UPDATEs on a maximal-width
|
|
|
|
* table (because UPDATE has to form working tuples that include CTID).
|
|
|
|
* In practice we want some additional daylight so that we can gracefully
|
|
|
|
* support operations that add hidden "resjunk" columns, for example
|
|
|
|
* SELECT * FROM wide_table ORDER BY foo, bar, baz.
|
|
|
|
* In any case, depending on column data types you will likely be running
|
|
|
|
* into the disk-block-based limit on overall tuple size if you have more
|
|
|
|
* than a thousand or so columns. TOAST won't help.
|
2000-08-07 22:16:13 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define MaxHeapAttributeNumber 1600 /* 8 * 200 */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2006-06-27 04:51:40 +02:00
|
|
|
/*
|
2004-04-01 23:28:47 +02:00
|
|
|
* Heap tuple header. To avoid wasting space, the fields should be
|
|
|
|
* layed out in such a way to avoid structure padding.
|
|
|
|
*
|
|
|
|
* Datums of composite types (row types) share the same general structure
|
|
|
|
* as on-disk tuples, so that the same routines can be used to build and
|
|
|
|
* examine them. However the requirements are slightly different: a Datum
|
|
|
|
* does not need any transaction visibility information, and it does need
|
|
|
|
* a length word and some embedded type information. We can achieve this
|
|
|
|
* by overlaying the xmin/cmin/xmax/cmax/xvac fields of a heap tuple
|
|
|
|
* with the fields needed in the Datum case. Typically, all tuples built
|
|
|
|
* in-memory will be initialized with the Datum fields; but when a tuple is
|
|
|
|
* about to be inserted in a table, the transaction fields will be filled,
|
|
|
|
* overwriting the datum fields.
|
2002-09-02 03:05:06 +02:00
|
|
|
*
|
|
|
|
* The overall structure of a heap tuple looks like:
|
|
|
|
* fixed fields (HeapTupleHeaderData struct)
|
|
|
|
* nulls bitmap (if HEAP_HASNULL is set in t_infomask)
|
|
|
|
* alignment padding (as needed to make user data MAXALIGN'd)
|
|
|
|
* object ID (if HEAP_HASOID is set in t_infomask)
|
|
|
|
* user data fields
|
|
|
|
*
|
2004-08-01 19:32:22 +02:00
|
|
|
* We store five "virtual" fields Xmin, Cmin, Xmax, Cmax, and Xvac in four
|
|
|
|
* physical fields. Xmin, Cmin and Xmax are always really stored, but
|
|
|
|
* Cmax and Xvac share a field. This works because we know that there are
|
|
|
|
* only a limited number of states that a tuple can be in, and that Cmax
|
|
|
|
* is only interesting for the lifetime of the deleting transaction.
|
|
|
|
* This assumes that VACUUM FULL never tries to move a tuple whose Cmax
|
|
|
|
* is still interesting (ie, delete-in-progress).
|
2002-09-02 03:05:06 +02:00
|
|
|
*
|
2004-08-01 19:32:22 +02:00
|
|
|
* Note that in 7.3 and 7.4 a similar idea was applied to Xmax and Cmin.
|
|
|
|
* However, with the advent of subtransactions, a tuple may need both Xmax
|
|
|
|
* and Cmin simultaneously, so this is no longer possible.
|
2002-09-02 03:05:06 +02:00
|
|
|
*
|
2005-08-20 02:40:32 +02:00
|
|
|
* A word about t_ctid: whenever a new tuple is stored on disk, its t_ctid
|
2005-10-15 04:49:52 +02:00
|
|
|
* is initialized with its own TID (location). If the tuple is ever updated,
|
2005-08-20 02:40:32 +02:00
|
|
|
* its t_ctid is changed to point to the replacement version of the tuple.
|
|
|
|
* Thus, a tuple is the latest version of its row iff XMAX is invalid or
|
|
|
|
* t_ctid points to itself (in which case, if XMAX is valid, the tuple is
|
|
|
|
* either locked or deleted). One can follow the chain of t_ctid links
|
|
|
|
* to find the newest version of the row. Beware however that VACUUM might
|
|
|
|
* erase the pointed-to (newer) tuple before erasing the pointing (older)
|
|
|
|
* tuple. Hence, when following a t_ctid link, it is necessary to check
|
|
|
|
* to see if the referenced slot is empty or contains an unrelated tuple.
|
|
|
|
* Check that the referenced tuple has XMIN equal to the referencing tuple's
|
|
|
|
* XMAX to verify that it is actually the descendant version and not an
|
|
|
|
* unrelated tuple stored into a slot recently freed by VACUUM. If either
|
|
|
|
* check fails, one may assume that there is no live descendant version.
|
|
|
|
*
|
2002-09-02 03:05:06 +02:00
|
|
|
* Following the fixed header fields, the nulls bitmap is stored (beginning
|
2002-09-04 22:31:48 +02:00
|
|
|
* at t_bits). The bitmap is *not* stored if t_infomask shows that there
|
2002-09-02 03:05:06 +02:00
|
|
|
* are no nulls in the tuple. If an OID field is present (as indicated by
|
|
|
|
* t_infomask), then it is stored just before the user data, which begins at
|
2002-09-04 22:31:48 +02:00
|
|
|
* the offset shown by t_hoff. Note that t_hoff must be a multiple of
|
2002-09-02 03:05:06 +02:00
|
|
|
* MAXALIGN.
|
1996-08-27 23:50:29 +02:00
|
|
|
*/
|
2004-04-01 23:28:47 +02:00
|
|
|
|
|
|
|
typedef struct HeapTupleFields
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
TransactionId t_xmin; /* inserting xact ID */
|
2004-07-01 02:52:04 +02:00
|
|
|
CommandId t_cmin; /* inserting command ID */
|
2005-04-28 23:47:18 +02:00
|
|
|
TransactionId t_xmax; /* deleting or locking xact ID */
|
2002-09-02 03:05:06 +02:00
|
|
|
|
2002-09-04 22:31:48 +02:00
|
|
|
union
|
|
|
|
{
|
2005-04-28 23:47:18 +02:00
|
|
|
CommandId t_cmax; /* deleting or locking command ID */
|
2002-09-02 03:05:06 +02:00
|
|
|
TransactionId t_xvac; /* VACUUM FULL xact ID */
|
2004-07-01 02:52:04 +02:00
|
|
|
} t_field4;
|
2004-04-01 23:28:47 +02:00
|
|
|
} HeapTupleFields;
|
|
|
|
|
|
|
|
typedef struct DatumTupleFields
|
|
|
|
{
|
|
|
|
int32 datum_len; /* required to be a varlena type */
|
|
|
|
|
|
|
|
int32 datum_typmod; /* -1, or identifier of a record type */
|
|
|
|
|
|
|
|
Oid datum_typeid; /* composite type OID, or RECORDOID */
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2004-04-01 23:28:47 +02:00
|
|
|
/*
|
|
|
|
* Note: field ordering is chosen with thought that Oid might someday
|
|
|
|
* widen to 64 bits.
|
|
|
|
*/
|
|
|
|
} DatumTupleFields;
|
|
|
|
|
|
|
|
typedef struct HeapTupleHeaderData
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
2004-08-29 07:07:03 +02:00
|
|
|
HeapTupleFields t_heap;
|
|
|
|
DatumTupleFields t_datum;
|
2004-04-01 23:28:47 +02:00
|
|
|
} t_choice;
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1998-11-27 20:33:35 +01:00
|
|
|
ItemPointerData t_ctid; /* current TID of this or newer tuple */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2006-06-27 04:51:40 +02:00
|
|
|
/* Fields below here must match MinimalTupleData! */
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
int16 t_natts; /* number of attributes */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2002-05-27 21:53:33 +02:00
|
|
|
uint16 t_infomask; /* various flag bits, see below */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2002-05-27 21:53:33 +02:00
|
|
|
uint8 t_hoff; /* sizeof header incl. bitmap, padding */
|
1998-02-26 05:46:47 +01:00
|
|
|
|
2004-11-12 21:08:40 +01:00
|
|
|
/* ^ - 27 bytes - ^ */
|
2000-06-02 12:20:27 +02:00
|
|
|
|
2002-05-27 21:53:33 +02:00
|
|
|
bits8 t_bits[1]; /* bitmap of NULLs -- VARIABLE LENGTH */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* MORE DATA FOLLOWS AT END OF STRUCT */
|
1999-05-26 00:43:53 +02:00
|
|
|
} HeapTupleHeaderData;
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1998-11-27 20:33:35 +01:00
|
|
|
typedef HeapTupleHeaderData *HeapTupleHeader;
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2002-06-15 21:54:24 +02:00
|
|
|
/*
|
|
|
|
* information stored in t_infomask:
|
|
|
|
*/
|
|
|
|
#define HEAP_HASNULL 0x0001 /* has null attribute(s) */
|
2002-08-25 19:20:01 +02:00
|
|
|
#define HEAP_HASVARWIDTH 0x0002 /* has variable-width attribute(s) */
|
2005-10-15 04:49:52 +02:00
|
|
|
#define HEAP_HASEXTERNAL 0x0004 /* has external stored attribute(s) */
|
|
|
|
#define HEAP_HASCOMPRESSED 0x0008 /* has compressed stored attribute(s) */
|
2002-06-15 21:54:24 +02:00
|
|
|
#define HEAP_HASEXTENDED 0x000C /* the two above combined */
|
2002-09-02 03:05:06 +02:00
|
|
|
#define HEAP_HASOID 0x0010 /* has an object-id field */
|
2005-04-28 23:47:18 +02:00
|
|
|
/* 0x0020 is presently unused */
|
2005-10-15 04:49:52 +02:00
|
|
|
#define HEAP_XMAX_EXCL_LOCK 0x0040 /* xmax is exclusive locker */
|
|
|
|
#define HEAP_XMAX_SHARED_LOCK 0x0080 /* xmax is shared locker */
|
2005-04-28 23:47:18 +02:00
|
|
|
/* if either LOCK bit is set, xmax hasn't deleted the tuple, only locked it */
|
|
|
|
#define HEAP_IS_LOCKED (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_SHARED_LOCK)
|
2002-06-15 21:54:24 +02:00
|
|
|
#define HEAP_XMIN_COMMITTED 0x0100 /* t_xmin committed */
|
|
|
|
#define HEAP_XMIN_INVALID 0x0200 /* t_xmin invalid/aborted */
|
|
|
|
#define HEAP_XMAX_COMMITTED 0x0400 /* t_xmax committed */
|
|
|
|
#define HEAP_XMAX_INVALID 0x0800 /* t_xmax invalid/aborted */
|
2005-04-28 23:47:18 +02:00
|
|
|
#define HEAP_XMAX_IS_MULTI 0x1000 /* t_xmax is a MultiXactId */
|
2002-06-15 21:54:24 +02:00
|
|
|
#define HEAP_UPDATED 0x2000 /* this is UPDATEd version of row */
|
2005-10-15 04:49:52 +02:00
|
|
|
#define HEAP_MOVED_OFF 0x4000 /* moved to another place by VACUUM
|
|
|
|
* FULL */
|
|
|
|
#define HEAP_MOVED_IN 0x8000 /* moved from another place by VACUUM
|
|
|
|
* FULL */
|
2002-07-02 07:46:14 +02:00
|
|
|
#define HEAP_MOVED (HEAP_MOVED_OFF | HEAP_MOVED_IN)
|
2002-06-15 21:54:24 +02:00
|
|
|
|
2002-09-02 03:05:06 +02:00
|
|
|
#define HEAP_XACT_MASK 0xFFC0 /* visibility-related bits */
|
2002-06-15 21:54:24 +02:00
|
|
|
|
|
|
|
|
2002-09-02 03:05:06 +02:00
|
|
|
/*
|
|
|
|
* HeapTupleHeader accessor macros
|
|
|
|
*
|
2002-09-04 22:31:48 +02:00
|
|
|
* Note: beware of multiple evaluations of "tup" argument. But the Set
|
2002-09-02 03:05:06 +02:00
|
|
|
* macros evaluate their other argument only once.
|
|
|
|
*/
|
2002-07-20 07:16:59 +02:00
|
|
|
|
2002-06-15 21:54:24 +02:00
|
|
|
#define HeapTupleHeaderGetXmin(tup) \
|
2002-07-02 07:46:14 +02:00
|
|
|
( \
|
2004-04-01 23:28:47 +02:00
|
|
|
(tup)->t_choice.t_heap.t_xmin \
|
2002-07-02 07:46:14 +02:00
|
|
|
)
|
2002-06-15 21:54:24 +02:00
|
|
|
|
2002-09-02 03:05:06 +02:00
|
|
|
#define HeapTupleHeaderSetXmin(tup, xid) \
|
2002-06-15 21:54:24 +02:00
|
|
|
( \
|
2004-04-01 23:28:47 +02:00
|
|
|
TransactionIdStore((xid), &(tup)->t_choice.t_heap.t_xmin) \
|
2002-06-15 21:54:24 +02:00
|
|
|
)
|
|
|
|
|
2002-09-02 03:05:06 +02:00
|
|
|
#define HeapTupleHeaderGetXmax(tup) \
|
2002-07-02 07:46:14 +02:00
|
|
|
( \
|
2004-07-01 02:52:04 +02:00
|
|
|
(tup)->t_choice.t_heap.t_xmax \
|
2002-07-02 07:46:14 +02:00
|
|
|
)
|
2002-06-15 21:54:24 +02:00
|
|
|
|
|
|
|
#define HeapTupleHeaderSetXmax(tup, xid) \
|
2004-07-01 02:52:04 +02:00
|
|
|
( \
|
|
|
|
TransactionIdStore((xid), &(tup)->t_choice.t_heap.t_xmax) \
|
|
|
|
)
|
2002-06-15 21:54:24 +02:00
|
|
|
|
2002-09-02 03:05:06 +02:00
|
|
|
#define HeapTupleHeaderGetCmin(tup) \
|
|
|
|
( \
|
2004-07-01 02:52:04 +02:00
|
|
|
(tup)->t_choice.t_heap.t_cmin \
|
2002-09-02 03:05:06 +02:00
|
|
|
)
|
2002-06-15 21:54:24 +02:00
|
|
|
|
|
|
|
#define HeapTupleHeaderSetCmin(tup, cid) \
|
2004-07-01 02:52:04 +02:00
|
|
|
( \
|
|
|
|
(tup)->t_choice.t_heap.t_cmin = (cid) \
|
|
|
|
)
|
2002-06-15 21:54:24 +02:00
|
|
|
|
2002-09-02 03:05:06 +02:00
|
|
|
/*
|
2004-07-01 02:52:04 +02:00
|
|
|
* Note: GetCmax will produce wrong answers after SetXvac has been executed
|
|
|
|
* by a transaction other than the inserting one. We could check
|
|
|
|
* HEAP_XMAX_INVALID and return FirstCommandId if it's clear, but since that
|
|
|
|
* bit will be set again if the deleting transaction aborts, there'd be no
|
|
|
|
* real gain in safety from the extra test. So, just rely on the caller not
|
|
|
|
* to trust the value unless it's meaningful.
|
2002-09-02 03:05:06 +02:00
|
|
|
*/
|
|
|
|
#define HeapTupleHeaderGetCmax(tup) \
|
|
|
|
( \
|
2004-07-01 02:52:04 +02:00
|
|
|
(tup)->t_choice.t_heap.t_field4.t_cmax \
|
2002-09-02 03:05:06 +02:00
|
|
|
)
|
|
|
|
|
2002-06-15 21:54:24 +02:00
|
|
|
#define HeapTupleHeaderSetCmax(tup, cid) \
|
2002-07-02 07:46:14 +02:00
|
|
|
do { \
|
|
|
|
Assert(!((tup)->t_infomask & HEAP_MOVED)); \
|
2004-07-01 02:52:04 +02:00
|
|
|
(tup)->t_choice.t_heap.t_field4.t_cmax = (cid); \
|
2002-07-02 07:46:14 +02:00
|
|
|
} while (0)
|
2002-06-15 21:54:24 +02:00
|
|
|
|
2002-09-02 03:05:06 +02:00
|
|
|
#define HeapTupleHeaderGetXvac(tup) \
|
|
|
|
( \
|
|
|
|
((tup)->t_infomask & HEAP_MOVED) ? \
|
2004-07-01 02:52:04 +02:00
|
|
|
(tup)->t_choice.t_heap.t_field4.t_xvac \
|
2002-09-02 03:05:06 +02:00
|
|
|
: \
|
|
|
|
InvalidTransactionId \
|
|
|
|
)
|
|
|
|
|
2002-06-15 21:54:24 +02:00
|
|
|
#define HeapTupleHeaderSetXvac(tup, xid) \
|
2002-07-02 07:46:14 +02:00
|
|
|
do { \
|
|
|
|
Assert((tup)->t_infomask & HEAP_MOVED); \
|
2004-07-01 02:52:04 +02:00
|
|
|
TransactionIdStore((xid), &(tup)->t_choice.t_heap.t_field4.t_xvac); \
|
2002-09-02 03:05:06 +02:00
|
|
|
} while (0)
|
|
|
|
|
2004-04-01 23:28:47 +02:00
|
|
|
#define HeapTupleHeaderGetDatumLength(tup) \
|
|
|
|
( \
|
|
|
|
(tup)->t_choice.t_datum.datum_len \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define HeapTupleHeaderSetDatumLength(tup, len) \
|
|
|
|
( \
|
|
|
|
(tup)->t_choice.t_datum.datum_len = (len) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define HeapTupleHeaderGetTypeId(tup) \
|
|
|
|
( \
|
|
|
|
(tup)->t_choice.t_datum.datum_typeid \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define HeapTupleHeaderSetTypeId(tup, typeid) \
|
|
|
|
( \
|
|
|
|
(tup)->t_choice.t_datum.datum_typeid = (typeid) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define HeapTupleHeaderGetTypMod(tup) \
|
|
|
|
( \
|
|
|
|
(tup)->t_choice.t_datum.datum_typmod \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define HeapTupleHeaderSetTypMod(tup, typmod) \
|
|
|
|
( \
|
|
|
|
(tup)->t_choice.t_datum.datum_typmod = (typmod) \
|
|
|
|
)
|
|
|
|
|
2002-09-02 03:05:06 +02:00
|
|
|
#define HeapTupleHeaderGetOid(tup) \
|
|
|
|
( \
|
|
|
|
((tup)->t_infomask & HEAP_HASOID) ? \
|
|
|
|
*((Oid *) ((char *)(tup) + (tup)->t_hoff - sizeof(Oid))) \
|
|
|
|
: \
|
|
|
|
InvalidOid \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define HeapTupleHeaderSetOid(tup, oid) \
|
|
|
|
do { \
|
|
|
|
Assert((tup)->t_infomask & HEAP_HASOID); \
|
|
|
|
*((Oid *) ((char *)(tup) + (tup)->t_hoff - sizeof(Oid))) = (oid); \
|
2002-07-02 07:46:14 +02:00
|
|
|
} while (0)
|
2002-06-15 21:54:24 +02:00
|
|
|
|
|
|
|
|
2000-06-02 12:20:27 +02:00
|
|
|
/*
|
2004-04-01 23:28:47 +02:00
|
|
|
* BITMAPLEN(NATTS) -
|
|
|
|
* Computes size of null bitmap given number of data columns.
|
2002-09-27 00:46:29 +02:00
|
|
|
*/
|
2004-04-01 23:28:47 +02:00
|
|
|
#define BITMAPLEN(NATTS) (((int)(NATTS) + 7) / 8)
|
2002-09-27 00:46:29 +02:00
|
|
|
|
2000-08-07 22:16:13 +02:00
|
|
|
/*
|
|
|
|
* MaxTupleSize is the maximum allowed size of a tuple, including header and
|
2001-03-22 05:01:46 +01:00
|
|
|
* MAXALIGN alignment padding. Basically it's BLCKSZ minus the other stuff
|
2000-08-07 22:16:13 +02:00
|
|
|
* that has to be on a disk page. The "other stuff" includes access-method-
|
|
|
|
* dependent "special space", which we assume will be no more than
|
|
|
|
* MaxSpecialSpace bytes (currently, on heap pages it's actually zero).
|
|
|
|
*
|
|
|
|
* NOTE: we do not need to count an ItemId for the tuple because
|
|
|
|
* sizeof(PageHeaderData) includes the first ItemId on the page.
|
|
|
|
*/
|
|
|
|
#define MaxSpecialSpace 32
|
|
|
|
|
|
|
|
#define MaxTupleSize \
|
|
|
|
(BLCKSZ - MAXALIGN(sizeof(PageHeaderData) + MaxSpecialSpace))
|
|
|
|
|
2005-09-02 21:02:20 +02:00
|
|
|
/*
|
|
|
|
* MaxHeapTuplesPerPage is an upper bound on the number of tuples that can
|
|
|
|
* fit on one heap page. (Note that indexes could have more, because they
|
|
|
|
* use a smaller tuple header.) We arrive at the divisor because each tuple
|
|
|
|
* must be maxaligned, and it must have an associated item pointer.
|
|
|
|
*/
|
|
|
|
#define MaxHeapTuplesPerPage \
|
|
|
|
((int) ((BLCKSZ - offsetof(PageHeaderData, pd_linp)) / \
|
|
|
|
(MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) + sizeof(ItemIdData))))
|
|
|
|
|
2000-08-07 22:16:13 +02:00
|
|
|
/*
|
|
|
|
* MaxAttrSize is a somewhat arbitrary upper limit on the declared size of
|
|
|
|
* data fields of char(n) and similar types. It need not have anything
|
|
|
|
* directly to do with the *actual* upper limit of varlena values, which
|
|
|
|
* is currently 1Gb (see struct varattrib in postgres.h). I've set it
|
|
|
|
* at 10Mb which seems like a reasonable number --- tgl 8/6/00.
|
|
|
|
*/
|
|
|
|
#define MaxAttrSize (10 * 1024 * 1024)
|
1999-07-04 06:56:02 +02:00
|
|
|
|
1999-07-03 02:33:04 +02:00
|
|
|
|
2000-12-28 00:59:14 +01:00
|
|
|
/*
|
|
|
|
* Attribute numbers for the system-defined attributes
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define SelfItemPointerAttributeNumber (-1)
|
|
|
|
#define ObjectIdAttributeNumber (-2)
|
|
|
|
#define MinTransactionIdAttributeNumber (-3)
|
|
|
|
#define MinCommandIdAttributeNumber (-4)
|
|
|
|
#define MaxTransactionIdAttributeNumber (-5)
|
|
|
|
#define MaxCommandIdAttributeNumber (-6)
|
2001-03-22 05:01:46 +01:00
|
|
|
#define TableOidAttributeNumber (-7)
|
2000-07-03 00:01:27 +02:00
|
|
|
#define FirstLowInvalidHeapAttributeNumber (-8)
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2004-04-01 23:28:47 +02:00
|
|
|
|
2006-06-27 04:51:40 +02:00
|
|
|
/*
|
|
|
|
* MinimalTuple is an alternate representation that is used for transient
|
|
|
|
* tuples inside the executor, in places where transaction status information
|
|
|
|
* is not required, the tuple rowtype is known, and shaving off a few bytes
|
|
|
|
* is worthwhile because we need to store many tuples. The representation
|
|
|
|
* is chosen so that tuple access routines can work with either full or
|
|
|
|
* minimal tuples via a HeapTupleData pointer structure. The access routines
|
|
|
|
* see no difference, except that they must not access the transaction status
|
|
|
|
* or t_ctid fields because those aren't there.
|
|
|
|
*
|
|
|
|
* For the most part, MinimalTuples should be accessed via TupleTableSlot
|
|
|
|
* routines. These routines will prevent access to the "system columns"
|
|
|
|
* and thereby prevent accidental use of the nonexistent fields.
|
|
|
|
*
|
|
|
|
* MinimalTupleData contains a length word, some padding, and fields matching
|
|
|
|
* HeapTupleHeaderData beginning with t_natts. The padding is chosen so that
|
|
|
|
* offsetof(t_natts) is the same modulo MAXIMUM_ALIGNOF in both structs.
|
|
|
|
* This makes data alignment rules equivalent in both cases.
|
|
|
|
*
|
|
|
|
* When a minimal tuple is accessed via a HeapTupleData pointer, t_data is
|
|
|
|
* set to point MINIMAL_TUPLE_OFFSET bytes before the actual start of the
|
|
|
|
* minimal tuple --- that is, where a full tuple matching the minimal tuple's
|
|
|
|
* data would start. This trick is what makes the structs seem equivalent.
|
|
|
|
*
|
|
|
|
* Note that t_hoff is computed the same as in a full tuple, hence it includes
|
|
|
|
* the MINIMAL_TUPLE_OFFSET distance. t_len does not include that, however.
|
|
|
|
*/
|
|
|
|
#define MINIMAL_TUPLE_OFFSET \
|
|
|
|
((offsetof(HeapTupleHeaderData, t_natts) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF)
|
|
|
|
#define MINIMAL_TUPLE_PADDING \
|
|
|
|
((offsetof(HeapTupleHeaderData, t_natts) - sizeof(uint32)) % MAXIMUM_ALIGNOF)
|
|
|
|
|
|
|
|
typedef struct MinimalTupleData
|
|
|
|
{
|
|
|
|
uint32 t_len; /* actual length of minimal tuple */
|
|
|
|
|
|
|
|
char mt_padding[MINIMAL_TUPLE_PADDING];
|
|
|
|
|
|
|
|
/* Fields below here must match HeapTupleHeaderData! */
|
|
|
|
|
|
|
|
int16 t_natts; /* number of attributes */
|
|
|
|
|
|
|
|
uint16 t_infomask; /* various flag bits, see below */
|
|
|
|
|
|
|
|
uint8 t_hoff; /* sizeof header incl. bitmap, padding */
|
|
|
|
|
|
|
|
/* ^ - 27 bytes - ^ */
|
|
|
|
|
|
|
|
bits8 t_bits[1]; /* bitmap of NULLs -- VARIABLE LENGTH */
|
|
|
|
|
|
|
|
/* MORE DATA FOLLOWS AT END OF STRUCT */
|
|
|
|
} MinimalTupleData;
|
|
|
|
|
|
|
|
typedef MinimalTupleData *MinimalTuple;
|
|
|
|
|
|
|
|
|
1998-11-27 20:33:35 +01:00
|
|
|
/*
|
2002-05-27 21:53:33 +02:00
|
|
|
* HeapTupleData is an in-memory data structure that points to a tuple.
|
2001-02-21 20:07:04 +01:00
|
|
|
*
|
2005-08-20 02:40:32 +02:00
|
|
|
* There are several ways in which this data structure is used:
|
|
|
|
*
|
|
|
|
* * Pointer to a tuple in a disk buffer: t_data points directly into the
|
|
|
|
* buffer (which the code had better be holding a pin on, but this is not
|
2005-11-20 20:49:08 +01:00
|
|
|
* reflected in HeapTupleData itself).
|
2005-08-20 02:40:32 +02:00
|
|
|
*
|
2005-11-20 20:49:08 +01:00
|
|
|
* * Pointer to nothing: t_data is NULL. This is used as a failure indication
|
|
|
|
* in some functions.
|
2005-08-20 02:40:32 +02:00
|
|
|
*
|
|
|
|
* * Part of a palloc'd tuple: the HeapTupleData itself and the tuple
|
|
|
|
* form a single palloc'd chunk. t_data points to the memory location
|
2005-11-20 20:49:08 +01:00
|
|
|
* immediately following the HeapTupleData struct (at offset HEAPTUPLESIZE).
|
|
|
|
* This is the output format of heap_form_tuple and related routines.
|
1998-11-27 20:33:35 +01:00
|
|
|
*
|
2005-08-20 02:40:32 +02:00
|
|
|
* * Separately allocated tuple: t_data points to a palloc'd chunk that
|
2005-11-22 19:17:34 +01:00
|
|
|
* is not adjacent to the HeapTupleData. (This case is deprecated since
|
2005-11-20 20:49:08 +01:00
|
|
|
* it's difficult to tell apart from case #1. It should be used only in
|
|
|
|
* limited contexts where the code knows that case #1 will never apply.)
|
1999-12-16 23:20:03 +01:00
|
|
|
*
|
2006-06-27 04:51:40 +02:00
|
|
|
* * Separately allocated minimal tuple: t_data points MINIMAL_TUPLE_OFFSET
|
|
|
|
* bytes before the start of a MinimalTuple. As with the previous case,
|
|
|
|
* this can't be told apart from case #1 by inspection; code setting up
|
|
|
|
* or destroying this representation has to know what it's doing.
|
|
|
|
*
|
2005-08-20 02:40:32 +02:00
|
|
|
* t_len should always be valid, except in the pointer-to-nothing case.
|
|
|
|
* t_self and t_tableOid should be valid if the HeapTupleData points to
|
|
|
|
* a disk buffer, or if it represents a copy of a tuple on disk. They
|
|
|
|
* should be explicitly set invalid in manufactured tuples.
|
1998-11-27 20:33:35 +01:00
|
|
|
*/
|
|
|
|
typedef struct HeapTupleData
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
uint32 t_len; /* length of *t_data */
|
|
|
|
ItemPointerData t_self; /* SelfItemPointer */
|
|
|
|
Oid t_tableOid; /* table the tuple came from */
|
|
|
|
HeapTupleHeader t_data; /* -> tuple header and data */
|
1998-11-27 20:33:35 +01:00
|
|
|
} HeapTupleData;
|
1999-05-25 18:15:34 +02:00
|
|
|
|
1998-11-27 20:33:35 +01:00
|
|
|
typedef HeapTupleData *HeapTuple;
|
|
|
|
|
1999-07-19 09:07:29 +02:00
|
|
|
#define HEAPTUPLESIZE MAXALIGN(sizeof(HeapTupleData))
|
1999-05-25 18:15:34 +02:00
|
|
|
|
2002-09-02 03:05:06 +02:00
|
|
|
/*
|
|
|
|
* GETSTRUCT - given a HeapTuple pointer, return address of the user data
|
1996-08-27 23:50:29 +02:00
|
|
|
*/
|
2002-09-02 03:05:06 +02:00
|
|
|
#define GETSTRUCT(TUP) ((char *) ((TUP)->t_data) + (TUP)->t_data->t_hoff)
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
/*
|
2004-04-01 23:28:47 +02:00
|
|
|
* Accessor macros to be used with HeapTuple pointers.
|
1996-08-27 23:50:29 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define HeapTupleIsValid(tuple) PointerIsValid(tuple)
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2004-01-16 21:51:30 +01:00
|
|
|
#define HeapTupleHasNulls(tuple) \
|
|
|
|
(((tuple)->t_data->t_infomask & HEAP_HASNULL) != 0)
|
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
#define HeapTupleNoNulls(tuple) \
|
2002-09-02 03:05:06 +02:00
|
|
|
(!((tuple)->t_data->t_infomask & HEAP_HASNULL))
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2004-01-16 21:51:30 +01:00
|
|
|
#define HeapTupleHasVarWidth(tuple) \
|
|
|
|
(((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH) != 0)
|
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
#define HeapTupleAllFixed(tuple) \
|
2002-09-02 03:05:06 +02:00
|
|
|
(!((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH))
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1999-12-21 01:06:44 +01:00
|
|
|
#define HeapTupleHasExternal(tuple) \
|
2002-09-02 03:05:06 +02:00
|
|
|
(((tuple)->t_data->t_infomask & HEAP_HASEXTERNAL) != 0)
|
1999-12-21 01:06:44 +01:00
|
|
|
|
|
|
|
#define HeapTupleHasCompressed(tuple) \
|
2002-09-02 03:05:06 +02:00
|
|
|
(((tuple)->t_data->t_infomask & HEAP_HASCOMPRESSED) != 0)
|
1999-12-21 01:06:44 +01:00
|
|
|
|
|
|
|
#define HeapTupleHasExtended(tuple) \
|
2002-09-02 03:05:06 +02:00
|
|
|
(((tuple)->t_data->t_infomask & HEAP_HASEXTENDED) != 0)
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2002-07-20 07:16:59 +02:00
|
|
|
#define HeapTupleGetOid(tuple) \
|
2002-09-02 03:05:06 +02:00
|
|
|
HeapTupleHeaderGetOid((tuple)->t_data)
|
2002-07-20 07:16:59 +02:00
|
|
|
|
|
|
|
#define HeapTupleSetOid(tuple, oid) \
|
2002-09-02 03:05:06 +02:00
|
|
|
HeapTupleHeaderSetOid((tuple)->t_data, (oid))
|
2002-07-20 07:16:59 +02:00
|
|
|
|
2004-04-01 23:28:47 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* WAL record definitions for heapam.c's WAL operations
|
|
|
|
*
|
|
|
|
* XLOG allows to store some information in high 4 bits of log
|
2004-08-01 19:32:22 +02:00
|
|
|
* record xl_info field. We use 3 for opcode and one for init bit.
|
2004-04-01 23:28:47 +02:00
|
|
|
*/
|
|
|
|
#define XLOG_HEAP_INSERT 0x00
|
|
|
|
#define XLOG_HEAP_DELETE 0x10
|
|
|
|
#define XLOG_HEAP_UPDATE 0x20
|
|
|
|
#define XLOG_HEAP_MOVE 0x30
|
|
|
|
#define XLOG_HEAP_CLEAN 0x40
|
2004-07-11 20:01:45 +02:00
|
|
|
#define XLOG_HEAP_NEWPAGE 0x50
|
2005-04-28 23:47:18 +02:00
|
|
|
#define XLOG_HEAP_LOCK 0x60
|
2006-05-11 01:18:39 +02:00
|
|
|
#define XLOG_HEAP_INPLACE 0x70
|
2004-04-01 23:28:47 +02:00
|
|
|
#define XLOG_HEAP_OPMASK 0x70
|
|
|
|
/*
|
|
|
|
* When we insert 1st item on new page in INSERT/UPDATE
|
|
|
|
* we can (and we do) restore entire page in redo
|
|
|
|
*/
|
|
|
|
#define XLOG_HEAP_INIT_PAGE 0x80
|
|
|
|
|
|
|
|
/*
|
2004-11-12 21:08:40 +01:00
|
|
|
* All what we need to find changed tuple
|
2004-04-01 23:28:47 +02:00
|
|
|
*
|
|
|
|
* NB: on most machines, sizeof(xl_heaptid) will include some trailing pad
|
|
|
|
* bytes for alignment. We don't want to store the pad space in the XLOG,
|
|
|
|
* so use SizeOfHeapTid for space calculations. Similar comments apply for
|
|
|
|
* the other xl_FOO structs.
|
|
|
|
*/
|
|
|
|
typedef struct xl_heaptid
|
|
|
|
{
|
|
|
|
RelFileNode node;
|
|
|
|
ItemPointerData tid; /* changed tuple id */
|
|
|
|
} xl_heaptid;
|
|
|
|
|
|
|
|
#define SizeOfHeapTid (offsetof(xl_heaptid, tid) + SizeOfIptrData)
|
|
|
|
|
|
|
|
/* This is what we need to know about delete */
|
|
|
|
typedef struct xl_heap_delete
|
|
|
|
{
|
|
|
|
xl_heaptid target; /* deleted tuple id */
|
|
|
|
} xl_heap_delete;
|
|
|
|
|
|
|
|
#define SizeOfHeapDelete (offsetof(xl_heap_delete, target) + SizeOfHeapTid)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't store the whole fixed part (HeapTupleHeaderData) of an inserted
|
|
|
|
* or updated tuple in WAL; we can save a few bytes by reconstructing the
|
|
|
|
* fields that are available elsewhere in the WAL record, or perhaps just
|
|
|
|
* plain needn't be reconstructed. These are the fields we must store.
|
|
|
|
* NOTE: t_hoff could be recomputed, but we may as well store it because
|
|
|
|
* it will come for free due to alignment considerations.
|
|
|
|
*/
|
|
|
|
typedef struct xl_heap_header
|
|
|
|
{
|
|
|
|
int16 t_natts;
|
|
|
|
uint16 t_infomask;
|
|
|
|
uint8 t_hoff;
|
|
|
|
} xl_heap_header;
|
|
|
|
|
|
|
|
#define SizeOfHeapHeader (offsetof(xl_heap_header, t_hoff) + sizeof(uint8))
|
|
|
|
|
|
|
|
/* This is what we need to know about insert */
|
|
|
|
typedef struct xl_heap_insert
|
|
|
|
{
|
|
|
|
xl_heaptid target; /* inserted tuple id */
|
|
|
|
/* xl_heap_header & TUPLE DATA FOLLOWS AT END OF STRUCT */
|
|
|
|
} xl_heap_insert;
|
|
|
|
|
|
|
|
#define SizeOfHeapInsert (offsetof(xl_heap_insert, target) + SizeOfHeapTid)
|
|
|
|
|
|
|
|
/* This is what we need to know about update|move */
|
|
|
|
typedef struct xl_heap_update
|
|
|
|
{
|
|
|
|
xl_heaptid target; /* deleted tuple id */
|
|
|
|
ItemPointerData newtid; /* new inserted tuple id */
|
|
|
|
/* NEW TUPLE xl_heap_header (PLUS xmax & xmin IF MOVE OP) */
|
|
|
|
/* and TUPLE DATA FOLLOWS AT END OF STRUCT */
|
|
|
|
} xl_heap_update;
|
|
|
|
|
|
|
|
#define SizeOfHeapUpdate (offsetof(xl_heap_update, newtid) + SizeOfIptrData)
|
|
|
|
|
2004-07-11 20:01:45 +02:00
|
|
|
/* This is what we need to know about vacuum page cleanup */
|
2004-04-01 23:28:47 +02:00
|
|
|
typedef struct xl_heap_clean
|
|
|
|
{
|
|
|
|
RelFileNode node;
|
|
|
|
BlockNumber block;
|
|
|
|
/* UNUSED OFFSET NUMBERS FOLLOW AT THE END */
|
|
|
|
} xl_heap_clean;
|
|
|
|
|
|
|
|
#define SizeOfHeapClean (offsetof(xl_heap_clean, block) + sizeof(BlockNumber))
|
|
|
|
|
2004-07-11 20:01:45 +02:00
|
|
|
/* This is for replacing a page's contents in toto */
|
|
|
|
/* NB: this is used for indexes as well as heaps */
|
|
|
|
typedef struct xl_heap_newpage
|
|
|
|
{
|
|
|
|
RelFileNode node;
|
|
|
|
BlockNumber blkno; /* location of new page */
|
|
|
|
/* entire page contents follow at end of record */
|
|
|
|
} xl_heap_newpage;
|
|
|
|
|
|
|
|
#define SizeOfHeapNewpage (offsetof(xl_heap_newpage, blkno) + sizeof(BlockNumber))
|
|
|
|
|
2005-04-28 23:47:18 +02:00
|
|
|
/* This is what we need to know about lock */
|
|
|
|
typedef struct xl_heap_lock
|
|
|
|
{
|
|
|
|
xl_heaptid target; /* locked tuple id */
|
2005-06-08 17:50:28 +02:00
|
|
|
TransactionId locking_xid; /* might be a MultiXactId not xid */
|
|
|
|
bool xid_is_mxact; /* is it? */
|
2005-04-28 23:47:18 +02:00
|
|
|
bool shared_lock; /* shared or exclusive row lock? */
|
|
|
|
} xl_heap_lock;
|
|
|
|
|
|
|
|
#define SizeOfHeapLock (offsetof(xl_heap_lock, shared_lock) + sizeof(bool))
|
|
|
|
|
2006-05-11 01:18:39 +02:00
|
|
|
/* This is what we need to know about in-place update */
|
|
|
|
typedef struct xl_heap_inplace
|
|
|
|
{
|
|
|
|
xl_heaptid target; /* updated tuple id */
|
|
|
|
/* TUPLE DATA FOLLOWS AT END OF STRUCT */
|
|
|
|
} xl_heap_inplace;
|
|
|
|
|
|
|
|
#define SizeOfHeapInplace (offsetof(xl_heap_inplace, target) + SizeOfHeapTid)
|
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* HTUP_H */
|