Lastly, when the highest-order or lowest-order bit is clear but the adjacent bit is set, the content of the datum has been compressed and must be decompressed before use. The type and size of such a TOAST pointer are determined by a code stored in the second byte of the datum. As a special case, if the remaining bits of a single-byte header are all zero (which would be impossible for a self-inclusive length), the value is a pointer to out-of-line data, with several possible alternatives as described below. Values with single-byte headers aren't aligned on any particular boundary, whereas values with four-byte headers are aligned on at least a four-byte boundary this omission of alignment padding provides additional space savings that is significant compared to short values. This alternative supports space-efficient storage of values shorter than 127 bytes, while still allowing the data type to grow to 1 GB at need. When the highest-order or lowest-order bit is set, the value has only a single-byte header instead of the normal four-byte header, and the remaining bits of that byte give the total datum size (including length byte) in bytes. When both bits are zero, the value is an ordinary un- TOASTed value of the data type, and the remaining bits of the length word give the total datum size (including length word) in bytes. TOAST usurps two bits of the varlena length word (the high-order bits on big-endian machines, the low-order bits on little-endian machines), thereby limiting the logical size of any value of a TOAST-able data type to 1 GB (2 30 - 1 bytes). (This is normally done by invoking PG_DETOAST_DATUM before doing anything with an input value, but in some cases more efficient approaches are possible. ![]() Therefore, the C-level functions supporting a TOAST-able data type must be careful about how they handle potentially TOASTed input values: an input might not actually consist of a four-byte length word and contents until after it's been detoasted. The special representations collectively called TOASTed values work by modifying or reinterpreting this initial length word. TOAST does not constrain the rest of the data type's representation. ![]() To support TOAST, a data type must have a variable-length ( varlena) representation, in which, ordinarily, the first four-byte word of any stored value contains the total length of the value in bytes (including itself). Only certain data types support TOAST - there is no need to impose the overhead on data types that cannot produce large field values. The TOAST infrastructure is also used to improve handling of large data values in-memory. The technique is affectionately known as TOAST (or “ the best thing since sliced bread”). This happens transparently to the user, with only small impact on most of the backend code. To overcome this limitation, large field values are compressed and/or broken up into multiple physical rows. Therefore, it is not possible to store very large field values directly. PostgreSQL uses a fixed page size (commonly 8 kB), and does not allow tuples to span multiple pages. This section provides an overview of TOAST (The Oversized-Attribute Storage Technique). ![]() Out-of-Line, On-Disk TOAST Storage 73.2.2. Moreover, although the dropped column values for newly created tuples are internally marked as null in the tuple's null bitmap, the null bitmap also occupies space.73.2.1. For shorter length variable-length fields, either a 4-byte or 1-byte field header is used and the value is stored inside the heap tuple.Ĭolumns that have been dropped from the table also contribute to the maximum column limit. Only an 18-byte pointer must remain inside the tuple in the table's heap. Variable-length fields of types such as text, varchar, and char can have their values stored out of line in the table's TOAST table when the values are large enough to require it. For example, excluding the tuple header, a tuple made up of 1,600 int columns would consume 6400 bytes and could be stored in a heap page, but a tuple of 1,600 bigint columns would consume 12800 bytes and would therefore not fit inside a heap page. The maximum number of columns for a table is further reduced as the tuple being stored must fit in a single 8192-byte heap page. Limited by the number of tuples that can fit onto 4,294,967,295 pagesįurther limited by tuple size fitting on a single page see note belowĬonstrained by maximum relations per databaseĬan be increased by recompiling PostgreSQL
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |