1999-07-15 17:21:54 +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
|
|
|
*
|
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, 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
|
|
|
*
|
2001-03-26 00:40:58 +02:00
|
|
|
* $Id: htup.h,v 1.48 2001/03/25 22:40:58 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"
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
#define MinHeapTupleBitmapSize 32 /* 8 * 4 */
|
|
|
|
|
2000-08-07 22:16:13 +02:00
|
|
|
/*
|
|
|
|
* MaxHeapAttributeNumber limits the number of (user) columns in a table.
|
|
|
|
* 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
|
|
|
|
* machines the absolute upper limit without making t_hoff wider would be
|
2001-03-22 05:01:46 +01:00
|
|
|
* about 1700. Note, however, that depending on column data types you will
|
2000-08-07 22:16:13 +02:00
|
|
|
* likely also 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.
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define MaxHeapAttributeNumber 1600 /* 8 * 200 */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
/*
|
2001-02-21 20:07:04 +01:00
|
|
|
* This is the on-disk copy of the tuple.
|
2001-03-22 05:01:46 +01:00
|
|
|
*
|
2001-02-21 20:07:04 +01:00
|
|
|
* To avoid wasting space, the attributes should be layed out in such a
|
1996-08-27 23:50:29 +02:00
|
|
|
* way to reduce structure padding.
|
|
|
|
*/
|
1998-11-27 20:33:35 +01:00
|
|
|
typedef struct HeapTupleHeaderData
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-02-26 05:46:47 +01:00
|
|
|
Oid t_oid; /* OID of this tuple -- 4 bytes */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
CommandId t_cmin; /* insert CID stamp -- 4 bytes each */
|
|
|
|
CommandId t_cmax; /* delete CommandId stamp */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
TransactionId t_xmin; /* insert XID stamp -- 4 bytes each */
|
|
|
|
TransactionId t_xmax; /* delete XID stamp */
|
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
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
int16 t_natts; /* number of attributes */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
uint16 t_infomask; /* various infos */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
2001-02-21 20:07:04 +01:00
|
|
|
uint8 t_hoff; /* sizeof() tuple header */
|
1998-02-26 05:46:47 +01:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
/* ^ - 31 bytes - ^ */
|
2000-06-02 12:20:27 +02:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
bits8 t_bits[MinHeapTupleBitmapSize / 8];
|
2001-02-21 20:07:04 +01:00
|
|
|
/* bit map of NULLs */
|
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
|
|
|
|
2000-06-02 12:20:27 +02:00
|
|
|
/*
|
|
|
|
* XLOG allows to store some information in high 4 bits of log
|
|
|
|
* record xl_info field
|
|
|
|
*/
|
2001-03-22 05:01:46 +01: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
|
2000-12-28 14:00:29 +01: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
|
|
|
|
*/
|
2001-03-22 05:01:46 +01:00
|
|
|
#define XLOG_HEAP_INIT_PAGE 0x80
|
2000-06-02 12:20:27 +02:00
|
|
|
|
|
|
|
/*
|
2000-07-03 04:54:21 +02:00
|
|
|
* All what we need to find changed tuple (18 bytes)
|
2001-03-26 00:40:58 +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.
|
2000-06-02 12:20:27 +02:00
|
|
|
*/
|
|
|
|
typedef struct xl_heaptid
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
RelFileNode node;
|
|
|
|
ItemPointerData tid; /* changed tuple id */
|
2000-06-02 12:20:27 +02:00
|
|
|
} xl_heaptid;
|
|
|
|
|
2001-03-26 00:40:58 +02:00
|
|
|
#define SizeOfHeapTid (offsetof(xl_heaptid, tid) + SizeOfIptrData)
|
|
|
|
|
2000-12-28 14:00:29 +01:00
|
|
|
/* This is what we need to know about delete */
|
2000-06-02 12:20:27 +02:00
|
|
|
typedef struct xl_heap_delete
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
xl_heaptid target; /* deleted tuple id */
|
2000-06-02 12:20:27 +02:00
|
|
|
} xl_heap_delete;
|
|
|
|
|
2001-03-26 00:40:58 +02:00
|
|
|
#define SizeOfHeapDelete (offsetof(xl_heap_delete, target) + SizeOfHeapTid)
|
2000-07-04 03:49:44 +02:00
|
|
|
|
2000-12-28 14:00:29 +01:00
|
|
|
typedef struct xl_heap_header
|
2000-06-02 12:20:27 +02:00
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
Oid t_oid;
|
|
|
|
int16 t_natts;
|
|
|
|
uint8 t_hoff;
|
|
|
|
uint8 mask; /* low 8 bits of t_infomask */
|
2000-12-28 14:00:29 +01:00
|
|
|
} xl_heap_header;
|
|
|
|
|
|
|
|
#define SizeOfHeapHeader (offsetof(xl_heap_header, mask) + sizeof(uint8))
|
|
|
|
|
|
|
|
/* This is what we need to know about insert */
|
|
|
|
typedef struct xl_heap_insert
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
xl_heaptid target; /* inserted tuple id */
|
2000-12-28 14:00:29 +01:00
|
|
|
/* xl_heap_header & TUPLE DATA FOLLOWS AT END OF STRUCT */
|
2000-06-02 12:20:27 +02:00
|
|
|
} xl_heap_insert;
|
|
|
|
|
2001-03-26 00:40:58 +02:00
|
|
|
#define SizeOfHeapInsert (offsetof(xl_heap_insert, target) + SizeOfHeapTid)
|
2000-07-04 03:49:44 +02:00
|
|
|
|
2000-12-28 14:00:29 +01:00
|
|
|
/* This is what we need to know about update|move */
|
2000-06-02 12:20:27 +02:00
|
|
|
typedef struct xl_heap_update
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
xl_heaptid target; /* deleted tuple id */
|
|
|
|
ItemPointerData newtid; /* new inserted tuple id */
|
2001-03-26 00:40:58 +02:00
|
|
|
/* NEW TUPLE xl_heap_header (PLUS xmax & xmin IF MOVE OP) */
|
2000-12-28 14:00:29 +01:00
|
|
|
/* and TUPLE DATA FOLLOWS AT END OF STRUCT */
|
2000-06-02 12:20:27 +02:00
|
|
|
} xl_heap_update;
|
|
|
|
|
2000-12-28 14:00:29 +01:00
|
|
|
#define SizeOfHeapUpdate (offsetof(xl_heap_update, newtid) + SizeOfIptrData)
|
|
|
|
|
|
|
|
/* This is what we need to know about page cleanup */
|
|
|
|
typedef struct xl_heap_clean
|
|
|
|
{
|
2001-03-22 05:01:46 +01:00
|
|
|
RelFileNode node;
|
|
|
|
BlockNumber block;
|
2000-12-30 16:19:57 +01:00
|
|
|
/* UNUSED OFFSET NUMBERS FOLLOW AT THE END */
|
2000-12-28 14:00:29 +01:00
|
|
|
} xl_heap_clean;
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define SizeOfHeapClean (offsetof(xl_heap_clean, block) + sizeof(BlockNumber))
|
2000-07-04 03:49:44 +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))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
1998-11-27 20:33:35 +01:00
|
|
|
/*
|
2001-02-21 20:07:04 +01:00
|
|
|
* This is the in-memory copy of the tuple.
|
|
|
|
*
|
1998-11-27 20:33:35 +01:00
|
|
|
* This new HeapTuple for version >= 6.5 and this is why it was changed:
|
|
|
|
*
|
|
|
|
* 1. t_len moved off on-disk tuple data - ItemIdData is used to get len;
|
|
|
|
* 2. t_ctid above is not self tuple TID now - it may point to
|
1999-05-25 18:15:34 +02:00
|
|
|
* updated version of tuple (required by MVCC);
|
|
|
|
* 3. someday someone let tuple to cross block boundaries -
|
|
|
|
* he have to add something below...
|
1999-12-16 23:20:03 +01:00
|
|
|
*
|
|
|
|
* Change for 7.0:
|
2000-04-12 19:17:23 +02:00
|
|
|
* Up to now t_data could be NULL, the memory location directly following
|
2000-11-14 21:47:34 +01:00
|
|
|
* HeapTupleData, or pointing into a buffer. Now, it could also point to
|
2000-04-12 19:17:23 +02:00
|
|
|
* a separate allocation that was done in the t_datamcxt memory context.
|
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 */
|
|
|
|
MemoryContext t_datamcxt; /* memory context of allocation */
|
|
|
|
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
|
|
|
|
|
|
|
|
1996-08-27 23:50:29 +02:00
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* support macros
|
1996-08-27 23:50:29 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1998-11-27 20:33:35 +01:00
|
|
|
#define GETSTRUCT(TUP) (((char *)((HeapTuple)(TUP))->t_data) + \
|
|
|
|
((HeapTuple)(TUP))->t_data->t_hoff)
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* BITMAPLEN(NATTS) -
|
|
|
|
* Computes minimum size of bitmap given number of domains.
|
1996-08-27 23:50:29 +02:00
|
|
|
*/
|
|
|
|
#define BITMAPLEN(NATTS) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((((((int)(NATTS) - 1) >> 3) + 4 - (MinHeapTupleBitmapSize >> 3)) \
|
|
|
|
& ~03) + (MinHeapTupleBitmapSize >> 3))
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* HeapTupleIsValid
|
1997-09-07 07:04:48 +02:00
|
|
|
* True iff the heap tuple is valid.
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* information stored in t_infomask:
|
|
|
|
*/
|
1997-11-02 16:27:14 +01:00
|
|
|
#define HEAP_HASNULL 0x0001 /* has null attribute(s) */
|
|
|
|
#define HEAP_HASVARLENA 0x0002 /* has variable length
|
1997-09-07 07:04:48 +02:00
|
|
|
* attribute(s) */
|
1999-12-21 01:06:44 +01:00
|
|
|
#define HEAP_HASEXTERNAL 0x0004 /* has external stored */
|
2000-04-12 19:17:23 +02:00
|
|
|
/* attribute(s) */
|
1999-12-21 01:06:44 +01:00
|
|
|
#define HEAP_HASCOMPRESSED 0x0008 /* has compressed stored */
|
2000-04-12 19:17:23 +02:00
|
|
|
/* attribute(s) */
|
1999-12-21 01:06:44 +01:00
|
|
|
#define HEAP_HASEXTENDED 0x000C /* the two above combined */
|
2000-09-07 11:58:38 +02:00
|
|
|
|
|
|
|
#define HEAP_XMAX_UNLOGGED 0x0080 /* to lock tuple for update */
|
2001-03-22 05:01:46 +01:00
|
|
|
/* without logging */
|
1997-11-02 16:27:14 +01: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 */
|
1998-12-15 13:47:01 +01:00
|
|
|
#define HEAP_MARKED_FOR_UPDATE 0x1000 /* marked for UPDATE */
|
1999-03-28 22:32:42 +02:00
|
|
|
#define HEAP_UPDATED 0x2000 /* this is UPDATEd version of row */
|
1999-05-25 18:15:34 +02:00
|
|
|
#define HEAP_MOVED_OFF 0x4000 /* removed or moved to another
|
|
|
|
* place by vacuum */
|
|
|
|
#define HEAP_MOVED_IN 0x8000 /* moved from another place by
|
|
|
|
* vacuum */
|
1997-11-02 16:27:14 +01:00
|
|
|
|
2000-09-07 11:58:38 +02:00
|
|
|
#define HEAP_XACT_MASK 0xFFF0 /* */
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
#define HeapTupleNoNulls(tuple) \
|
1998-11-27 20:33:35 +01:00
|
|
|
(!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASNULL))
|
1996-08-27 23:50:29 +02:00
|
|
|
|
|
|
|
#define HeapTupleAllFixed(tuple) \
|
1998-11-27 20:33:35 +01:00
|
|
|
(!(((HeapTuple) (tuple))->t_data->t_infomask & HEAP_HASVARLENA))
|
1996-08-27 23:50:29 +02:00
|
|
|
|
1999-12-21 01:06:44 +01:00
|
|
|
#define HeapTupleHasExternal(tuple) \
|
|
|
|
((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASEXTERNAL) != 0)
|
|
|
|
|
|
|
|
#define HeapTupleHasCompressed(tuple) \
|
|
|
|
((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASCOMPRESSED) != 0)
|
|
|
|
|
|
|
|
#define HeapTupleHasExtended(tuple) \
|
|
|
|
((((HeapTuple)(tuple))->t_data->t_infomask & HEAP_HASEXTENDED) != 0)
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* HTUP_H */
|