Re: Make tuple deformation faster
Andy Fan <zhihuifan1213@163.com>
From: Andy Fan <zhihuifan1213@163.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2024-07-01T09:17:00Z
Lists: pgsql-hackers
David Rowley <dgrowleyml@gmail.com> writes: > Currently, TupleDescData contains the descriptor's attributes in a > variable length array of FormData_pg_attribute allocated within the > same allocation as the TupleDescData. According to my IDE, > sizeof(FormData_pg_attribute) == 104 bytes. It's that large mainly due > to attname being 64 bytes. The TupleDescData.attrs[] array could end > up quite large on tables with many columns and that could result in > poor CPU cache hit ratios when deforming tuples. ... > > To test the performance of this, I tried using the attached script > which creates a table where the first column is a variable length > column and the final column is an int. The query I ran to test the > performance inserted 1 million rows into this table and performed a > sum() on the final column. The attached graph shows that the query is > 30% faster than master with 15 columns between the first and last > column. Yet another a wonderful optimization! I just want to know how did you find this optimization (CPU cache hit) case and think it worths some time. because before we invest our time to optimize something, it is better know that we can get some measurable improvement after our time is spend. At for this case, 30% is really a huge number even it is a artificial case. Another case is Andrew introduced NullableDatum 5 years ago and said using it in TupleTableSlot could be CPU cache friendly, I can follow that, but how much it can improve in an ideal case, is it possible to forecast it somehow? I ask it here because both cases are optimizing for CPU cache.. -- Best Regards Andy Fan
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix possible Assert failure in verify_compact_attribute()
- 33b06a20016d 18.0 landed
-
Speedup tuple deformation with additional function inlining
- 58a359e585d0 18.0 landed
-
Fix race condition in TupleDescCompactAttr assert code
- 6f3820f37aba 18.0 landed
-
Optimize alignment calculations in tuple form/deform
- db448ce5ad36 18.0 landed
-
Remove pg_attribute.attcacheoff column
- 02a8d0c45253 18.0 landed
-
Introduce CompactAttribute array in TupleDesc, take 2
- 5983a4cffc31 18.0 landed
-
Introduce CompactAttribute array in TupleDesc
- d28dff3f6cd6 18.0 landed
-
Use TupleDescAttr macro consistently
- 65b71dec2d57 18.0 landed