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/utils/adt | |
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/utils/adt')
-rw-r--r-- | src/backend/utils/adt/expandedrecord.c | 10 | ||||
-rw-r--r-- | src/backend/utils/adt/ri_triggers.c | 2 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/backend/utils/adt/expandedrecord.c b/src/backend/utils/adt/expandedrecord.c index d2842495b57..913c08b06e0 100644 --- a/src/backend/utils/adt/expandedrecord.c +++ b/src/backend/utils/adt/expandedrecord.c @@ -699,7 +699,7 @@ ER_get_flat_size(ExpandedObjectHeader *eohptr) { for (i = 0; i < erh->nfields; i++) { - Form_pg_attribute attr = TupleDescAttr(tupdesc, i); + CompactAttribute *attr = TupleDescCompactAttr(tupdesc, i); if (!erh->dnulls[i] && !attr->attbyval && attr->attlen == -1 && @@ -1115,7 +1115,7 @@ expanded_record_set_field_internal(ExpandedRecordHeader *erh, int fnumber, bool check_constraints) { TupleDesc tupdesc; - Form_pg_attribute attr; + CompactAttribute *attr; Datum *dvalues; bool *dnulls; char *oldValue; @@ -1146,7 +1146,7 @@ expanded_record_set_field_internal(ExpandedRecordHeader *erh, int fnumber, * Copy new field value into record's context, and deal with detoasting, * if needed. */ - attr = TupleDescAttr(tupdesc, fnumber - 1); + attr = TupleDescCompactAttr(tupdesc, fnumber - 1); if (!isnull && !attr->attbyval) { MemoryContext oldcxt; @@ -1279,7 +1279,7 @@ expanded_record_set_fields(ExpandedRecordHeader *erh, for (fnumber = 0; fnumber < erh->nfields; fnumber++) { - Form_pg_attribute attr = TupleDescAttr(tupdesc, fnumber); + CompactAttribute *attr = TupleDescCompactAttr(tupdesc, fnumber); Datum newValue; bool isnull; @@ -1541,7 +1541,7 @@ check_domain_for_new_field(ExpandedRecordHeader *erh, int fnumber, */ if (!isnull) { - Form_pg_attribute attr = TupleDescAttr(erh->er_tupdesc, fnumber - 1); + CompactAttribute *attr = TupleDescCompactAttr(erh->er_tupdesc, fnumber - 1); if (!attr->attbyval && attr->attlen == -1 && VARATT_IS_EXTERNAL(DatumGetPointer(newValue))) diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index 3185f48afa6..093a3f1b66b 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -2932,7 +2932,7 @@ ri_KeysEqual(Relation rel, TupleTableSlot *oldslot, TupleTableSlot *newslot, * difference for ON UPDATE CASCADE, but for consistency we treat * all changes to the PK the same. */ - Form_pg_attribute att = TupleDescAttr(oldslot->tts_tupleDescriptor, attnums[i] - 1); + CompactAttribute *att = TupleDescCompactAttr(oldslot->tts_tupleDescriptor, attnums[i] - 1); if (!datum_image_eq(oldvalue, newvalue, att->attbyval, att->attlen)) return false; |