diff options
author | David Rowley <drowley@postgresql.org> | 2024-12-21 09:43:26 +1300 |
---|---|---|
committer | David Rowley <drowley@postgresql.org> | 2024-12-21 09:43:26 +1300 |
commit | db448ce5ad36a2754e4e75900b180260143aacf8 (patch) | |
tree | 54753cad82035c6a3cdf7edaa897291b09622d6b /src/backend/access/common/indextuple.c | |
parent | 1f81b48a9d567ae9074ab1f3233eae9997b3d7bd (diff) | |
download | postgresql-db448ce5ad36a2754e4e75900b180260143aacf8.tar.gz postgresql-db448ce5ad36a2754e4e75900b180260143aacf8.zip |
Optimize alignment calculations in tuple form/deform
Here we convert CompactAttribute.attalign from a char, which is directly
derived from pg_attribute.attalign into a uint8, which stores the number
of bytes to align the column's value by in the tuple.
This allows tuple deformation and tuple size calculations to move away
from using the inefficient att_align_nominal() macro, which manually
checks each TYPALIGN_* char to translate that into the alignment bytes
for the given type. Effectively, this commit changes those to TYPEALIGN
calls, which are branchless and only perform some simple arithmetic with
some bit-twiddling.
The removed branches were often mispredicted by CPUs, especially so in
real-world tables which often contain a mishmash of different types
with different alignment requirements.
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/common/indextuple.c')
-rw-r--r-- | src/backend/access/common/indextuple.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c index 38aeb230879..a846b3d4a99 100644 --- a/src/backend/access/common/indextuple.c +++ b/src/backend/access/common/indextuple.c @@ -363,7 +363,7 @@ nocache_index_getattr(IndexTuple tup, if (att->attlen <= 0) break; - off = att_align_nominal(off, att->attalign); + off = att_nominal_alignby(off, att->attalignby); att->attcacheoff = off; @@ -412,19 +412,19 @@ nocache_index_getattr(IndexTuple tup, * either an aligned or unaligned value. */ if (usecache && - off == att_align_nominal(off, att->attalign)) + off == att_nominal_alignby(off, att->attalignby)) att->attcacheoff = off; else { - off = att_align_pointer(off, att->attalign, -1, - tp + off); + off = att_pointer_alignby(off, att->attalignby, -1, + tp + off); usecache = false; } } else { - /* not varlena, so safe to use att_align_nominal */ - off = att_align_nominal(off, att->attalign); + /* not varlena, so safe to use att_nominal_alignby */ + off = att_nominal_alignby(off, att->attalignby); if (usecache) att->attcacheoff = off; @@ -513,19 +513,19 @@ index_deform_tuple_internal(TupleDesc tupleDescriptor, * an aligned or unaligned value. */ if (!slow && - off == att_align_nominal(off, thisatt->attalign)) + off == att_nominal_alignby(off, thisatt->attalignby)) thisatt->attcacheoff = off; else { - off = att_align_pointer(off, thisatt->attalign, -1, - tp + off); + off = att_pointer_alignby(off, thisatt->attalignby, -1, + tp + off); slow = true; } } else { - /* not varlena, so safe to use att_align_nominal */ - off = att_align_nominal(off, thisatt->attalign); + /* not varlena, so safe to use att_nominal_alignby */ + off = att_nominal_alignby(off, thisatt->attalignby); if (!slow) thisatt->attcacheoff = off; |