summaryrefslogtreecommitdiff
path: root/src/backend/executor
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/executor
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/executor')
-rw-r--r--src/backend/executor/execExpr.c4
-rw-r--r--src/backend/executor/execExprInterp.c6
-rw-r--r--src/backend/executor/execJunk.c2
-rw-r--r--src/backend/executor/execTuples.c8
-rw-r--r--src/backend/executor/functions.c2
-rw-r--r--src/backend/executor/nodeMemoize.c8
-rw-r--r--src/backend/executor/nodeModifyTable.c4
-rw-r--r--src/backend/executor/nodeValuesscan.c4
-rw-r--r--src/backend/executor/tstoreReceiver.c4
9 files changed, 21 insertions, 21 deletions
diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c
index 81714341f07..3d01a90bd64 100644
--- a/src/backend/executor/execExpr.c
+++ b/src/backend/executor/execExpr.c
@@ -598,7 +598,7 @@ ExecBuildUpdateProjection(List *targetList,
*/
for (int attnum = relDesc->natts; attnum > 0; attnum--)
{
- Form_pg_attribute attr = TupleDescAttr(relDesc, attnum - 1);
+ CompactAttribute *attr = TupleDescCompactAttr(relDesc, attnum - 1);
if (attr->attisdropped)
continue;
@@ -694,7 +694,7 @@ ExecBuildUpdateProjection(List *targetList,
*/
for (int attnum = 1; attnum <= relDesc->natts; attnum++)
{
- Form_pg_attribute attr = TupleDescAttr(relDesc, attnum - 1);
+ CompactAttribute *attr = TupleDescCompactAttr(relDesc, attnum - 1);
if (attr->attisdropped)
{
diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c
index 60dcbcbe596..56e13d20a87 100644
--- a/src/backend/executor/execExprInterp.c
+++ b/src/backend/executor/execExprInterp.c
@@ -3152,7 +3152,7 @@ ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op,
for (int att = 1; att <= tupDesc->natts; att++)
{
/* ignore dropped columns */
- if (TupleDescAttr(tupDesc, att - 1)->attisdropped)
+ if (TupleDescCompactAttr(tupDesc, att - 1)->attisdropped)
continue;
if (heap_attisnull(&tmptup, att, tupDesc))
{
@@ -5296,8 +5296,8 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
for (int i = 0; i < var_tupdesc->natts; i++)
{
- Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
- Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
+ CompactAttribute *vattr = TupleDescCompactAttr(var_tupdesc, i);
+ CompactAttribute *sattr = TupleDescCompactAttr(tupleDesc, i);
if (!vattr->attisdropped)
continue; /* already checked non-dropped cols */
diff --git a/src/backend/executor/execJunk.c b/src/backend/executor/execJunk.c
index b962c313834..7d0afca4181 100644
--- a/src/backend/executor/execJunk.c
+++ b/src/backend/executor/execJunk.c
@@ -169,7 +169,7 @@ ExecInitJunkFilterConversion(List *targetList,
t = list_head(targetList);
for (i = 0; i < cleanLength; i++)
{
- if (TupleDescAttr(cleanTupType, i)->attisdropped)
+ if (TupleDescCompactAttr(cleanTupType, i)->attisdropped)
continue; /* map entry is already zero */
for (;;)
{
diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c
index 00dc3396156..875515777b6 100644
--- a/src/backend/executor/execTuples.c
+++ b/src/backend/executor/execTuples.c
@@ -187,7 +187,7 @@ tts_virtual_materialize(TupleTableSlot *slot)
/* compute size of memory required */
for (int natt = 0; natt < desc->natts; natt++)
{
- Form_pg_attribute att = TupleDescAttr(desc, natt);
+ CompactAttribute *att = TupleDescCompactAttr(desc, natt);
Datum val;
if (att->attbyval || slot->tts_isnull[natt])
@@ -223,7 +223,7 @@ tts_virtual_materialize(TupleTableSlot *slot)
/* and copy all attributes into the pre-allocated space */
for (int natt = 0; natt < desc->natts; natt++)
{
- Form_pg_attribute att = TupleDescAttr(desc, natt);
+ CompactAttribute *att = TupleDescCompactAttr(desc, natt);
Datum val;
if (att->attbyval || slot->tts_isnull[natt])
@@ -1044,7 +1044,7 @@ slot_deform_heap_tuple(TupleTableSlot *slot, HeapTuple tuple, uint32 *offp,
for (; attnum < natts; attnum++)
{
- Form_pg_attribute thisatt = TupleDescAttr(tupleDesc, attnum);
+ CompactAttribute *thisatt = TupleDescCompactAttr(tupleDesc, attnum);
if (hasnulls && att_isnull(attnum, bp))
{
@@ -2237,7 +2237,7 @@ BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
*/
for (i = 0; i < natts; i++)
{
- if (!TupleDescAttr(tupdesc, i)->attisdropped)
+ if (!TupleDescCompactAttr(tupdesc, i)->attisdropped)
{
/* Non-dropped attributes */
dvalues[i] = InputFunctionCall(&attinmeta->attinfuncs[i],
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c
index 3b2f78b2197..3a2d51c5ad0 100644
--- a/src/backend/executor/functions.c
+++ b/src/backend/executor/functions.c
@@ -1886,7 +1886,7 @@ check_sql_fn_retval(List *queryTreeLists,
/* remaining columns in rettupdesc had better all be dropped */
for (colindex++; colindex <= tupnatts; colindex++)
{
- if (!TupleDescAttr(rettupdesc, colindex - 1)->attisdropped)
+ if (!TupleDescCompactAttr(rettupdesc, colindex - 1)->attisdropped)
ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("return type mismatch in function declared to return %s",
diff --git a/src/backend/executor/nodeMemoize.c b/src/backend/executor/nodeMemoize.c
index df8e3fff082..aff3d9d921d 100644
--- a/src/backend/executor/nodeMemoize.c
+++ b/src/backend/executor/nodeMemoize.c
@@ -175,10 +175,10 @@ MemoizeHash_hash(struct memoize_hash *tb, const MemoizeKey *key)
if (!pslot->tts_isnull[i]) /* treat nulls as having hash key 0 */
{
- Form_pg_attribute attr;
+ CompactAttribute *attr;
uint32 hkey;
- attr = TupleDescAttr(pslot->tts_tupleDescriptor, i);
+ attr = TupleDescCompactAttr(pslot->tts_tupleDescriptor, i);
hkey = datum_image_hash(pslot->tts_values[i], attr->attbyval, attr->attlen);
@@ -242,7 +242,7 @@ MemoizeHash_equal(struct memoize_hash *tb, const MemoizeKey *key1,
for (int i = 0; i < numkeys; i++)
{
- Form_pg_attribute attr;
+ CompactAttribute *attr;
if (tslot->tts_isnull[i] != pslot->tts_isnull[i])
{
@@ -255,7 +255,7 @@ MemoizeHash_equal(struct memoize_hash *tb, const MemoizeKey *key1,
continue;
/* perform binary comparison on the two datums */
- attr = TupleDescAttr(tslot->tts_tupleDescriptor, i);
+ attr = TupleDescCompactAttr(tslot->tts_tupleDescriptor, i);
if (!datum_image_eq(tslot->tts_values[i], pslot->tts_values[i],
attr->attbyval, attr->attlen))
{
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 1161520f76b..c445c433df4 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -496,14 +496,14 @@ ExecComputeStoredGenerated(ResultRelInfo *resultRelInfo,
for (int i = 0; i < natts; i++)
{
- Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
+ CompactAttribute *attr = TupleDescCompactAttr(tupdesc, i);
if (ri_GeneratedExprs[i])
{
Datum val;
bool isnull;
- Assert(attr->attgenerated == ATTRIBUTE_GENERATED_STORED);
+ Assert(TupleDescAttr(tupdesc, i)->attgenerated == ATTRIBUTE_GENERATED_STORED);
econtext->ecxt_scantuple = slot;
diff --git a/src/backend/executor/nodeValuesscan.c b/src/backend/executor/nodeValuesscan.c
index 92948917a08..9838977f08a 100644
--- a/src/backend/executor/nodeValuesscan.c
+++ b/src/backend/executor/nodeValuesscan.c
@@ -142,8 +142,8 @@ ValuesNext(ValuesScanState *node)
foreach(lc, exprstatelist)
{
ExprState *estate = (ExprState *) lfirst(lc);
- Form_pg_attribute attr = TupleDescAttr(slot->tts_tupleDescriptor,
- resind);
+ CompactAttribute *attr = TupleDescCompactAttr(slot->tts_tupleDescriptor,
+ resind);
values[resind] = ExecEvalExpr(estate,
econtext,
diff --git a/src/backend/executor/tstoreReceiver.c b/src/backend/executor/tstoreReceiver.c
index de4646b5c26..658d1724c83 100644
--- a/src/backend/executor/tstoreReceiver.c
+++ b/src/backend/executor/tstoreReceiver.c
@@ -65,7 +65,7 @@ tstoreStartupReceiver(DestReceiver *self, int operation, TupleDesc typeinfo)
{
for (i = 0; i < natts; i++)
{
- Form_pg_attribute attr = TupleDescAttr(typeinfo, i);
+ CompactAttribute *attr = TupleDescCompactAttr(typeinfo, i);
if (attr->attisdropped)
continue;
@@ -154,7 +154,7 @@ tstoreReceiveSlot_detoast(TupleTableSlot *slot, DestReceiver *self)
for (i = 0; i < natts; i++)
{
Datum val = slot->tts_values[i];
- Form_pg_attribute attr = TupleDescAttr(typeinfo, i);
+ CompactAttribute *attr = TupleDescCompactAttr(typeinfo, i);
if (!attr->attisdropped && attr->attlen == -1 && !slot->tts_isnull[i])
{