aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/common/indextuple.c
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2024-12-03 16:50:59 +1300
committerDavid Rowley <drowley@postgresql.org>2024-12-03 16:50:59 +1300
commitd28dff3f6cd6a7562fb2c211ac0fb74a33ffd032 (patch)
tree4b7126eba2dcbed5e08714b4ab2d8577058814c3 /src/backend/access/common/indextuple.c
parente4c8865196f6ad6bb3473bcad1d2ad51147e4513 (diff)
downloadpostgresql-d28dff3f6cd6a7562fb2c211ac0fb74a33ffd032.tar.gz
postgresql-d28dff3f6cd6a7562fb2c211ac0fb74a33ffd032.zip
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
Diffstat (limited to 'src/backend/access/common/indextuple.c')
-rw-r--r--src/backend/access/common/indextuple.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c
index bb2c6a2bcc1..37133ed7f80 100644
--- a/src/backend/access/common/indextuple.c
+++ b/src/backend/access/common/indextuple.c
@@ -303,13 +303,13 @@ nocache_index_getattr(IndexTuple tup,
if (!slow)
{
- Form_pg_attribute att;
+ CompactAttribute *att;
/*
* If we get here, there are no nulls up to and including the target
* attribute. If we have a cached offset, we can use it.
*/
- att = TupleDescAttr(tupleDesc, attnum);
+ att = TupleDescCompactAttr(tupleDesc, attnum);
if (att->attcacheoff >= 0)
return fetchatt(att, tp + att->attcacheoff);
@@ -324,7 +324,7 @@ nocache_index_getattr(IndexTuple tup,
for (j = 0; j <= attnum; j++)
{
- if (TupleDescAttr(tupleDesc, j)->attlen <= 0)
+ if (TupleDescCompactAttr(tupleDesc, j)->attlen <= 0)
{
slow = true;
break;
@@ -347,18 +347,18 @@ nocache_index_getattr(IndexTuple tup,
* fixed-width columns, in hope of avoiding future visits to this
* routine.
*/
- TupleDescAttr(tupleDesc, 0)->attcacheoff = 0;
+ TupleDescCompactAttr(tupleDesc, 0)->attcacheoff = 0;
/* we might have set some offsets in the slow path previously */
- while (j < natts && TupleDescAttr(tupleDesc, j)->attcacheoff > 0)
+ while (j < natts && TupleDescCompactAttr(tupleDesc, j)->attcacheoff > 0)
j++;
- off = TupleDescAttr(tupleDesc, j - 1)->attcacheoff +
- TupleDescAttr(tupleDesc, j - 1)->attlen;
+ off = TupleDescCompactAttr(tupleDesc, j - 1)->attcacheoff +
+ TupleDescCompactAttr(tupleDesc, j - 1)->attlen;
for (; j < natts; j++)
{
- Form_pg_attribute att = TupleDescAttr(tupleDesc, j);
+ CompactAttribute *att = TupleDescCompactAttr(tupleDesc, j);
if (att->attlen <= 0)
break;
@@ -372,7 +372,7 @@ nocache_index_getattr(IndexTuple tup,
Assert(j > attnum);
- off = TupleDescAttr(tupleDesc, attnum)->attcacheoff;
+ off = TupleDescCompactAttr(tupleDesc, attnum)->attcacheoff;
}
else
{
@@ -392,7 +392,7 @@ nocache_index_getattr(IndexTuple tup,
off = 0;
for (i = 0;; i++) /* loop exit is at "break" */
{
- Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
+ CompactAttribute *att = TupleDescCompactAttr(tupleDesc, i);
if (IndexTupleHasNulls(tup) && att_isnull(i, bp))
{
@@ -440,7 +440,7 @@ nocache_index_getattr(IndexTuple tup,
}
}
- return fetchatt(TupleDescAttr(tupleDesc, attnum), tp + off);
+ return fetchatt(TupleDescCompactAttr(tupleDesc, attnum), tp + off);
}
/*
@@ -490,7 +490,7 @@ index_deform_tuple_internal(TupleDesc tupleDescriptor,
for (attnum = 0; attnum < natts; attnum++)
{
- Form_pg_attribute thisatt = TupleDescAttr(tupleDescriptor, attnum);
+ CompactAttribute *thisatt = TupleDescCompactAttr(tupleDescriptor, attnum);
if (hasnulls && att_isnull(attnum, bp))
{
@@ -588,7 +588,7 @@ index_truncate_tuple(TupleDesc sourceDescriptor, IndexTuple source,
return CopyIndexTuple(source);
/* Create temporary descriptor to scribble on */
- truncdesc = palloc(TupleDescSize(sourceDescriptor));
+ truncdesc = CreateTemplateTupleDesc(sourceDescriptor->natts);
TupleDescCopy(truncdesc, sourceDescriptor);
truncdesc->natts = leavenatts;