Introduce CompactAttribute array in TupleDesc, take 2
authorDavid Rowley <drowley@postgresql.org>
Fri, 20 Dec 2024 09:31:26 +0000 (22:31 +1300)
committerDavid Rowley <drowley@postgresql.org>
Fri, 20 Dec 2024 09:31:26 +0000 (22:31 +1300)
commit5983a4cffc31640fda6643f10146a5b72b203eaa
tree0ff0361ca37173c5093ae3e1eb23fe657c904adc
parent8ac0021b6f10928a46b7f3d1b25bc21c0ac7f8c5
Introduce CompactAttribute array in TupleDesc, take 2

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.

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
Reviewed-by: Andres Freund, Victor Yegorov
Discussion: https://postgr.es/m/CAApHDvrBztXP3yx=NKNmo3xwFAFhEdyPnvrDg3=M0RhDs+4vYw@mail.gmail.com
44 files changed:
contrib/amcheck/verify_heapam.c
contrib/pageinspect/gistfuncs.c
contrib/pageinspect/heapfuncs.c
contrib/postgres_fdw/postgres_fdw.c
src/backend/access/brin/brin_inclusion.c
src/backend/access/brin/brin_tuple.c
src/backend/access/common/attmap.c
src/backend/access/common/heaptuple.c
src/backend/access/common/indextuple.c
src/backend/access/common/tupdesc.c
src/backend/access/gin/ginbulk.c
src/backend/access/gin/ginget.c
src/backend/access/gist/gist.c
src/backend/access/gist/gistbuild.c
src/backend/access/heap/heapam.c
src/backend/access/heap/heapam_handler.c
src/backend/access/heap/heaptoast.c
src/backend/access/nbtree/nbtutils.c
src/backend/access/spgist/spgdoinsert.c
src/backend/access/spgist/spgutils.c
src/backend/access/table/toast_helper.c
src/backend/catalog/index.c
src/backend/commands/copy.c
src/backend/commands/tablecmds.c
src/backend/executor/execExpr.c
src/backend/executor/execExprInterp.c
src/backend/executor/execJunk.c
src/backend/executor/execTuples.c
src/backend/executor/functions.c
src/backend/executor/nodeMemoize.c
src/backend/executor/nodeModifyTable.c
src/backend/executor/nodeValuesscan.c
src/backend/executor/tstoreReceiver.c
src/backend/jit/llvm/llvmjit_deform.c
src/backend/optimizer/util/plancat.c
src/backend/replication/pgoutput/pgoutput.c
src/backend/utils/adt/expandedrecord.c
src/backend/utils/adt/ri_triggers.c
src/backend/utils/cache/relcache.c
src/include/access/htup_details.h
src/include/access/itup.h
src/include/access/tupdesc.h
src/include/access/tupmacs.h
src/tools/pgindent/typedefs.list