Introduce CompactAttribute array in TupleDesc
David Rowley <drowley@postgresql.org>
Introduce CompactAttribute array in TupleDesc The new compact_attrs array stores a few select fields from FormData_pg_attribute in a more compact way, using only 16 bytes per column instead of the 104 bytes that FormData_pg_attribute uses. Using CompactAttribute allows performance-critical operations such as tuple deformation to be performed without looking at the FormData_pg_attribute element in TupleDesc which means fewer cacheline accesses. With this change, NAMEDATALEN could be increased with a much smaller negative impact on performance. For some workloads, tuple deformation can be the most CPU intensive part of processing the query. Some testing with 16 columns on a table where the first column is variable length showed around a 10% increase in transactions per second for an OLAP type query performing aggregation on the 16th column. However, in certain cases, the increases were much higher, up to ~25% on one AMD Zen4 machine. This also makes pg_attribute.attcacheoff redundant. A follow-on commit will remove it, thus shrinking the FormData_pg_attribute struct by 4 bytes. Author: David Rowley Discussion: https://postgr.es/m/CAApHDvrBztXP3yx=NKNmo3xwFAFhEdyPnvrDg3=M0RhDs+4vYw@mail.gmail.com Reviewed-by: Andres Freund, Victor Yegorov
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/access/common/heaptuple.c | modified | +28 −25 |
| src/backend/access/common/indextuple.c | modified | +13 −13 |
| src/backend/access/common/tupdesc.c | modified | +60 −10 |
| src/backend/access/spgist/spgutils.c | modified | +3 −1 |
| src/backend/catalog/index.c | modified | +2 −0 |
| src/backend/commands/tablecmds.c | modified | +4 −0 |
| src/backend/executor/execTuples.c | modified | +2 −2 |
| src/backend/utils/cache/relcache.c | modified | +15 −6 |
| src/backend/utils/cache/typcache.c | modified | +13 −0 |
| src/include/access/htup_details.h | modified | +2 −2 |
| src/include/access/itup.h | modified | +6 −4 |
| src/include/access/tupdesc.h | modified | +94 −3 |
| src/include/access/tupmacs.h | modified | +3 −2 |
| src/tools/pgindent/typedefs.list | modified | +1 −0 |
Discussion
- Make tuple deformation faster 41 messages · 2024-07-01 → 2025-06-16