diff options
author | David Rowley <drowley@postgresql.org> | 2024-12-20 22:31:26 +1300 |
---|---|---|
committer | David Rowley <drowley@postgresql.org> | 2024-12-20 22:31:26 +1300 |
commit | 5983a4cffc31640fda6643f10146a5b72b203eaa (patch) | |
tree | 0ff0361ca37173c5093ae3e1eb23fe657c904adc /src/backend/access/heap/heapam.c | |
parent | 8ac0021b6f10928a46b7f3d1b25bc21c0ac7f8c5 (diff) | |
download | postgresql-5983a4cffc31640fda6643f10146a5b72b203eaa.tar.gz postgresql-5983a4cffc31640fda6643f10146a5b72b203eaa.zip |
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
Diffstat (limited to 'src/backend/access/heap/heapam.c')
-rw-r--r-- | src/backend/access/heap/heapam.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 6cdc68d981a..329e727f80d 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -4200,8 +4200,6 @@ static bool heap_attr_equals(TupleDesc tupdesc, int attrnum, Datum value1, Datum value2, bool isnull1, bool isnull2) { - Form_pg_attribute att; - /* * If one value is NULL and other is not, then they are certainly not * equal @@ -4231,8 +4229,10 @@ heap_attr_equals(TupleDesc tupdesc, int attrnum, Datum value1, Datum value2, } else { + CompactAttribute *att; + Assert(attrnum <= tupdesc->natts); - att = TupleDescAttr(tupdesc, attrnum - 1); + att = TupleDescCompactAttr(tupdesc, attrnum - 1); return datumIsEqual(value1, value2, att->attbyval, att->attlen); } } @@ -4314,7 +4314,7 @@ HeapDetermineColumnsInfo(Relation relation, * that system attributes can't be stored externally. */ if (attrnum < 0 || isnull1 || - TupleDescAttr(tupdesc, attrnum - 1)->attlen != -1) + TupleDescCompactAttr(tupdesc, attrnum - 1)->attlen != -1) continue; /* |