Add columns, tick nullability, and get the on-heap tuple size — header, null bitmap, alignment padding, TOAST inlining threshold, plus rows-per-page and full-table footprint.
| Name | Type | Length | Null? | Cost | Ops |
|---|
–
Every heap tuple starts with a 23-byte HeapTupleHeader (t_xmin, t_xmax, t_cid/t_xvac, t_ctid, t_infomask2, t_infomask, t_hoff). If any column is nullable, a null bitmap of ceil(ncols/8) bytes follows, and t_hoff is padded up to MAXALIGN (8).
Each column has an alignment requirement (char=1, int2=2, int4/date=4, int8/timestamp/float8/oid/uuid=8, text/varchar/bytea/jsonb use char align for the varlena header but the 4-byte length word gives them de-facto 4-byte alignment). We pad the tuple offset up to the alignment of each column before adding its width. Variable-length types get a 1-byte short header if the payload is ≤ 126 bytes, otherwise a 4-byte long header; if the whole tuple exceeds TOAST_TUPLE_THRESHOLD (~2 kB) the largest varlenas are compressed and/or moved out-of-line to the TOAST table.
Rows are stored inside 8 kB pages. Each page has a 24-byte header, and each row also gets a 4-byte line pointer at the top of the page. The estimator adds all of that plus a configurable fillfactor.