mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
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
This commit is contained in:
13
src/backend/utils/cache/typcache.c
vendored
13
src/backend/utils/cache/typcache.c
vendored
@@ -241,12 +241,18 @@ shared_record_table_compare(const void *a, const void *b, size_t size,
|
||||
TupleDesc t2;
|
||||
|
||||
if (k1->shared)
|
||||
{
|
||||
t1 = (TupleDesc) dsa_get_address(area, k1->u.shared_tupdesc);
|
||||
t1->attrs = TupleDescAttrAddress(t1);
|
||||
}
|
||||
else
|
||||
t1 = k1->u.local_tupdesc;
|
||||
|
||||
if (k2->shared)
|
||||
{
|
||||
t2 = (TupleDesc) dsa_get_address(area, k2->u.shared_tupdesc);
|
||||
t2->attrs = TupleDescAttrAddress(t2);
|
||||
}
|
||||
else
|
||||
t2 = k2->u.local_tupdesc;
|
||||
|
||||
@@ -264,7 +270,10 @@ shared_record_table_hash(const void *a, size_t size, void *arg)
|
||||
TupleDesc t;
|
||||
|
||||
if (k->shared)
|
||||
{
|
||||
t = (TupleDesc) dsa_get_address(area, k->u.shared_tupdesc);
|
||||
t->attrs = TupleDescAttrAddress(t);
|
||||
}
|
||||
else
|
||||
t = k->u.local_tupdesc;
|
||||
|
||||
@@ -1867,6 +1876,7 @@ lookup_rowtype_tupdesc_internal(Oid type_id, int32 typmod, bool noError)
|
||||
tupdesc = (TupleDesc)
|
||||
dsa_get_address(CurrentSession->area,
|
||||
entry->shared_tupdesc);
|
||||
tupdesc->attrs = TupleDescAttrAddress(tupdesc);
|
||||
Assert(typmod == tupdesc->tdtypmod);
|
||||
|
||||
/* We may need to extend the local RecordCacheArray. */
|
||||
@@ -2953,6 +2963,7 @@ find_or_make_matching_shared_tupledesc(TupleDesc tupdesc)
|
||||
result = (TupleDesc)
|
||||
dsa_get_address(CurrentSession->area,
|
||||
record_table_entry->key.u.shared_tupdesc);
|
||||
result->attrs = TupleDescAttrAddress(result);
|
||||
Assert(result->tdrefcount == -1);
|
||||
|
||||
return result;
|
||||
@@ -3016,6 +3027,7 @@ find_or_make_matching_shared_tupledesc(TupleDesc tupdesc)
|
||||
result = (TupleDesc)
|
||||
dsa_get_address(CurrentSession->area,
|
||||
record_table_entry->key.u.shared_tupdesc);
|
||||
result->attrs = TupleDescAttrAddress(result);
|
||||
Assert(result->tdrefcount == -1);
|
||||
|
||||
return result;
|
||||
@@ -3028,6 +3040,7 @@ find_or_make_matching_shared_tupledesc(TupleDesc tupdesc)
|
||||
record_table_entry);
|
||||
result = (TupleDesc)
|
||||
dsa_get_address(CurrentSession->area, shared_dp);
|
||||
result->attrs = TupleDescAttrAddress(result);
|
||||
Assert(result->tdrefcount == -1);
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user