5.2 Tuple Structure
Heap tuples in table pages are classified into two types: usual data tuples and TOAST tuples. This section describes only the usual tuple.
A heap tuple comprises three parts: the HeapTupleHeaderData structure, NULL bitmap, and user data (Fig. 5.2).
The HeapTupleHeaderData structure is defined in src/include/access/htup_details.h.
The HeapTupleHeaderData
structure contains seven fields,
but only four of them are required in the subsequent sections:
-
t_xmin holds the txid of the transaction that inserted this tuple.
-
t_xmax holds the txid of the transaction that deleted or updated this tuple.
If this tuple has not been deleted or updated, t_xmax is set to 0, which means INVALID. -
t_cid holds the command id (cid), which is the number of SQL commands that were executed before this command was executed within the current transaction, starting from 0.
For example, assume that we execute three INSERT commands within a single transaction: ‘BEGIN; INSERT; INSERT; INSERT; COMMIT;’. If the first command inserts this tuple, t_cid is set to 0. If the second command inserts this tuple, t_cid is set to 1, and so on. -
t_ctid holds the tuple identifier (tid) that points to itself or a new tuple.
tid, described in Section 1.3, is used to identify a tuple within a table.
When this tuple is updated, the t_ctid of this tuple points to the new tuple; otherwise, the t_ctid points to itself.