Re: Make tuple deformation faster
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Victor Yegorov <vyegorov@gmail.com>, Matthias van de Meent <boekewurm+postgres@gmail.com>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2024-12-04T22:52:01Z
Lists: pgsql-hackers
On Thu, 5 Dec 2024 at 03:51, Andres Freund <andres@anarazel.de> wrote: > Possibly stupid idea: Could we instead store the attributes *before* the main > TupleDescData, with increasing "distance" for increased attnos? That way we > wouldn't need to calculate any variable offsets. Of course the price would be > to have some slightly more complicated invocation of pfree(), but that's > comparatively rare. Are you thinking this to make the address calculation cheaper? or so that the hacky code that truncates the TupleDesc would work without crashing still? If it's for the latter then the pfree() would be tricky to make work still as natts would need to be consulted to find the address to pfree. > On 2024-12-05 01:42:36 +1300, David Rowley wrote: > > Since I'm calculating the base address of the FormData_pg_attribute > > array in TupleDesc by looking at natts, when this code changes natts > > on the fly, that means calls to TupleDescAttr end up looking in the > > wrong place for the required FormData_pg_attribute element. > > It's possible out-of-core code is doing that too, could we detect this in > assert enabled builds? The assert in TupleDescCompactAttr() which verifies the CompactAttribute matches the FormData_pg_attribute did highlight these issues. It's just it wasn't that obvious what the cause of the issue was from that failing assert. I expect there would be some breaking of extensions by removing the attrs array anyway. 65b71dec2d fixed up some cases where TupleDescAttr() wasn't being used, so anything out there that's doing something similar to what that commit fixed would fail to compile. One way to ensure we purposefully break any code manually adjusting natts would be to rename that field. That would mean having to adjust all the loops over each attribute in core. There are quite a few: $ git grep -E "^\s+for.*->natts;" | wc -l 147 David
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