Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rowley2024-12-20 09:31:26 +0000
committerDavid Rowley2024-12-20 09:31:26 +0000
commit5983a4cffc31640fda6643f10146a5b72b203eaa (patch)
tree0ff0361ca37173c5093ae3e1eb23fe657c904adc /src/backend/access/gist
parent8ac0021b6f10928a46b7f3d1b25bc21c0ac7f8c5 (diff)
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/gist')
-rw-r--r--src/backend/access/gist/gist.c5
-rw-r--r--src/backend/access/gist/gistbuild.c6
2 files changed, 6 insertions, 5 deletions
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index ebc65449c1b..272390ff67d 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -1557,9 +1557,8 @@ initGISTstate(Relation index)
* tuples during page split. Also, B-tree is not adjusting tuples on
* internal pages the way GiST does.
*/
- giststate->nonLeafTupdesc = CreateTupleDescCopyConstr(index->rd_att);
- giststate->nonLeafTupdesc->natts =
- IndexRelationGetNumberOfKeyAttributes(index);
+ giststate->nonLeafTupdesc = CreateTupleDescTruncatedCopy(index->rd_att,
+ IndexRelationGetNumberOfKeyAttributes(index));
for (i = 0; i < IndexRelationGetNumberOfKeyAttributes(index); i++)
{
diff --git a/src/backend/access/gist/gistbuild.c b/src/backend/access/gist/gistbuild.c
index 63d1914b37f..3a2759b4468 100644
--- a/src/backend/access/gist/gistbuild.c
+++ b/src/backend/access/gist/gistbuild.c
@@ -657,10 +657,12 @@ gistInitBuffering(GISTBuildState *buildstate)
itupMinSize = (Size) MAXALIGN(sizeof(IndexTupleData));
for (i = 0; i < index->rd_att->natts; i++)
{
- if (TupleDescAttr(index->rd_att, i)->attlen < 0)
+ CompactAttribute *attr = TupleDescCompactAttr(index->rd_att, i);
+
+ if (attr->attlen < 0)
itupMinSize += VARHDRSZ;
else
- itupMinSize += TupleDescAttr(index->rd_att, i)->attlen;
+ itupMinSize += attr->attlen;
}
/* Calculate average and maximal number of index tuples which fit to page */